Add more tests for combinations of fhm and mucus peak
This commit is contained in:
+8
-6
@@ -12,23 +12,25 @@ export default function (cycleDays, tempEvalEndIndex) {
|
||||
const threeFollowingDays = mucusDays.slice(i + 1, i + 4)
|
||||
if (threeFollowingDays.length < 3) continue
|
||||
|
||||
const bestQualityOccurringIn3FollowingDays = threeFollowingDays.some(day => day.mucus.value >= bestQuality)
|
||||
const bestQualityOccurringIn3FollowingDays = threeFollowingDays.some(day => {
|
||||
return day.mucus.value >= bestQuality
|
||||
})
|
||||
if (bestQualityOccurringIn3FollowingDays) continue
|
||||
|
||||
// FIXME mucus peak can be same day as first higher measurement
|
||||
const cycleDayIndex = cycleDays.indexOf(day)
|
||||
const relevantDays = cycleDays
|
||||
.slice(cycleDayIndex + 1, tempEvalEndIndex + 1)
|
||||
.filter(day => day.mucus && !day.mucus.exclude)
|
||||
|
||||
const evaluationCompleteDay = relevantDays.length > 3 ?
|
||||
relevantDays[relevantDays.length - 1] : threeFollowingDays[threeFollowingDays.length - 1]
|
||||
const noBestQualityUntilEndOfTempEval = relevantDays.every(day => {
|
||||
return day.mucus.value < bestQuality
|
||||
})
|
||||
|
||||
if (relevantDays.every(day => day.mucus.value < bestQuality)) {
|
||||
if (noBestQualityUntilEndOfTempEval) {
|
||||
return {
|
||||
detected: true,
|
||||
mucusPeak: day,
|
||||
evaluationCompleteDay
|
||||
evaluationCompleteDay: threeFollowingDays[threeFollowingDays.length - 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+118
-1
@@ -101,6 +101,118 @@ const fiveDayCycle = [
|
||||
{ date: '2018-06-03', bleeding: 3 },
|
||||
].map(convertToSymptoFormat)
|
||||
|
||||
const mucusPeakAndFhmOnSameDay = [
|
||||
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||
{ date: '2018-06-02', temperature: 36.65 },
|
||||
{ date: '2018-06-04', temperature: 36.6 },
|
||||
{ date: '2018-06-05', temperature: 36.55 },
|
||||
{ date: '2018-06-06', temperature: 36.7, mucus: 0 },
|
||||
{ date: '2018-06-09', temperature: 36.5, mucus: 4 },
|
||||
{ date: '2018-06-10', temperature: 36.4, mucus: 2 },
|
||||
{ date: '2018-06-13', temperature: 36.45, mucus: 3 },
|
||||
{ date: '2018-06-14', temperature: 36.5, mucus: 4 },
|
||||
{ date: '2018-06-15', temperature: 36.55, mucus: 4 },
|
||||
{ date: '2018-06-16', temperature: 36.7, mucus: 3 },
|
||||
{ date: '2018-06-17', temperature: 36.65, mucus: 3 },
|
||||
{ date: '2018-06-18', temperature: 36.75, mucus: 4 },
|
||||
{ date: '2018-06-19', temperature: 36.8, mucus: 3 },
|
||||
{ date: '2018-06-20', temperature: 36.9, mucus: 2 },
|
||||
{ date: '2018-06-21', temperature: 36.8, mucus: 2 },
|
||||
{ date: '2018-06-22', temperature: 36.9, mucus: 2 },
|
||||
{ date: '2018-06-25', temperature: 36.9, mucus: 1 },
|
||||
{ date: '2018-06-26', temperature: 36.8, mucus: 1 },
|
||||
{ date: '2018-06-27', temperature: 36.9, mucus: 1 }
|
||||
].map(convertToSymptoFormat)
|
||||
|
||||
const fhmTwoDaysBeforeMucusPeak = [
|
||||
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||
{ date: '2018-06-02', temperature: 36.65 },
|
||||
{ date: '2018-06-04', temperature: 36.6 },
|
||||
{ date: '2018-06-05', temperature: 36.55 },
|
||||
{ date: '2018-06-06', temperature: 36.7, mucus: 0 },
|
||||
{ date: '2018-06-09', temperature: 36.5, mucus: 1 },
|
||||
{ date: '2018-06-10', temperature: 36.4, mucus: 2 },
|
||||
{ date: '2018-06-13', temperature: 36.45, mucus: 2 },
|
||||
{ date: '2018-06-14', temperature: 36.5, mucus: 2 },
|
||||
{ date: '2018-06-15', temperature: 36.55, mucus: 1 },
|
||||
{ date: '2018-06-16', temperature: 36.7, mucus: 2 },
|
||||
{ date: '2018-06-17', temperature: 36.65, mucus: 2 },
|
||||
{ date: '2018-06-18', temperature: 36.75, mucus: 2 },
|
||||
{ date: '2018-06-19', temperature: 36.8, mucus: 3 },
|
||||
{ date: '2018-06-20', temperature: 36.85, mucus: 2 },
|
||||
{ date: '2018-06-21', temperature: 36.8, mucus: 4 },
|
||||
{ date: '2018-06-22', temperature: 36.9, mucus: 2 },
|
||||
{ date: '2018-06-25', temperature: 36.9, mucus: 1 },
|
||||
{ date: '2018-06-26', temperature: 36.8, mucus: 1 },
|
||||
].map(convertToSymptoFormat)
|
||||
|
||||
const mucusPeakTwoDaysBeforeFhm = [
|
||||
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||
{ date: '2018-06-02', temperature: 36.65 },
|
||||
{ date: '2018-06-04', temperature: 36.6 },
|
||||
{ date: '2018-06-05', temperature: 36.55, mucus: 2 },
|
||||
{ date: '2018-06-06', temperature: 36.7, mucus: 0 },
|
||||
{ date: '2018-06-09', temperature: 36.5, mucus: 4 },
|
||||
{ date: '2018-06-10', temperature: 36.4, mucus: 2 },
|
||||
{ date: '2018-06-13', temperature: 36.45, mucus: 3 },
|
||||
{ date: '2018-06-14', temperature: 36.5, mucus: 4 },
|
||||
{ date: '2018-06-15', temperature: 36.55, mucus: 4 },
|
||||
{ date: '2018-06-16', temperature: 36.7, mucus: 4 },
|
||||
{ date: '2018-06-17', temperature: 36.65, mucus: 3 },
|
||||
{ date: '2018-06-18', temperature: 36.75, mucus: 2 },
|
||||
{ date: '2018-07-02', temperature: 36.8, mucus: 3 },
|
||||
{ date: '2018-07-03', temperature: 36.9, mucus: 2 },
|
||||
{ date: '2018-07-04', temperature: 36.8, mucus: 2 },
|
||||
].map(convertToSymptoFormat)
|
||||
|
||||
const mucusPeak5DaysAfterFhm = [
|
||||
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||
{ date: '2018-06-02', temperature: 36.65, mucus: 2 },
|
||||
{ date: '2018-06-04', temperature: 36.6 },
|
||||
{ date: '2018-06-05', temperature: 36.55 },
|
||||
{ date: '2018-06-06', temperature: 36.7, mucus: 0 },
|
||||
{ date: '2018-06-09', temperature: 36.5, mucus: 4 },
|
||||
{ date: '2018-06-10', temperature: 36.4, mucus: 2 },
|
||||
{ date: '2018-06-13', temperature: 36.45, mucus: 3 },
|
||||
{ date: '2018-06-14', temperature: 36.5, mucus: 3 },
|
||||
{ date: '2018-06-15', temperature: 36.55, mucus: 3 },
|
||||
{ date: '2018-06-16', temperature: 36.7, mucus: 3 },
|
||||
{ date: '2018-06-17', temperature: 36.65, mucus: 3 },
|
||||
{ date: '2018-06-18', temperature: 36.60, mucus: 2 },
|
||||
{ date: '2018-06-19', temperature: 36.8, mucus: 2 },
|
||||
{ date: '2018-06-20', temperature: 36.85, mucus: 2 },
|
||||
{ date: '2018-06-21', temperature: 36.8, mucus: 2 },
|
||||
{ date: '2018-06-22', temperature: 36.9, mucus: 2 },
|
||||
{ date: '2018-06-25', temperature: 36.9, mucus: 1 },
|
||||
{ date: '2018-06-26', temperature: 36.8, mucus: 4 },
|
||||
{ date: '2018-06-30', temperature: 36.9, mucus: 1 },
|
||||
{ date: '2018-07-01', temperature: 36.9, mucus: 1 },
|
||||
{ date: '2018-07-02', temperature: 36.9, mucus: 1 }
|
||||
].map(convertToSymptoFormat)
|
||||
|
||||
const fhm5DaysAfterMucusPeak = [
|
||||
{ date: '2018-06-01', temperature: 36.6, bleeding: 2 },
|
||||
{ date: '2018-06-02', temperature: 36.65 },
|
||||
{ date: '2018-06-04', temperature: 36.6 },
|
||||
{ date: '2018-06-05', temperature: 36.55 },
|
||||
{ date: '2018-06-06', temperature: 36.7, mucus: 0 },
|
||||
{ date: '2018-06-09', temperature: 36.5, mucus: 4 },
|
||||
{ date: '2018-06-10', temperature: 36.4, mucus: 2 },
|
||||
{ date: '2018-06-13', temperature: 36.45, mucus: 3 },
|
||||
{ date: '2018-06-14', temperature: 36.5, mucus: 4 },
|
||||
{ date: '2018-06-15', temperature: 36.55, mucus: 3 },
|
||||
{ date: '2018-06-16', temperature: 36.7, mucus: 3 },
|
||||
{ date: '2018-06-17', temperature: 36.65, mucus: 3 },
|
||||
{ date: '2018-06-18', temperature: 36.75, mucus: 2 },
|
||||
{ date: '2018-06-19', temperature: 36.8, mucus: 2 },
|
||||
{ date: '2018-06-20', temperature: 36.85, mucus: 2 },
|
||||
{ date: '2018-06-21', temperature: 36.8, mucus: 2 },
|
||||
{ date: '2018-06-22', temperature: 36.9, mucus: 2 },
|
||||
{ date: '2018-06-25', temperature: 36.9, mucus: 1 },
|
||||
{ date: '2018-06-26', temperature: 36.8, mucus: 4 },
|
||||
{ date: '2018-06-27', temperature: 36.9, mucus: 1 }
|
||||
].map(convertToSymptoFormat)
|
||||
|
||||
export {
|
||||
cycleWithoutTempShift,
|
||||
cycleWithTempAndMucusShift,
|
||||
@@ -108,5 +220,10 @@ export {
|
||||
cycleWithTempShift,
|
||||
cycleWithoutAnyShifts,
|
||||
fiveDayCycle,
|
||||
cycleWithEarlyMucus
|
||||
cycleWithEarlyMucus,
|
||||
fhm5DaysAfterMucusPeak,
|
||||
fhmTwoDaysBeforeMucusPeak,
|
||||
mucusPeak5DaysAfterFhm,
|
||||
mucusPeakAndFhmOnSameDay,
|
||||
mucusPeakTwoDaysBeforeFhm
|
||||
}
|
||||
+164
-1
@@ -8,7 +8,12 @@ import {
|
||||
cycleWithTempShift,
|
||||
cycleWithoutAnyShifts,
|
||||
fiveDayCycle,
|
||||
cycleWithEarlyMucus
|
||||
cycleWithEarlyMucus,
|
||||
mucusPeakAndFhmOnSameDay,
|
||||
fhmTwoDaysBeforeMucusPeak,
|
||||
fhm5DaysAfterMucusPeak,
|
||||
mucusPeak5DaysAfterFhm,
|
||||
mucusPeakTwoDaysBeforeFhm
|
||||
} from './fixtures'
|
||||
|
||||
const expect = chai.expect
|
||||
@@ -139,6 +144,164 @@ describe('sympto', () => {
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
describe('combining first higher measurment and mucus peak', () => {
|
||||
it('with fhM + mucus peak on same day finds correct start of post-ovu phase', () => {
|
||||
const status = getSensiplanStatus({
|
||||
cycle: mucusPeakAndFhmOnSameDay,
|
||||
previousCycle: cycleWithTempShift
|
||||
})
|
||||
|
||||
expect(status.temperatureShift).to.be.an('object')
|
||||
expect(status.mucusShift).to.be.an('object')
|
||||
expect(status.assumeFertility).to.be.false()
|
||||
expect(Object.keys(status.phases).length).to.eql(3)
|
||||
expect(status.phases.preOvulatory).to.eql({
|
||||
start: { date: '2018-06-01' },
|
||||
end: { date: '2018-06-05' },
|
||||
cycleDays: mucusPeakAndFhmOnSameDay.filter(({date}) => date <= '2018-06-05')
|
||||
})
|
||||
expect(status.phases.periOvulatory).to.eql({
|
||||
start: { date: '2018-06-06' },
|
||||
end: { date: '2018-06-21', time: '18:00' },
|
||||
cycleDays: mucusPeakAndFhmOnSameDay.filter(({date}) => {
|
||||
return date > '2018-06-05' && date <= '2018-06-21'
|
||||
})
|
||||
})
|
||||
expect(status.phases.postOvulatory).to.eql({
|
||||
start: {
|
||||
date: '2018-06-21',
|
||||
time: '18:00'
|
||||
},
|
||||
cycleDays: mucusPeakAndFhmOnSameDay.filter(({date}) => date >= '2018-06-21')
|
||||
})
|
||||
})
|
||||
|
||||
it('with fhM 2 days before mucus peak waits for end of mucus eval', () => {
|
||||
const status = getSensiplanStatus({
|
||||
cycle: fhmTwoDaysBeforeMucusPeak,
|
||||
previousCycle: cycleWithTempShift
|
||||
})
|
||||
|
||||
expect(status.temperatureShift).to.be.an('object')
|
||||
expect(status.mucusShift).to.be.an('object')
|
||||
expect(status.assumeFertility).to.be.false()
|
||||
expect(Object.keys(status.phases).length).to.eql(3)
|
||||
expect(status.phases.preOvulatory).to.eql({
|
||||
start: { date: '2018-06-01' },
|
||||
end: { date: '2018-06-05' },
|
||||
cycleDays: fhmTwoDaysBeforeMucusPeak.filter(({date}) => date <= '2018-06-05')
|
||||
})
|
||||
expect(status.phases.periOvulatory).to.eql({
|
||||
start: { date: '2018-06-06' },
|
||||
end: { date: '2018-06-26', time: '18:00' },
|
||||
cycleDays: fhmTwoDaysBeforeMucusPeak.filter(({date}) => {
|
||||
return date > '2018-06-05' && date <= '2018-06-26'
|
||||
})
|
||||
})
|
||||
expect(status.phases.postOvulatory).to.eql({
|
||||
start: {
|
||||
date: '2018-06-26',
|
||||
time: '18:00'
|
||||
},
|
||||
cycleDays: fhmTwoDaysBeforeMucusPeak.filter(({date}) => date >= '2018-06-26')
|
||||
})
|
||||
})
|
||||
|
||||
it('with another mucus peak 5 days after fHM ignores it', () => {
|
||||
const status = getSensiplanStatus({
|
||||
cycle: mucusPeak5DaysAfterFhm,
|
||||
previousCycle: cycleWithTempShift
|
||||
})
|
||||
|
||||
expect(status.temperatureShift).to.be.an('object')
|
||||
expect(status.mucusShift).to.be.an('object')
|
||||
expect(status.assumeFertility).to.be.false()
|
||||
expect(Object.keys(status.phases).length).to.eql(3)
|
||||
expect(status.phases.preOvulatory).to.eql({
|
||||
start: { date: '2018-06-01' },
|
||||
end: { date: '2018-06-01' },
|
||||
cycleDays: mucusPeak5DaysAfterFhm.filter(({date}) => date <= '2018-06-01')
|
||||
})
|
||||
expect(status.phases.periOvulatory).to.eql({
|
||||
start: { date: '2018-06-02' },
|
||||
end: { date: '2018-06-22', time: '18:00' },
|
||||
cycleDays: mucusPeak5DaysAfterFhm.filter(({date}) => {
|
||||
return date > '2018-06-01' && date <= '2018-06-22'
|
||||
})
|
||||
})
|
||||
expect(status.phases.postOvulatory).to.eql({
|
||||
start: {
|
||||
date: '2018-06-22',
|
||||
time: '18:00'
|
||||
},
|
||||
cycleDays: mucusPeak5DaysAfterFhm.filter(({date}) => date >= '2018-06-22')
|
||||
})
|
||||
})
|
||||
|
||||
it('with mucus peak 2 days before fhM waits for end of temp eval', () => {
|
||||
const status = getSensiplanStatus({
|
||||
cycle: mucusPeakTwoDaysBeforeFhm,
|
||||
previousCycle: cycleWithTempShift
|
||||
})
|
||||
|
||||
expect(status.temperatureShift).to.be.an('object')
|
||||
expect(status.mucusShift).to.be.an('object')
|
||||
expect(status.assumeFertility).to.be.false()
|
||||
expect(Object.keys(status.phases).length).to.eql(3)
|
||||
expect(status.phases.preOvulatory).to.eql({
|
||||
start: { date: '2018-06-01' },
|
||||
end: { date: '2018-06-04' },
|
||||
cycleDays: mucusPeakTwoDaysBeforeFhm.filter(({date}) => date <= '2018-06-04')
|
||||
})
|
||||
expect(status.phases.periOvulatory).to.eql({
|
||||
start: { date: '2018-06-05' },
|
||||
end: { date: '2018-07-03', time: '18:00' },
|
||||
cycleDays: mucusPeakTwoDaysBeforeFhm.filter(({date}) => {
|
||||
return date > '2018-06-04' && date <= '2018-07-03'
|
||||
})
|
||||
})
|
||||
expect(status.phases.postOvulatory).to.eql({
|
||||
start: {
|
||||
date: '2018-07-03',
|
||||
time: '18:00'
|
||||
},
|
||||
cycleDays: mucusPeakTwoDaysBeforeFhm.filter(({date}) => date >= '2018-07-03')
|
||||
})
|
||||
})
|
||||
|
||||
it('with mucus peak 5 days before fhM waits for end of temp eval', () => {
|
||||
const status = getSensiplanStatus({
|
||||
cycle: fhm5DaysAfterMucusPeak,
|
||||
previousCycle: cycleWithTempShift
|
||||
})
|
||||
|
||||
expect(status.temperatureShift).to.be.an('object')
|
||||
expect(status.mucusShift).to.be.an('object')
|
||||
expect(status.assumeFertility).to.be.false()
|
||||
expect(Object.keys(status.phases).length).to.eql(3)
|
||||
expect(status.phases.preOvulatory).to.eql({
|
||||
start: { date: '2018-06-01' },
|
||||
end: { date: '2018-06-05' },
|
||||
cycleDays: fhm5DaysAfterMucusPeak.filter(({date}) => date <= '2018-06-05')
|
||||
})
|
||||
expect(status.phases.periOvulatory).to.eql({
|
||||
start: { date: '2018-06-06' },
|
||||
end: { date: '2018-06-21', time: '18:00' },
|
||||
cycleDays: fhm5DaysAfterMucusPeak.filter(({date}) => {
|
||||
return date > '2018-06-05' && date <= '2018-06-21'
|
||||
})
|
||||
})
|
||||
expect(status.phases.postOvulatory).to.eql({
|
||||
start: {
|
||||
date: '2018-06-21',
|
||||
time: '18:00'
|
||||
},
|
||||
cycleDays: fhm5DaysAfterMucusPeak.filter(({date}) => date >= '2018-06-21')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when args are wrong', () => {
|
||||
it('throws when arg object is not in right format', () => {
|
||||
const wrongObject = { hello: 'world' }
|
||||
|
||||
Reference in New Issue
Block a user