<commit_before>'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)[0];
    rightAfterBolus.iob.should.equal(1);
    rightAfterBolus.bolussnooze.should.equal(1);

    var hourLaterInputs = inputs;
    hourLaterInputs.clock = new Date(now + (60 * 60 * 1000)).toISOString();
    var hourLater = require('../lib/iob')(hourLaterInputs)[0];
    hourLater.iob.should.be.lessThan(1);
    hourLater.bolussnooze.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)[0];

    afterDIA.iob.should.equal(0);
    afterDIA.bolussnooze.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: [{<commit_msg>Increase test coverage by testing temp basal calculations (#139)<commit_after>'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)[0];
    rightAfterBolus.iob.should.equal(1);
    rightAfterBolus.bolussnooze.should.equal(1);

    var hourLaterInputs = inputs;
    hourLaterInputs.clock = new Date(now + (60 * 60 * 1000)).toISOString();
    var hourLater = require('../lib/iob')(hourLaterInputs)[0];
    hourLater.iob.should.be.lessThan(1);
    hourLater.bolussnooze.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)[0];

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

  });

  it('should calculate IOB with Temp Basals', function() {

    var now = Date.now()
      , timestamp = new Date(now).toISOString()
      , timestampEarly = new Date(now - (60 * 60 * 1000)).toISOString()
      , inputs = {
        clock: timestamp
        , history: [{
        _type: 'TempBasalDuration'
        ,'duration (min)': 30
    	, date: timestampEarly
        },{_type: 'TempBasal'
        , rate: 2
        , date: timestampEarly
        , timestamp: timestampEarly
        },
        {
        _type: 'TempBasalDuration'
        ,'duration (min)': 30
    	, date: timestamp
        },{_type: 'TempBasal'
        , rate: 2
        , date: timestamp
        , timestamp: timestamp
        }]
        , profile: {
          dia: 3,
          current_basal: 1
        }
      };

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

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

    var now = Date.now()
      , timestamp = new Date(now).toISOString()
      , inputs = {
        clock: timestamp
        , history: [{
{'fraction_non_alphanumeric': 0.1481578947368421, 'fraction_numerical': 0.02368421052631579, 'mean_word_length': 2.3877005347593583, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4762877', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1232, 'n_words': 244}