This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
tests.js
130 lines (103 loc) · 4.83 KB
/
tests.js
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
var chord = require('./chord');
var vows = require('vows');
var assert = require('assert');
vows.describe('Chord').addBatch({
'Adding an exponential key': {
'should add two small values': function () {
assert.isTrue(chord.equal_to(chord.add_exp([0,0,0,1], 0), [0,0,0,2]));
},
'should add a value smaller than 32 bits': function () {
assert.isTrue(chord.equal_to(chord.add_exp([0,0,0,0], 12), [0,0,0,4096]));
},
'should add a value larger than 32 bits': function () {
assert.isTrue(chord.equal_to(chord.add_exp([0,0,0,0], 44), [0,0,4096,0]));
},
'should carry additions across words': function () {
assert.isTrue(chord.equal_to(chord.add_exp([2, 0xffffffff], 0), [3, 0]));
},
'should carry and wrap': function () {
assert.isTrue(chord.equal_to(chord.add_exp([0xffffffff, 0xffffffff, 0xffffffff], 0), [0,0,0]))
}
},
'Comparing keys': {
'should find equal things equal': function () {
assert.isTrue(chord.equal_to([1,2,3,4], [1,2,3,4]));
},
'equality should find differences in least significant word': function () {
assert.isFalse(chord.equal_to([1,2,3,4], [1,2,3,5]));
},
'equality should find differences in most significant word': function () {
assert.isFalse(chord.equal_to([1,2,3,4], [5,2,3,4]));
},
'should compare equal things as less than or equal': function () {
assert.isTrue(chord.less_than_or_equal([1,2,3,4], [1,2,3,4]));
},
'should compare lesser things as less than or equal': function () {
assert.isTrue(chord.less_than_or_equal([1,2,3,3], [1,2,3,4]));
},
'should not compare greater things as less than or equal': function () {
assert.isFalse(chord.less_than_or_equal([1,2,3,5], [1,2,3,4]));
},
'should not compare equal things as less than': function () {
assert.isFalse(chord.less_than([1,2,3,4], [1,2,3,4]));
},
'should compare lesser things as less than': function () {
assert.isTrue(chord.less_than([1,2,3,3], [1,2,3,4]));
},
'should not compare greater things as less than': function () {
assert.isFalse(chord.less_than([1,2,3,5], [1,2,3,4]));
},
'most significant word should take precedence over least for less than': function () {
assert.isTrue(chord.less_than([1,2,3,4], [2,2,3,3]));
},
'specific case that broke for real': function () {
assert.isTrue(chord.less_than([1195588147,3697448847,138059749,162608140],
[1456031017,292686529,2153452302,2944297828]));
assert.isFalse(chord.less_than([1456031017,292686529,2153452302,2944297828],
[1195588147,3697448847,138059749,162608140]));
}
},
'Testing key ranges': {
'key is in range': function () {
assert.isTrue(chord.in_range([2], [1], [3]));
assert.isTrue(chord.in_half_open_range([2], [1], [3]));
},
'key is not in range': function () {
assert.isFalse(chord.in_range([4], [1], [3]));
assert.isFalse(chord.in_half_open_range([4], [1], [3]));
},
'key is in reversed range': function () {
assert.isTrue(chord.in_range([4], [3], [1]));
assert.isTrue(chord.in_half_open_range([4], [3], [1]));
},
'key is not in reversed range': function () {
assert.isFalse(chord.in_range([2], [3], [1]));
assert.isFalse(chord.in_half_open_range([2], [3], [1]));
},
'key is not in empty range': function () {
assert.isFalse(chord.in_range([1], [1], [1]));
},
'key is in empty range': function () {
assert.isTrue(chord.in_range([2], [1], [1]));
},
'key is in half open empty range': function () {
assert.isTrue(chord.in_half_open_range([1], [1], [1]));
assert.isTrue(chord.in_half_open_range([2], [1], [1]));
},
'key on lower boundary is not in range': function () {
assert.isFalse(chord.in_range([1], [1], [3]));
assert.isFalse(chord.in_half_open_range([1], [1], [3]));
},
'key on upper boundary is not in range': function () {
assert.isFalse(chord.in_range([3], [1], [3]));
},
'key on upper boundary is in half open range': function () {
assert.isTrue(chord.in_half_open_range([3], [1], [3]));
},
'specific case that broke for real': function () {
assert.isFalse(chord.in_range([1456031017,292686529,2153452302,2944297828],
[1195588147,3697448847,138059749,162608140],
[1456031017,292686529,2153452302,2944297828]));
}
}
}).export(module);