Skip to content
Snippets Groups Projects
Commit 7fcaa4af authored by tina's avatar tina
Browse files

Merge branch '136-add-tests-for-getallmensesstarts' into 'master'

Resolve "add tests for getAllMensesStarts"

Closes #136

See merge request bloodyhealth/drip!58
parents b80c91cb 48484843
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -17,7 +17,7 @@ describe('getCycleLengthStats', () => { ...@@ -17,7 +17,7 @@ describe('getCycleLengthStats', () => {
stdDeviation: 53.06 stdDeviation: 53.06
} }
expect(result).to.eql(expectedResult) expect(result).to.eql(expectedResult)
}) }),
it('works for a simple even-numbered array', () => { it('works for a simple even-numbered array', () => {
const cycleLengths = [4, 1, 15, 2, 20, 5] const cycleLengths = [4, 1, 15, 2, 20, 5]
...@@ -30,7 +30,8 @@ describe('getCycleLengthStats', () => { ...@@ -30,7 +30,8 @@ describe('getCycleLengthStats', () => {
stdDeviation: 7.78 stdDeviation: 7.78
} }
expect(result).to.eql(expectedResult) expect(result).to.eql(expectedResult)
}) }),
it('works for an one-element array', () => { it('works for an one-element array', () => {
const cycleLengths = [42] const cycleLengths = [42]
const result = cycleInfo(cycleLengths) const result = cycleInfo(cycleLengths)
...@@ -42,20 +43,60 @@ describe('getCycleLengthStats', () => { ...@@ -42,20 +43,60 @@ describe('getCycleLengthStats', () => {
stdDeviation: null stdDeviation: null
} }
expect(result).to.eql(expectedResult) 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', () => { describe('when args are wrong', () => {
it('throws when arg object is an empty array', () => { it('throws when arg object is an empty array', () => {
const cycleLengths = [] const cycleLengths = []
expect(() => cycleInfo(cycleLengths).to.throw(AssertionError)) expect(() => cycleInfo(cycleLengths).to.throw(AssertionError))
}) }),
it('throws when arg object is not in right format', () => { it('throws when arg object is not in right format', () => {
const wrongObject = { hello: 'world' } const wrongObject = { hello: 'world' }
expect(() => cycleInfo(wrongObject).to.throw(AssertionError)) expect(() => cycleInfo(wrongObject).to.throw(AssertionError))
}) }),
it('throws when arg array contains a string', () => { it('throws when arg array contains a string', () => {
const wrongElement = [4, 1, 15, '2', 20, 5] const wrongElement = [4, 1, 15, '2', 20, 5]
expect(() => cycleInfo(wrongElement).to.throw(AssertionError)) expect(() => cycleInfo(wrongElement).to.throw(AssertionError))
}) }),
it('throws when arg array contains a NaN', () => { it('throws when arg array contains a NaN', () => {
const wrongElement = [4, 1, 15, NaN, 20, 5] const wrongElement = [4, 1, 15, NaN, 20, 5]
expect(() => cycleInfo(wrongElement).to.throw(AssertionError)) expect(() => cycleInfo(wrongElement).to.throw(AssertionError))
......
...@@ -343,4 +343,82 @@ describe('getCycleForDay', () => { ...@@ -343,4 +343,82 @@ describe('getCycleForDay', () => {
}, },
]) ])
}) })
})
describe('getAllMensesStart', () => {
it('works for one cycle start', () => {
const cycleDaysSortedByDate = [
{
date: '2018-05-01',
bleeding: { value: 1 }
}
]
const { getAllMensesStarts } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
})
const result = getAllMensesStarts()
expect(result.length).to.eql(1)
expect(result).to.eql(['2018-05-01'])
}),
it('works for two cycle starts', () => {
const cycleDaysSortedByDate = [
{
date: '2018-06-02',
bleeding: { value: 2 }
},
{
date: '2018-06-01',
bleeding: { value: 2 }
},
{
date: '2018-05-01',
bleeding: { value: 2 }
}
]
const { getAllMensesStarts } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
})
const result = getAllMensesStarts()
expect(result.length).to.eql(2)
expect(result).to.eql(['2018-06-01', '2018-05-01'])
}),
it('works for two cycle starts with excluded data', () => {
const cycleDaysSortedByDate = [
{
date: '2018-06-01',
bleeding: { value: 2 }
},
{
date: '2018-05-01',
bleeding: { value: 2 }
},
{
date: '2018-04-31',
bleeding: { value: 2 , exclude: true}
},
]
const { getAllMensesStarts } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
})
const result = getAllMensesStarts()
expect(result.length).to.eql(2)
expect(result).to.eql(['2018-06-01', '2018-05-01'])
}),
it('returns an empty array if no bleeding days are given', () => {
const cycleDaysSortedByDate = [ {} ]
const { getAllMensesStarts } = cycleModule({
cycleDaysSortedByDate,
bleedingDaysSortedByDate: cycleDaysSortedByDate.filter(d => d.bleeding)
})
const result = getAllMensesStarts()
expect(result.length).to.eql(0)
expect(result).to.eql([])
})
}) })
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment