Skip to content

Commit

Permalink
workaround to a rounding issue that shows -0.00 iob
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Mar 23, 2015
1 parent 28e42c2 commit a7f68f4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/iob.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function calcTotal(treatments, profile, time) {

return {
iob: iob,
display: iob.toFixed(2),
display: iob.toFixed(2) == '-0.00' ? '0.00' : iob.toFixed(2),
activity: activity
};
}
Expand Down
24 changes: 21 additions & 3 deletions tests/iob.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var should = require('should');

var FIVE_MINS = 10 * 60 * 1000;

describe('IOB', function ( ) {
var iob = require('../lib/iob')();

Expand Down Expand Up @@ -34,16 +36,32 @@ describe('IOB', function ( ) {
it('should calculate IOB using defaults', function() {

var treatments = [{
created_at: (new Date()) - 1,
insulin: "1.00"
}];
created_at: (new Date()) - 1,
insulin: "1.00"
}];

var rightAfterBolus = iob.calcTotal(treatments);

rightAfterBolus.display.should.equal('1.00');

});

it('should not show a negative IOB when approaching 0', function() {

var time = new Date() - 1;

var treatments = [{
created_at: time,
insulin: "5.00"
}];

var whenApproaching0 = iob.calcTotal(treatments, undefined, new Date(time + (3 * 60 * 60 * 1000) - (90 * 1000)));

//before fix we got this: AssertionError: expected '-0.00' to be '0.00'
whenApproaching0.display.should.equal('0.00');

});

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

var time = new Date()
Expand Down

0 comments on commit a7f68f4

Please sign in to comment.