Make previousCycle explicit in signature

This commit is contained in:
Julia Friesel
2018-07-18 10:02:11 +02:00
parent b455a030cc
commit 52b6e5de0a
2 changed files with 33 additions and 28 deletions
+5 -6
View File
@@ -4,8 +4,8 @@ import getPreOvulatoryPhase from './pre-ovulatory'
import { LocalDate } from 'js-joda' import { LocalDate } from 'js-joda'
import assert from 'assert' import assert from 'assert'
export default function getSymptoThermalStatus({ cycle, previousCycles = [] }) { export default function getSymptoThermalStatus({ cycle, previousCycle, earlierCycles = [] }) {
throwIfArgsAreNotInRequiredFormat([cycle, ...previousCycles]) throwIfArgsAreNotInRequiredFormat([cycle, ...earlierCycles])
const status = { const status = {
assumeFertility: true, assumeFertility: true,
@@ -14,11 +14,10 @@ export default function getSymptoThermalStatus({ cycle, previousCycles = [] }) {
// if there was no first higher measurement in the previous cycle, // if there was no first higher measurement in the previous cycle,
// no infertile pre-ovulatory phase may be assumed // no infertile pre-ovulatory phase may be assumed
const lastCycle = previousCycles[previousCycles.length - 1] if (previousCycle) {
if (lastCycle) { const statusForLast = getSymptoThermalStatus({ cycle: previousCycle })
const statusForLast = getSymptoThermalStatus({ cycle: lastCycle })
if (statusForLast.temperatureShift) { if (statusForLast.temperatureShift) {
status.phases.preOvulatory = getPreOvulatoryPhase(cycle, previousCycles) status.phases.preOvulatory = getPreOvulatoryPhase(cycle, [previousCycle, ...earlierCycles])
if (status.phases.preOvulatory.cycleDays.length === cycle.length) { if (status.phases.preOvulatory.cycleDays.length === cycle.length) {
status.assumeFertility = false status.assumeFertility = false
return status return status
+28 -22
View File
@@ -26,7 +26,7 @@ describe('sympto', () => {
it('with no shifts detects only peri-ovulatory', function () { it('with no shifts detects only peri-ovulatory', function () {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: cycleWithoutAnyShifts, cycle: cycleWithoutAnyShifts,
previousCycles: [cycleWithoutFhm,] previousCycle: cycleWithoutFhm
}) })
expect(status).to.eql({ expect(status).to.eql({
@@ -43,7 +43,7 @@ describe('sympto', () => {
it('with shifts detects only peri-ovulatory and post-ovulatory', () => { it('with shifts detects only peri-ovulatory and post-ovulatory', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: longAndComplicatedCycle, cycle: longAndComplicatedCycle,
previousCycles: [cycleWithoutFhm,] previousCycle: cycleWithoutFhm
}) })
expect(status.temperatureShift).to.be.an('object') expect(status.temperatureShift).to.be.an('object')
@@ -71,7 +71,7 @@ describe('sympto', () => {
it('according to 5-day-rule', function () { it('according to 5-day-rule', function () {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: fiveDayCycle, cycle: fiveDayCycle,
previousCycles: [cycleWithFhm] previousCycle: cycleWithFhm
}) })
expect(Object.keys(status.phases).length).to.eql(1) expect(Object.keys(status.phases).length).to.eql(1)
@@ -88,7 +88,7 @@ describe('sympto', () => {
it('according to 5-day-rule', function () { it('according to 5-day-rule', function () {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: cycleWithTempAndNoMucusShift, cycle: cycleWithTempAndNoMucusShift,
previousCycles: [cycleWithFhm] previousCycle: cycleWithFhm
}) })
expect(Object.keys(status.phases).length).to.eql(2) expect(Object.keys(status.phases).length).to.eql(2)
@@ -108,7 +108,7 @@ describe('sympto', () => {
it('according to 5-day-rule with shortened pre-phase', function () { it('according to 5-day-rule with shortened pre-phase', function () {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: cycleWithEarlyMucus, cycle: cycleWithEarlyMucus,
previousCycles: [cycleWithFhm] previousCycle: cycleWithFhm
}) })
expect(Object.keys(status.phases).length).to.eql(2) expect(Object.keys(status.phases).length).to.eql(2)
@@ -128,7 +128,7 @@ describe('sympto', () => {
it('according to 5-day-rule', function () { it('according to 5-day-rule', function () {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: longAndComplicatedCycle, cycle: longAndComplicatedCycle,
previousCycles: [cycleWithFhm] previousCycle: cycleWithFhm
}) })
expect(Object.keys(status.phases).length).to.eql(3) expect(Object.keys(status.phases).length).to.eql(3)
@@ -159,7 +159,7 @@ describe('sympto', () => {
it('with fhM + mucus peak on same day finds start of postovu phase', () => { it('with fhM + mucus peak on same day finds start of postovu phase', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: mucusPeakAndFhmOnSameDay, cycle: mucusPeakAndFhmOnSameDay,
previousCycles: [cycleWithFhm] previousCycle: cycleWithFhm
}) })
expect(status.temperatureShift).to.be.an('object') expect(status.temperatureShift).to.be.an('object')
@@ -193,7 +193,7 @@ describe('sympto', () => {
it('with fhM 2 days before mucus peak waits for end of mucus eval', () => { it('with fhM 2 days before mucus peak waits for end of mucus eval', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: fhmTwoDaysBeforeMucusPeak, cycle: fhmTwoDaysBeforeMucusPeak,
previousCycles: [cycleWithFhm] previousCycle: cycleWithFhm
}) })
expect(status.temperatureShift).to.be.an('object') expect(status.temperatureShift).to.be.an('object')
@@ -227,7 +227,7 @@ describe('sympto', () => {
it('another example for mucus peak before temp shift', () => { it('another example for mucus peak before temp shift', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: mucusPeakSlightlyBeforeTempShift, cycle: mucusPeakSlightlyBeforeTempShift,
previousCycles: [cycleWithFhm] previousCycle: cycleWithFhm
}) })
expect(status.temperatureShift).to.be.an('object') expect(status.temperatureShift).to.be.an('object')
@@ -261,7 +261,7 @@ describe('sympto', () => {
it('with another mucus peak 5 days after fHM ignores it', () => { it('with another mucus peak 5 days after fHM ignores it', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: mucusPeak5DaysAfterFhm, cycle: mucusPeak5DaysAfterFhm,
previousCycles: [cycleWithFhm] previousCycle: cycleWithFhm
}) })
expect(status.temperatureShift).to.be.an('object') expect(status.temperatureShift).to.be.an('object')
@@ -295,7 +295,7 @@ describe('sympto', () => {
it('with mucus peak 2 days before fhM waits for end of temp eval', () => { it('with mucus peak 2 days before fhM waits for end of temp eval', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: mucusPeakTwoDaysBeforeFhm, cycle: mucusPeakTwoDaysBeforeFhm,
previousCycles: [cycleWithFhm] previousCycle: cycleWithFhm
}) })
expect(status.temperatureShift).to.be.an('object') expect(status.temperatureShift).to.be.an('object')
@@ -329,7 +329,7 @@ describe('sympto', () => {
it('with mucus peak 5 days before fhM waits for end of temp eval', () => { it('with mucus peak 5 days before fhM waits for end of temp eval', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: fhm5DaysAfterMucusPeak, cycle: fhm5DaysAfterMucusPeak,
previousCycles: [cycleWithFhm] previousCycle: cycleWithFhm
}) })
expect(status.temperatureShift).to.be.an('object') expect(status.temperatureShift).to.be.an('object')
@@ -365,7 +365,8 @@ describe('sympto', () => {
it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { it('shortens the pre-ovu phase if there is a previous <13 fhm', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: longAndComplicatedCycle, cycle: longAndComplicatedCycle,
previousCycles: [fhmOnDay12, ...Array(13).fill(fhmOnDay15)] previousCycle: fhmOnDay15,
earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)]
}) })
expect(status.temperatureShift).to.be.an('object') expect(status.temperatureShift).to.be.an('object')
@@ -398,7 +399,8 @@ describe('sympto', () => {
it('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { it('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: longAndComplicatedCycle, cycle: longAndComplicatedCycle,
previousCycles: Array(11).fill(fhmOnDay12) previousCycle: fhmOnDay12,
earlierCycles: Array(10).fill(fhmOnDay12)
}) })
expect(status.temperatureShift).to.be.an('object') expect(status.temperatureShift).to.be.an('object')
@@ -431,7 +433,8 @@ describe('sympto', () => {
it('shortens the pre-ovu phase if mucus occurs', () => { it('shortens the pre-ovu phase if mucus occurs', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: cycleWithEarlyMucus, cycle: cycleWithEarlyMucus,
previousCycles: Array(11).fill(fhmOnDay12) previousCycle: fhmOnDay12,
earlierCycles: Array(10).fill(fhmOnDay12)
}) })
expect(status.assumeFertility).to.be.true() expect(status.assumeFertility).to.be.true()
@@ -453,7 +456,8 @@ describe('sympto', () => {
it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: longAndComplicatedCycle, cycle: longAndComplicatedCycle,
previousCycles: Array(12).fill(fhmOnDay15) previousCycle: fhmOnDay15,
earlierCycles: Array(11).fill(fhmOnDay15)
}) })
expect(status.assumeFertility).to.be.false() expect(status.assumeFertility).to.be.false()
@@ -485,7 +489,8 @@ describe('sympto', () => {
it('does not lengthen the pre-ovu phase if < 12 cycles', () => { it('does not lengthen the pre-ovu phase if < 12 cycles', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: longAndComplicatedCycle, cycle: longAndComplicatedCycle,
previousCycles: Array(11).fill(fhmOnDay15) previousCycle: fhmOnDay15,
earlierCycles: Array(10).fill(fhmOnDay15)
}) })
expect(status.assumeFertility).to.be.false() expect(status.assumeFertility).to.be.false()
@@ -517,7 +522,8 @@ describe('sympto', () => {
it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { it('does not detect any pre-ovu phase if prev cycle had no fhm', () => {
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle: longAndComplicatedCycle, cycle: longAndComplicatedCycle,
previousCycles: [...Array(12).fill(fhmOnDay15), cycleWithoutFhm] previousCycle: cycleWithoutFhm,
earlierCycles: [...Array(12).fill(fhmOnDay15)]
}) })
expect(status.assumeFertility).to.be.false() expect(status.assumeFertility).to.be.false()
@@ -555,7 +561,7 @@ describe('sympto', () => {
hello: 'world', hello: 'world',
bleeding: { value: 0 } bleeding: { value: 0 }
}], }],
previousCycles: [[{ earlierCycles: [[{
date: '1992-09-09', date: '1992-09-09',
bleeding: { value: 0 } bleeding: { value: 0 }
}]] }]]
@@ -566,7 +572,7 @@ describe('sympto', () => {
temperature: {value: '35'}, temperature: {value: '35'},
bleeding: { value: 0 } bleeding: { value: 0 }
}], }],
previousCycles: [[{ earlierCycles: [[{
date: '1992-09-09', date: '1992-09-09',
bleeding: { value: 0 } bleeding: { value: 0 }
}]] }]]
@@ -576,7 +582,7 @@ describe('sympto', () => {
date: '09-14-2017', date: '09-14-2017',
bleeding: { value: 0 } bleeding: { value: 0 }
}], }],
previousCycles: [[{ earlierCycles: [[{
date: '1992-09-09', date: '1992-09-09',
bleeding: { value: 0 } bleeding: { value: 0 }
}]] }]]
@@ -590,7 +596,7 @@ describe('sympto', () => {
value: 'medium' value: 'medium'
} }
}], }],
previousCycles: [[ earlierCycles: [[
{ {
date: '2017-09-23', date: '2017-09-23',
} }