|
1 require("../env"); |
|
2 require("../../d3"); |
|
3 |
|
4 var vows = require("vows"), |
|
5 assert = require("assert"); |
|
6 |
|
7 var suite = vows.describe("d3.bisect"); |
|
8 |
|
9 suite.addBatch({ |
|
10 "bisectLeft": { |
|
11 topic: function() { |
|
12 return d3.bisectLeft; |
|
13 }, |
|
14 "finds the index of an exact match": function(bisect) { |
|
15 var array = [1, 2, 3]; |
|
16 assert.equal(bisect(array, 1), 0); |
|
17 assert.equal(bisect(array, 2), 1); |
|
18 assert.equal(bisect(array, 3), 2); |
|
19 }, |
|
20 "finds the index of the first match": function(bisect) { |
|
21 var array = [1, 2, 2, 3]; |
|
22 assert.equal(bisect(array, 1), 0); |
|
23 assert.equal(bisect(array, 2), 1); |
|
24 assert.equal(bisect(array, 3), 3); |
|
25 }, |
|
26 "finds the insertion point of a non-exact match": function(bisect) { |
|
27 var array = [1, 2, 3]; |
|
28 assert.equal(bisect(array, 0.5), 0); |
|
29 assert.equal(bisect(array, 1.5), 1); |
|
30 assert.equal(bisect(array, 2.5), 2); |
|
31 assert.equal(bisect(array, 3.5), 3); |
|
32 }, |
|
33 "observes the optional lower bound": function(bisect) { |
|
34 var array = [1, 2, 3, 4, 5]; |
|
35 assert.equal(bisect(array, 0, 2), 2); |
|
36 assert.equal(bisect(array, 1, 2), 2); |
|
37 assert.equal(bisect(array, 2, 2), 2); |
|
38 assert.equal(bisect(array, 3, 2), 2); |
|
39 assert.equal(bisect(array, 4, 2), 3); |
|
40 assert.equal(bisect(array, 5, 2), 4); |
|
41 assert.equal(bisect(array, 6, 2), 5); |
|
42 }, |
|
43 "observes the optional bounds": function(bisect) { |
|
44 var array = [1, 2, 3, 4, 5]; |
|
45 assert.equal(bisect(array, 0, 2, 3), 2); |
|
46 assert.equal(bisect(array, 1, 2, 3), 2); |
|
47 assert.equal(bisect(array, 2, 2, 3), 2); |
|
48 assert.equal(bisect(array, 3, 2, 3), 2); |
|
49 assert.equal(bisect(array, 4, 2, 3), 3); |
|
50 assert.equal(bisect(array, 5, 2, 3), 3); |
|
51 assert.equal(bisect(array, 6, 2, 3), 3); |
|
52 } |
|
53 } |
|
54 }); |
|
55 |
|
56 suite.addBatch({ |
|
57 "bisectRight": { |
|
58 topic: function() { |
|
59 return d3.bisectRight; |
|
60 }, |
|
61 "finds the index after an exact match": function(bisect) { |
|
62 var array = [1, 2, 3]; |
|
63 assert.equal(bisect(array, 1), 1); |
|
64 assert.equal(bisect(array, 2), 2); |
|
65 assert.equal(bisect(array, 3), 3); |
|
66 }, |
|
67 "finds the index after the last match": function(bisect) { |
|
68 var array = [1, 2, 2, 3]; |
|
69 assert.equal(bisect(array, 1), 1); |
|
70 assert.equal(bisect(array, 2), 3); |
|
71 assert.equal(bisect(array, 3), 4); |
|
72 }, |
|
73 "finds the insertion point of a non-exact match": function(bisect) { |
|
74 var array = [1, 2, 3]; |
|
75 assert.equal(bisect(array, 0.5), 0); |
|
76 assert.equal(bisect(array, 1.5), 1); |
|
77 assert.equal(bisect(array, 2.5), 2); |
|
78 assert.equal(bisect(array, 3.5), 3); |
|
79 }, |
|
80 "observes the optional lower bound": function(bisect) { |
|
81 var array = [1, 2, 3, 4, 5]; |
|
82 assert.equal(bisect(array, 0, 2), 2); |
|
83 assert.equal(bisect(array, 1, 2), 2); |
|
84 assert.equal(bisect(array, 2, 2), 2); |
|
85 assert.equal(bisect(array, 3, 2), 3); |
|
86 assert.equal(bisect(array, 4, 2), 4); |
|
87 assert.equal(bisect(array, 5, 2), 5); |
|
88 assert.equal(bisect(array, 6, 2), 5); |
|
89 }, |
|
90 "observes the optional bounds": function(bisect) { |
|
91 var array = [1, 2, 3, 4, 5]; |
|
92 assert.equal(bisect(array, 0, 2, 3), 2); |
|
93 assert.equal(bisect(array, 1, 2, 3), 2); |
|
94 assert.equal(bisect(array, 2, 2, 3), 2); |
|
95 assert.equal(bisect(array, 3, 2, 3), 3); |
|
96 assert.equal(bisect(array, 4, 2, 3), 3); |
|
97 assert.equal(bisect(array, 5, 2, 3), 3); |
|
98 assert.equal(bisect(array, 6, 2, 3), 3); |
|
99 } |
|
100 } |
|
101 }); |
|
102 |
|
103 suite.export(module); |