-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
executable file
·79 lines (60 loc) · 2.05 KB
/
test.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
var alloc = require('buffer-alloc')
var tape = require('tape')
var thinbit = require('./')
tape('ThinBit Tests: set and get', function (t) {
var tbits = thinbit()
t.same(tbits.get(0), false, 'first bit is false')
tbits.set(0, true)
t.same(tbits.get(0), true, 'first bit is true')
t.same(tbits.get(1), false, 'second bit is false')
tbits.set(0, false)
t.same(tbits.get(0), false, 'first bit is reset')
t.end()
})
tape('ThinBit Tests: set large and get', function (t) {
var tbits = thinbit()
t.same(tbits.get(9999999999999), false, 'large bit is false')
tbits.set(9999999999999, true)
t.same(tbits.get(9999999999999), true, 'large bit is true')
t.same(tbits.get(9999999999999 + 1), false, 'large bit + 1 is false')
tbits.set(9999999999999, false)
t.same(tbits.get(9999999999999), false, 'large bit is reset')
t.end()
})
tape('ThinBit Tests: get and set buffer', function (t) {
var tbits = thinbit({trackUpdates: true})
t.same(tbits.pages.get(0, true), undefined)
t.same(tbits.pages.get(Math.floor(9999999999999 / 8 / 1024), true), undefined)
tbits.set(9999999999999, true)
var tbits2 = thinbit()
var upd = tbits.pages.lastUpdate()
tbits2.pages.set(Math.floor(upd.offset / 1024), upd.buffer)
t.same(tbits2.get(9999999999999), true, 'bit is set')
t.end()
})
tape('ThinBit Tests: toBuffer', function (t) {
var tbits = thinbit()
t.same(tbits.toBuffer(), alloc(0))
tbits.set(0, true)
t.same(tbits.toBuffer(), tbits.pages.get(0).buffer)
tbits.set(9000, true)
t.same(tbits.toBuffer(), Buffer.concat([tbits.pages.get(0).buffer, tbits.pages.get(1).buffer]))
t.end()
})
tape('ThinBit Tests: pass in buffer', function (t) {
var tbits = thinbit()
tbits.set(0, true)
tbits.set(9000, true)
var clone = thinbit(tbits.toBuffer())
t.same(clone.get(0), true)
t.same(clone.get(9000), true)
t.end()
})
tape('ThinBit Tests: set small buffer', function (t) {
var buf = alloc(1)
buf[0] = 255
var tbits = thinbit(buf)
t.same(tbits.get(0), true)
t.same(tbits.pages.get(0).buffer.length, tbits.pageSize)
t.end()
})