-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbisect-test.js
More file actions
103 lines (98 loc) · 3.41 KB
/
Copy pathbisect-test.js
File metadata and controls
103 lines (98 loc) · 3.41 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require("../env");
require("../../d3");
var vows = require("vows"),
assert = require("assert");
var suite = vows.describe("d3.bisect");
suite.addBatch({
"bisectLeft": {
topic: function() {
return d3.bisectLeft;
},
"finds the index of an exact match": function(bisect) {
var array = [1, 2, 3];
assert.equal(bisect(array, 1), 0);
assert.equal(bisect(array, 2), 1);
assert.equal(bisect(array, 3), 2);
},
"finds the index of the first match": function(bisect) {
var array = [1, 2, 2, 3];
assert.equal(bisect(array, 1), 0);
assert.equal(bisect(array, 2), 1);
assert.equal(bisect(array, 3), 3);
},
"finds the insertion point of a non-exact match": function(bisect) {
var array = [1, 2, 3];
assert.equal(bisect(array, 0.5), 0);
assert.equal(bisect(array, 1.5), 1);
assert.equal(bisect(array, 2.5), 2);
assert.equal(bisect(array, 3.5), 3);
},
"observes the optional lower bound": function(bisect) {
var array = [1, 2, 3, 4, 5];
assert.equal(bisect(array, 0, 2), 2);
assert.equal(bisect(array, 1, 2), 2);
assert.equal(bisect(array, 2, 2), 2);
assert.equal(bisect(array, 3, 2), 2);
assert.equal(bisect(array, 4, 2), 3);
assert.equal(bisect(array, 5, 2), 4);
assert.equal(bisect(array, 6, 2), 5);
},
"observes the optional bounds": function(bisect) {
var array = [1, 2, 3, 4, 5];
assert.equal(bisect(array, 0, 2, 3), 2);
assert.equal(bisect(array, 1, 2, 3), 2);
assert.equal(bisect(array, 2, 2, 3), 2);
assert.equal(bisect(array, 3, 2, 3), 2);
assert.equal(bisect(array, 4, 2, 3), 3);
assert.equal(bisect(array, 5, 2, 3), 3);
assert.equal(bisect(array, 6, 2, 3), 3);
}
}
});
suite.addBatch({
"bisectRight": {
topic: function() {
return d3.bisectRight;
},
"finds the index after an exact match": function(bisect) {
var array = [1, 2, 3];
assert.equal(bisect(array, 1), 1);
assert.equal(bisect(array, 2), 2);
assert.equal(bisect(array, 3), 3);
},
"finds the index after the last match": function(bisect) {
var array = [1, 2, 2, 3];
assert.equal(bisect(array, 1), 1);
assert.equal(bisect(array, 2), 3);
assert.equal(bisect(array, 3), 4);
},
"finds the insertion point of a non-exact match": function(bisect) {
var array = [1, 2, 3];
assert.equal(bisect(array, 0.5), 0);
assert.equal(bisect(array, 1.5), 1);
assert.equal(bisect(array, 2.5), 2);
assert.equal(bisect(array, 3.5), 3);
},
"observes the optional lower bound": function(bisect) {
var array = [1, 2, 3, 4, 5];
assert.equal(bisect(array, 0, 2), 2);
assert.equal(bisect(array, 1, 2), 2);
assert.equal(bisect(array, 2, 2), 2);
assert.equal(bisect(array, 3, 2), 3);
assert.equal(bisect(array, 4, 2), 4);
assert.equal(bisect(array, 5, 2), 5);
assert.equal(bisect(array, 6, 2), 5);
},
"observes the optional bounds": function(bisect) {
var array = [1, 2, 3, 4, 5];
assert.equal(bisect(array, 0, 2, 3), 2);
assert.equal(bisect(array, 1, 2, 3), 2);
assert.equal(bisect(array, 2, 2, 3), 2);
assert.equal(bisect(array, 3, 2, 3), 3);
assert.equal(bisect(array, 4, 2, 3), 3);
assert.equal(bisect(array, 5, 2, 3), 3);
assert.equal(bisect(array, 6, 2, 3), 3);
}
}
});
suite.export(module);