forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cob.test.js
91 lines (70 loc) · 2.53 KB
/
cob.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'use strict';
var should = require('should');
describe('COB', function ( ) {
var cob = require('../lib/plugins/cob')();
var profileData = {
sens: 95
, carbratio: 18
, carbs_hr: 30
};
var profile = require('../lib/profilefunctions')([profileData]);
it('should calculate IOB, multiple treatments', function() {
var treatments = [
{
"carbs": "100",
"created_at": new Date("2015-05-29T02:03:48.827Z")
},
{
"carbs": "10",
"created_at": new Date("2015-05-29T03:45:10.670Z")
}
];
var after100 = cob.cobTotal(treatments, profile, new Date("2015-05-29T02:03:49.827Z"));
var before10 = cob.cobTotal(treatments, profile, new Date("2015-05-29T03:45:10.670Z"));
var after10 = cob.cobTotal(treatments, profile, new Date("2015-05-29T03:45:11.670Z"));
after100.cob.should.equal(100);
Math.round(before10.cob).should.equal(59);
Math.round(after10.cob).should.equal(69); //WTF == 128
});
it('should calculate IOB, single treatment', function() {
var treatments = [
{
"carbs": "8",
"created_at": new Date("2015-05-29T04:40:40.174Z")
}
];
var rightAfterCorrection = new Date("2015-05-29T04:41:40.174Z");
var later1 = new Date("2015-05-29T05:04:40.174Z");
var later2 = new Date("2015-05-29T05:20:00.174Z");
var later3 = new Date("2015-05-29T05:50:00.174Z");
var later4 = new Date("2015-05-29T06:50:00.174Z");
var result1 = cob.cobTotal(treatments, profile, rightAfterCorrection);
var result2 = cob.cobTotal(treatments, profile, later1);
var result3 = cob.cobTotal(treatments, profile, later2);
var result4 = cob.cobTotal(treatments, profile, later3);
var result5 = cob.cobTotal(treatments, profile, later4);
result1.cob.should.equal(8);
result2.cob.should.equal(6);
result3.cob.should.equal(0);
result4.cob.should.equal(0);
result5.cob.should.equal(0);
});
it('set a pill to the current COB', function (done) {
var app = {};
var clientSettings = {};
var data = {
treatments: [{carbs: "8", "created_at": new Date()}]
, profile: require('../lib/profilefunctions')([profileData])
};
var pluginBase = {
updatePillText: function mockedUpdatePillText (plugin, options) {
options.value.should.equal('8g');
done();
}
};
var sandbox = require('../lib/sandbox')();
var sbx = sandbox.clientInit(app, clientSettings, Date.now(), pluginBase, data);
cob.setProperties(sbx);
cob.updateVisualisation(sbx);
});
});