Skip to content

Commit

Permalink
Merge pull request #27 from jasoncalabrese/wip/iob-test
Browse files Browse the repository at this point in the history
a couple basic IOB test to make sure 3hr and 4hr dia's work
  • Loading branch information
scottleibrand committed Nov 18, 2015
2 parents 08cdc23 + 6544b3b commit 1abc2c7
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/iob/total.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function iobTotal(opts, time) {
//}

treatments.forEach(function(treatment) {
if(treatment.date < time.getTime( )) {
if(treatment.date <= time.getTime( )) {
var dia = profile_data.dia;
var tIOB = iobCalc(treatment, time, dia);
if (tIOB && tIOB.iobContrib) iob += tIOB.iobContrib;
Expand Down
83 changes: 83 additions & 0 deletions tests/iob.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
'use strict';

require('should');

describe('IOB', function ( ) {

it('should calculate IOB', function() {

var now = Date.now()
, timestamp = new Date(now).toISOString()
, inputs = {
clock: timestamp
, history: [{
_type: 'Bolus'
, amount: 1
, timestamp: timestamp
}]
, profile: {
dia: 3
}
};

var rightAfterBolus = require('../lib/iob')(inputs);
rightAfterBolus.iob.should.equal(1);
rightAfterBolus.bolusiob.should.equal(1);

var hourLaterInputs = inputs;
hourLaterInputs.clock = new Date(now + (60 * 60 * 1000)).toISOString();
var hourLater = require('../lib/iob')(hourLaterInputs);
hourLater.iob.should.be.lessThan(1);
hourLater.bolusiob.should.be.lessThan(.5);
hourLater.iob.should.be.greaterThan(0);

var afterDIAInputs = inputs;
afterDIAInputs.clock = new Date(now + (3 * 60 * 60 * 1000)).toISOString();
var afterDIA = require('../lib/iob')(afterDIAInputs);

afterDIA.iob.should.equal(0);
afterDIA.bolusiob.should.equal(0);

});

it('should calculate IOB using a 4 hour duration', function() {

var now = Date.now()
, timestamp = new Date(now).toISOString()
, inputs = {
clock: timestamp
, history: [{
_type: 'Bolus'
, amount: 1
, timestamp: timestamp
}]
, profile: {
dia: 4
}
};

var rightAfterBolus = require('../lib/iob')(inputs);
rightAfterBolus.iob.should.equal(1);
rightAfterBolus.bolusiob.should.equal(1);

var hourLaterInputs = inputs;
hourLaterInputs.clock = new Date(now + (60 * 60 * 1000)).toISOString();
var hourLater = require('../lib/iob')(hourLaterInputs);
hourLater.iob.should.be.lessThan(1);
hourLater.bolusiob.should.be.lessThan(.5);
hourLater.iob.should.be.greaterThan(0);

var after3hDIAInputs = inputs;
after3hDIAInputs.clock = new Date(now + (3 * 60 * 60 * 1000)).toISOString();
var after3hDIA = require('../lib/iob')(after3hDIAInputs);
after3hDIA.iob.should.greaterThan(0);

var after4hDIAInputs = inputs;
after4hDIAInputs.clock = new Date(now + (4 * 60 * 60 * 1000)).toISOString();
var after4hDIA = require('../lib/iob')(after4hDIAInputs);
after4hDIA.iob.should.equal(0);

});


});

0 comments on commit 1abc2c7

Please sign in to comment.