diff --git a/.vscode/launch.json b/.vscode/launch.json index dc95908..989f78a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,13 +12,9 @@ "/**" ], "env": {"CI": "true"}, - //"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts", "args": ["--verbose", "-i", "--no-cache", "${workspaceFolder}/src/components/__tests__/DbTextInputComponent.test.tsx"], "console": "integratedTerminal", "program": "${workspaceRoot}/node_modules/.bin/jest", - // "outFiles": [ - // "${workspaceFolder}/**/*.js" - // ] } ] } \ No newline at end of file diff --git a/src/components/__tests__/DbButtonComponent.test.tsx b/src/components/__tests__/DbButtonComponent.test.tsx index 3eccdf8..c4345e9 100644 --- a/src/components/__tests__/DbButtonComponent.test.tsx +++ b/src/components/__tests__/DbButtonComponent.test.tsx @@ -31,7 +31,12 @@ it('renders correctly when pressed', async () => { let i = 0 const Sample = () => ( - i++} /> + i++} + /> ) render() diff --git a/src/core/QuickInsulin.ts b/src/core/QuickInsulin.ts index f16c927..955b369 100644 --- a/src/core/QuickInsulin.ts +++ b/src/core/QuickInsulin.ts @@ -4,7 +4,7 @@ import longtermAdaptationCriteria from './quick_insulin_longterm_adaptation_crit import {Trend, TrendService} from './TrendService' export interface GlycemiaObjective { - min: number, + min: number max: number } @@ -19,14 +19,11 @@ export class MealGlycemiaMeasure { } private computeTrend(glycemiaObjective: GlycemiaObjective) { - if (this._afterMealGlycemia > glycemiaObjective.max) { return Trend.UP - } - else if (this._afterMealGlycemia < glycemiaObjective.min) { + } else if (this._afterMealGlycemia < glycemiaObjective.min) { return Trend.DOWN - } - else { + } else { return Trend.STABLE } } @@ -34,7 +31,6 @@ export class MealGlycemiaMeasure { public get trend() { return this._trend } - } export class PuntualAdaptationResult { @@ -72,7 +68,6 @@ export class PuntualAdaptationResult { } export class QuickInsulin { - public computePunctualAdaptation( glycemiaLevel: number, acetoneLevel?: number, @@ -125,7 +120,6 @@ export class QuickInsulin { findObjectiveCriterion = () => { return punctualAdaptationCriteria.find(c => c.objective) } - } export class AcetoneNeededError extends Error { diff --git a/src/core/__tests__/QuickInsulin.test.ts b/src/core/__tests__/QuickInsulin.test.ts index 3a92809..a99df08 100644 --- a/src/core/__tests__/QuickInsulin.test.ts +++ b/src/core/__tests__/QuickInsulin.test.ts @@ -1,5 +1,9 @@ import {test, expect} from '@jest/globals' -import {AcetoneNeededError, MealGlycemiaMeasure, QuickInsulin} from '../QuickInsulin' +import { + AcetoneNeededError, + MealGlycemiaMeasure, + QuickInsulin, +} from '../QuickInsulin' jest.mock( '../quick_insulin_punctual_adaptation_criteria.json', @@ -63,117 +67,112 @@ jest.mock( describe('punctual adaptation', () => { test('adaptation for glycemia measure 0.8 is 0', () => { let quickInsulin = new QuickInsulin() - + let glycemiaLevel = 0.8 - + expect( quickInsulin.computePunctualAdaptation(glycemiaLevel).totalAdaptation, ).toEqual(0) }) - + test('adaptation for glycemia measure 2.3 is +2', () => { let quickInsulin = new QuickInsulin() - + let glycemiaLevel = 2.3 - + expect( quickInsulin.computePunctualAdaptation(glycemiaLevel).totalAdaptation, ).toEqual(2) }) - + test('adaptation for glycemia measure 1.8 is +1', () => { let quickInsulin = new QuickInsulin() - + let glycemiaLevel = 1.8 - + expect( quickInsulin.computePunctualAdaptation(glycemiaLevel).totalAdaptation, ).toEqual(1) }) - + test('exception when condition not found', () => { let quickInsulin = new QuickInsulin() - + let glycemiaLevel = 2.1 - + const t = () => quickInsulin.computePunctualAdaptation(glycemiaLevel) - + expect(t).toThrowError() }) - + test('adaptation for glycemia measure 2.6 and acetone level = 0 is +3', () => { let quickInsulin = new QuickInsulin() - + let glycemiaLevel = 2.6 let acetoneLevel = 0 - + expect( quickInsulin.computePunctualAdaptation(glycemiaLevel, acetoneLevel) .totalAdaptation, ).toEqual(3) }) - + test('acetone level required error when glycemia >= 2.5', () => { let quickInsulin = new QuickInsulin() - + let glycemiaLevel = 2.5 - + const t = () => { quickInsulin.computePunctualAdaptation(glycemiaLevel).totalAdaptation } - + expect(t).toThrow(AcetoneNeededError) }) - }) describe('long term adaptaion', () => { - let objective = {min: 0.7, max: 1.4} - it.each( + it.each([ [ + 'Adaptation is +2 when trend is UP', [ - 'Adaptation is +2 when trend is UP', - [ - new MealGlycemiaMeasure(1.6, objective), - new MealGlycemiaMeasure(1.7, objective), - new MealGlycemiaMeasure(1.5, objective) - ], - +2 + new MealGlycemiaMeasure(1.6, objective), + new MealGlycemiaMeasure(1.7, objective), + new MealGlycemiaMeasure(1.5, objective), ], + +2, + ], + [ + 'Adaptation is -2 when trend is DOWN', [ - 'Adaptation is -2 when trend is DOWN', - [ - new MealGlycemiaMeasure(0.6, objective), - new MealGlycemiaMeasure(0.55, objective), - new MealGlycemiaMeasure(0.65, objective) - ], - -2 + new MealGlycemiaMeasure(0.6, objective), + new MealGlycemiaMeasure(0.55, objective), + new MealGlycemiaMeasure(0.65, objective), ], + -2, + ], + [ + 'Adaptation is 0 when no trend', [ - 'Adaptation is 0 when no trend', - [ - new MealGlycemiaMeasure(0.6, objective), - new MealGlycemiaMeasure(0.55, objective), - new MealGlycemiaMeasure(0.65, objective) - ], - -2 + new MealGlycemiaMeasure(0.6, objective), + new MealGlycemiaMeasure(0.55, objective), + new MealGlycemiaMeasure(0.65, objective), ], + -2, + ], + [ + 'Adaptation is 0 when trend is STABLE', [ - 'Adaptation is 0 when trend is STABLE', - [ - new MealGlycemiaMeasure(1.3, objective), - new MealGlycemiaMeasure(0.8, objective), - new MealGlycemiaMeasure(0.99, objective) - ], - 0 + new MealGlycemiaMeasure(1.3, objective), + new MealGlycemiaMeasure(0.8, objective), + new MealGlycemiaMeasure(0.99, objective), ], - ] - ) ('%s', (_label, measures, expectedAdaptation) => { - let quickInsulin = new QuickInsulin() - let adaptation = quickInsulin.computeLongtermAdaptation(measures) - expect(adaptation).toEqual(expectedAdaptation) - }) - -}) \ No newline at end of file + 0, + ], + ])('%s', (_label, measures, expectedAdaptation) => { + let quickInsulin = new QuickInsulin() + let adaptation = quickInsulin.computeLongtermAdaptation(measures) + expect(adaptation).toEqual(expectedAdaptation) + }) +}) diff --git a/src/core/__tests__/TrendService.test.ts b/src/core/__tests__/TrendService.test.ts index 96bb308..37329bd 100644 --- a/src/core/__tests__/TrendService.test.ts +++ b/src/core/__tests__/TrendService.test.ts @@ -1,27 +1,41 @@ import {test, expect} from '@jest/globals' -import { Trend, TrendService } from '../TrendService' +import {Trend, TrendService} from '../TrendService' describe('trend service', () => { - test.each([ - [{trend: Trend.DOWN}, {trend:Trend.UP} , {trend: Trend.STABLE} , Trend.STABLE], - [{trend: Trend.DOWN}, {trend:Trend.DOWN} , {trend: Trend.DOWN} , Trend.DOWN], - [{trend: Trend.UP}, {trend:Trend.UP} , {trend: Trend.UP} , Trend.UP], - [{trend: Trend.STABLE}, {trend:Trend.STABLE} , {trend: Trend.STABLE} , Trend.STABLE], - ]) + [ + {trend: Trend.DOWN}, + {trend: Trend.UP}, + {trend: Trend.STABLE}, + Trend.STABLE, + ], + [{trend: Trend.DOWN}, {trend: Trend.DOWN}, {trend: Trend.DOWN}, Trend.DOWN], + [{trend: Trend.UP}, {trend: Trend.UP}, {trend: Trend.UP}, Trend.UP], + [ + {trend: Trend.STABLE}, + {trend: Trend.STABLE}, + {trend: Trend.STABLE}, + Trend.STABLE, + ], + ])( + ' when trend1 = %j and trend2 = %j and trend3 = %j, computed trend must give %s', ( - ' when trend1 = %j and trend2 = %j and trend3 = %j, computed trend must give %s', - (trend1: {trend: Trend}, trend2: {trend: Trend}, trend3: {trend: Trend}, expected: Trend) => { - let trendService = new TrendService() - expect(trendService.findTrend([trend1, trend2, trend3])).toEqual(expected) - } - ) - }) - - it('throws error when not enough measures are provided', () => { - let trendService = new TrendService() - let t = () => {trendService.findTrend([{trend: Trend.DOWN}, {trend: Trend.DOWN}])} + trend1: {trend: Trend}, + trend2: {trend: Trend}, + trend3: {trend: Trend}, + expected: Trend, + ) => { + let trendService = new TrendService() + expect(trendService.findTrend([trend1, trend2, trend3])).toEqual(expected) + }, + ) +}) - expect(t).toThrowError() +it('throws error when not enough measures are provided', () => { + let trendService = new TrendService() + let t = () => { + trendService.findTrend([{trend: Trend.DOWN}, {trend: Trend.DOWN}]) + } - }) + expect(t).toThrowError() +})