All files / tick-map/es6-tests tick-map.js

100% Statements 18/18
100% Branches 0/0
100% Functions 2/2
100% Lines 18/18
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 321x 1x       1x 1x 1x           1x 1x 1x 7x 7x 7x     1x 1x 7x 7x 7x     1x 1x    
const test = require('tap').test;
const TickMap = require('..');
 
// ES6-specific tests to be conditionally included
 
test('es6 iterator', t => {
  const tm = new TickMap();
  const ticks = [
    2.2,
    3.3,3.999,
    5.5,
    6.6,6,6.9999
  ];
  const sorted = [0,1,2,3,5,4,6];
  const values = [];
  ticks.forEach(function(tick) {
    const value = { prop: new Date() };
    values.push(value);
    tm.add(tick, value);
  });
 
  let idx = 0;
  for(let entry of tm) {
    t.equal(entry.tick, ticks[sorted[idx]]);
    t.equal(entry.value, values[sorted[idx]]);
    idx++;
  }
 
  t.equal(idx, ticks.length);
  t.end();
});