|
| 1 | +var Plotly = require('@src/plotly'); |
| 2 | + |
| 3 | +describe('Test search.js:', function() { |
| 4 | + 'use strict'; |
| 5 | + |
| 6 | + describe('findBin', function() { |
| 7 | + it('should work on ascending arrays', function() { |
| 8 | + expect(Plotly.Lib.findBin(-10000, [0, 1, 3])).toBe(-1); |
| 9 | + expect(Plotly.Lib.findBin(0.5, [0, 1, 3])).toBe(0); |
| 10 | + expect(Plotly.Lib.findBin(2, [0, 1, 3])).toBe(1); |
| 11 | + expect(Plotly.Lib.findBin(10000, [0, 1, 3])).toBe(2); |
| 12 | + // default: linelow falsey, so the line is in the higher bin |
| 13 | + expect(Plotly.Lib.findBin(1, [0, 1, 3])).toBe(1); |
| 14 | + // linelow truthy, so the line is in the lower bin |
| 15 | + expect(Plotly.Lib.findBin(1, [0, 1, 3], true)).toBe(0); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should work on decending arrays', function() { |
| 19 | + expect(Plotly.Lib.findBin(-10000, [3, 1, 0])).toBe(2); |
| 20 | + expect(Plotly.Lib.findBin(0.5, [3, 1, 0])).toBe(1); |
| 21 | + expect(Plotly.Lib.findBin(2, [3, 1, 0])).toBe(0); |
| 22 | + expect(Plotly.Lib.findBin(10000, [3, 1, 0])).toBe(-1); |
| 23 | + |
| 24 | + expect(Plotly.Lib.findBin(1, [3, 1, 0])).toBe(0); |
| 25 | + expect(Plotly.Lib.findBin(1, [3, 1, 0], true)).toBe(1); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should treat a length-1 array as ascending', function() { |
| 29 | + expect(Plotly.Lib.findBin(-1, [0])).toBe(-1); |
| 30 | + expect(Plotly.Lib.findBin(1, [0])).toBe(0); |
| 31 | + |
| 32 | + expect(Plotly.Lib.findBin(0, [0])).toBe(0); |
| 33 | + expect(Plotly.Lib.findBin(0, [0], true)).toBe(-1); |
| 34 | + }); |
| 35 | + // TODO: didn't test bins as objects {start, stop, size} |
| 36 | + }); |
| 37 | +}); |
0 commit comments