git ssb

2+

Dominic / pull-stream



Commit 4d8da84532dda783798716e49c5335f3daaffdf1

test for filter

Dominic Tarr committed on 3/22/2013, 11:12:38 PM
Parent: db028394b8ca29adb83cfb734c52c0e335f0cab5

Files changed

test/filter.jsadded
test/filter.jsView
@@ -1,0 +1,39 @@
1+
2+var test = require('tape')
3+var pull = require('../')
4+
5+test('filtered randomnes', function (t) {
6+ pull.infinite()
7+ .pipe(pull.filter(function (d) {
8+ console.log('f', d)
9+ return d > 0.5
10+ }))
11+ .pipe(pull.take(100))
12+ .pipe(pull.writeArray(function (err, array) {
13+ t.equal(array.length, 100)
14+ array.forEach(function (d) {
15+ t.ok(d > 0.5)
16+ t.ok(d <= 1)
17+ })
18+ console.log(array)
19+ t.end()
20+
21+ }))
22+})
23+
24+test('filter with regexp', function (t) {
25+ pull.infinite()
26+ .pipe(pull.map(function (d) {
27+ return Math.round(d * 1000).toString(16)
28+ }))
29+ .pipe(pull.filter(/^[^e]+$/i)) //no E
30+ .pipe(pull.take(37))
31+ .pipe(pull.writeArray(function (err, array) {
32+ t.equal(array.length, 37)
33+ console.log(array)
34+ array.forEach(function (d) {
35+ t.equal(d.indexOf('e'), -1)
36+ })
37+ t.end()
38+ }))
39+})

Built with git-ssb-web