-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
169 lines (149 loc) · 5 KB
/
test.js
File metadata and controls
169 lines (149 loc) · 5 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
!function(root, name) {
var common = typeof module != 'undefined' && !!module.exports
var cueing = common ? require('./') : root[name]
function ok(desc, test) {
if (typeof test == 'function') test = test()
if (!test) throw new Error(desc)
}
ok('instanceof', cueing() instanceof cueing)
ok('inherits array', cueing() instanceof Array && 0 === cueing([0]).pop())
ok('default instance properties', function() {
var o = cueing()
if (0 !== o.length) return false
if (0 !== o._needle) return false
if (o._needle != o.needle()) return false
if (0 !== o.recall().length) return false
return o.recall() instanceof cueing
})
ok('instance properties from range', function() {
var o = cueing(3)
if (3 !== o.length) return false
if (0 !== +o.needle()) return false
if (0 !== o.recall().length) return false
return true
})
ok('instance properties from array', function() {
var o = cueing(['a', 'b'])
if (2 !== o.length) return false
if (0 !== +o.needle()) return false
if (0 !== o.recall().length) return false
return true
})
ok('instance coerces to needle', function() {
var o = cueing(['a'])
if (o._needle != o) return false
if (0 !== +o) return false
if ('0' !== String(o)) return false
if (o !== [o][o]) return false
if (0 !== o._needle) return false
if (o !== o.needle() || o !== o.needle(0)) return false
return isFinite(o)
})
ok('#cue', function() {
var letters = ['a', 'b', 'c']
if (2 !== +cueing.cue(letters, -1)) return false
if (0 !== +cueing.cue(letters, 0)) return false
if (1 !== +cueing.cue(letters, 1)) return false
return true
})
ok('#cue offset', function() {
var letters = ['a', 'b', 'c']
if (2 !== +cueing.cue(letters, 1, 1)) return false
if (0 !== +cueing.cue(letters, -1, 1)) return false
if (0 !== +cueing.cue(letters, 2, 1)) return false
if (1 !== +cueing.cue(letters, 0, 4)) return false
return true
})
ok('#seek', function() {
var letters = ['a', 'b', 'c']
if ('c' !== cueing.seek(letters, -1)) return false
if ('c' !== cueing.seek(letters, -2, 1)) return false
if ('a' !== cueing.seek(letters, 0)) return false
if ('b' !== cueing.seek(letters, 1)) return false
return true
})
ok('#seek offset', function() {
var letters = ['a', 'b', 'c']
if ('c' !== cueing.seek(letters, 1, 1)) return false
if ('a' !== cueing.seek(letters, 2, 1)) return false
if ('b' !== cueing.seek(letters, 0, 4)) return false
return true
})
ok('#store fresh', function() {
var history = []
cueing.store(history, 8)
cueing.store(history, 7)
return history.join('') === '87'
})
ok('#store existing', function() {
var history = [1, 5]
cueing.store(history, 5)
cueing.store(history, 3)
cueing.store(history, 1)
return history.join('') === '1531'
})
ok('.cue', function() {
var o = cueing(10)
if (0 !== +o) return false
if (1 !== +o.cue(1)) return false
if (0 !== +o.cue(-1)) return false
if (9 !== +o.cue(-1)) return false
if (9 !== +o.cue(-30)) return false
if (9 !== +o) return false
return true
})
ok('.seek', function() {
var o = cueing(['a', 'b', 'c', 'd', 'e'])
if (0 !== +o.needle()) return false
if ('b' !== o.seek(1)) return false
if ('a' !== o.seek(-1)) return false
if ('e' !== o.seek(-1)) return false
if ('e' !== o.seek(-5)) return false
if ('e' !== o.seek(-15)) return false
if ('e' !== o.seek(50)) return false
if ('a' !== o.seek(51)) return false
return true
})
ok('.needle', function() {
var o = cueing(10)
if (1 !== +o.cue(1) || 1 != o.needle()) return false
if (2 !== +o.cue(1) || 2 != o.needle()) return false
if (9 !== +o.cue(-3) || 9 != o.needle()) return false
if (1 !== +o.needle(1) || 1 != o.needle()) return false
if (5 !== +o.needle(5) || 5 != o.needle()) return false
return true
})
ok('.clone', function() {
var o = cueing(['a', 'b']), clone = o.clone()
if (o === clone) return false
if (o._needle !== clone._needle) return false
if (o._recall === clone._recall) return false
if (o.join() !== clone.join()) return false
return o.recall().length === clone.recall().length
})
ok('.store', function() {
var o = cueing().needle(1)
if (o !== o.store()) return false
if (1 !== cueing.seek(o._recall, -1)) return false
var stored = o._recall.length
return 2 > o.store().store()._recall.length - stored
})
ok('.recall', function() {
var o = cueing(10).store().cue(1).store().cue(1).store()
if (+o.needle() !== +o.recall(-1)) return false
if (o._recall.join() !== o.recall().join()) return false
if (5 !== o.needle(5).store()._recall.pop()) return false
return o.recall(0) instanceof cueing
})
ok('.clear', function() {
var o = cueing(10)
o.cue(1)
o.cue(1)
o.clear()
return !o.recall().length
})
try {
console.info('Tests passed =)')
window.console.dir(cueing)
} catch (e) {}
}(this, 'cueing');