From 48484843dff6e56a561cc173f5714da636da19ef Mon Sep 17 00:00:00 2001 From: tina <lt-bloody@riox.eu> Date: Wed, 22 Aug 2018 15:08:08 +0200 Subject: [PATCH] adds more tests for getcyclelengthstats with more realistic data --- test/cycle-length.spec.js | 51 +++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/test/cycle-length.spec.js b/test/cycle-length.spec.js index 043cf96d..ee05fcb5 100644 --- a/test/cycle-length.spec.js +++ b/test/cycle-length.spec.js @@ -17,7 +17,7 @@ describe('getCycleLengthStats', () => { stdDeviation: 53.06 } expect(result).to.eql(expectedResult) - }) + }), it('works for a simple even-numbered array', () => { const cycleLengths = [4, 1, 15, 2, 20, 5] @@ -30,7 +30,8 @@ describe('getCycleLengthStats', () => { stdDeviation: 7.78 } expect(result).to.eql(expectedResult) - }) + }), + it('works for an one-element array', () => { const cycleLengths = [42] const result = cycleInfo(cycleLengths) @@ -42,20 +43,60 @@ describe('getCycleLengthStats', () => { stdDeviation: null } expect(result).to.eql(expectedResult) + }), + + describe('works for more realistic examples', () => { + it('1 day difference between shortest and longest period', () => { + const cycleLengths = [28, 29, 28, 28, 28, 29, 28, 28, 28, 29, 29, 28] + const result = cycleInfo(cycleLengths) + const expectedResult = { + minimum: 28, + maximum: 29, + mean: 28.33, + median: 28, + stdDeviation: 0.49 + } + expect(result).to.eql(expectedResult) + }), + it('3 days difference between shortest and longest period', () => { + const cycleLengths = [28, 29, 28, 28, 27, 30, 28, 27, 28, 28, 29, 27] + const result = cycleInfo(cycleLengths) + const expectedResult = { + minimum: 27, + maximum: 30, + mean: 28.08, + median: 28, + stdDeviation: 0.90 + } + expect(result).to.eql(expectedResult) + }), + it('8 days difference between shortest and longest period', () => { + const cycleLengths = [28, 32, 29, 27, 28, 26, 33, 28, 29, 34, 27, 29] + const result = cycleInfo(cycleLengths) + const expectedResult = { + minimum: 26, + maximum: 34, + mean: 29.17, + median: 28.5, + stdDeviation: 2.52 + } + expect(result).to.eql(expectedResult) + }) }) + describe('when args are wrong', () => { it('throws when arg object is an empty array', () => { const cycleLengths = [] expect(() => cycleInfo(cycleLengths).to.throw(AssertionError)) - }) + }), it('throws when arg object is not in right format', () => { const wrongObject = { hello: 'world' } expect(() => cycleInfo(wrongObject).to.throw(AssertionError)) - }) + }), it('throws when arg array contains a string', () => { const wrongElement = [4, 1, 15, '2', 20, 5] expect(() => cycleInfo(wrongElement).to.throw(AssertionError)) - }) + }), it('throws when arg array contains a NaN', () => { const wrongElement = [4, 1, 15, NaN, 20, 5] expect(() => cycleInfo(wrongElement).to.throw(AssertionError)) -- GitLab