resolves some of the suggested improvements, renames the term period with cycle

This commit is contained in:
tina
2018-08-09 18:31:14 +02:00
parent c99aa7509d
commit f2b8723fb9
4 changed files with 48 additions and 53 deletions
@@ -1,14 +1,14 @@
import chai from 'chai'
import { AssertionError } from 'assert'
import periodInfo from '../lib/period-length'
import cycleInfo from '../lib/cycle-length'
const expect = chai.expect
describe('getPeriodLengthStats', () => {
describe('getCycleLengthStats', () => {
it('works for a simple odd-numbered array', () => {
const periodLengths = [99, 5, 1, 2, 100]
const result = periodInfo(periodLengths)
const cycleLengths = [99, 5, 1, 2, 100]
const result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 1,
maximum: 100,
@@ -20,8 +20,8 @@ describe('getPeriodLengthStats', () => {
})
it('works for a simple even-numbered array', () => {
const periodLengths = [4, 1, 15, 2, 20, 5]
const result = periodInfo(periodLengths)
const cycleLengths = [4, 1, 15, 2, 20, 5]
const result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 1,
maximum: 20,
@@ -32,8 +32,8 @@ describe('getPeriodLengthStats', () => {
expect(result).to.eql(expectedResult)
})
it('works for an one-element array', () => {
const periodLengths = [42]
const result = periodInfo(periodLengths)
const cycleLengths = [42]
const result = cycleInfo(cycleLengths)
const expectedResult = {
minimum: 42,
maximum: 42,
@@ -45,20 +45,20 @@ describe('getPeriodLengthStats', () => {
})
describe('when args are wrong', () => {
it('throws when arg object is an empty array', () => {
const periodLengths = []
expect(() => periodInfo(periodLengths).to.throw(AssertionError))
const cycleLengths = []
expect(() => cycleInfo(cycleLengths).to.throw(AssertionError))
})
it('throws when arg object is not in right format', () => {
const wrongObject = { hello: 'world' }
expect(() => periodInfo(wrongObject).to.throw(AssertionError))
expect(() => cycleInfo(wrongObject).to.throw(AssertionError))
})
it('throws when arg array contains a string', () => {
const wrongElement = [4, 1, 15, '2', 20, 5]
expect(() => periodInfo(wrongElement).to.throw(AssertionError))
expect(() => cycleInfo(wrongElement).to.throw(AssertionError))
})
it('throws when arg array contains a NaN', () => {
const wrongElement = [4, 1, 15, NaN, 20, 5]
expect(() => periodInfo(wrongElement).to.throw(AssertionError))
expect(() => cycleInfo(wrongElement).to.throw(AssertionError))
})
})
})