-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
120 lines (98 loc) · 2.84 KB
/
index.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
var test = require("tape").test
var concat = require("concat-stream")
var gen = require("../gen").gen
var one = require("../gen").one
var rand = require("../gen").rand
test("init", function (t) {
t.equals(typeof gen, "function", "gen is a function")
t.equals(typeof one, "function", "one is a function")
t.equals(typeof rand, "function", "rand is a function")
t.end()
})
test("one", function (t) {
t.plan(1)
function collect(records) {
t.deepEquals(records, [{_t: 100, foo: "bar", zzz: 1101}], "Expected record streamed")
}
one(100, {foo: "bar", zzz: 1101})
.pipe(concat(collect))
})
test("one errors", function (t) {
t.throws(function () {one()}, "No args throws")
t.throws(function () {one({foo: "bar"})}, "No timestamp throws")
t.end()
})
test("gen", function (t) {
t.plan(1)
function collect(records) {
var expected = [
{_t: 500, gen: 0},
{_t: 1000, gen: 1},
{_t: 1500, gen: 2},
{_t: 2000, gen: 3}
]
t.deepEquals(records, expected, "Expected records streamed")
}
gen({start: 500, until: 2000, interval: 500})
.pipe(concat(collect))
})
test("gen options", function (t) {
t.plan(1)
function collect(records) {
var expected = [
{_t: 500, foo: 203},
{_t: 1000, foo: 206},
{_t: 1500, foo: 209},
{_t: 2000, foo: 212}
]
t.deepEquals(records, expected, "Expected records streamed")
}
gen({start: 500, until: 2000, interval: 500, key: "foo", initial: 203, increment: 3})
.pipe(concat(collect))
})
test("gen errors", function (t) {
t.throws(function () {gen()}, "No args throws")
t.throws(function () {gen({start: "bar", until: 10, interval: 1000})}, "Not enough/bad args")
t.end()
})
test("rand", function (t) {
t.plan(5)
function collect(records) {
records.map(function (r) {
t.ok(r.rand >= 0 && r.rand <= 1, "value is probably a Math.random value")
r.rand = 3
})
var expected = [
{_t: 500, rand: 3},
{_t: 1000, rand: 3},
{_t: 1500, rand: 3},
{_t: 2000, rand: 3}
]
t.deepEquals(records, expected, "Expected records streamed")
}
rand({start: 500, until: 2000, interval: 500})
.pipe(concat(collect))
})
test("rand options", function (t) {
t.plan(5)
function collect(records) {
records.map(function (r) {
t.ok(r.foo >= 0 && r.foo <= 1, "value is probably a Math.random value")
r.foo = 3
})
var expected = [
{_t: 500, foo: 3},
{_t: 1000, foo: 3},
{_t: 1500, foo: 3},
{_t: 2000, foo: 3}
]
t.deepEquals(records, expected, "Expected records streamed")
}
rand({start: 500, until: 2000, interval: 500, key: "foo"})
.pipe(concat(collect))
})
test("rand errors", function (t) {
t.throws(function () {rand()}, "No args throws")
t.throws(function () {rand({start: "bar", until: 10, interval: 1000})}, "Not enough/bad args")
t.end()
})