Files: 9e8b7714e605551f6eb22a0160194142cb7c3e47 / test / filter.js
1268 bytesRaw
1 | |
2 | var test = require('tape') |
3 | var pull = require('../') |
4 | |
5 | test('filtered randomnes', function (t) { |
6 | pull( |
7 | pull.infinite(), |
8 | pull.filter(function (d) { |
9 | console.log('f', d) |
10 | return d > 0.5 |
11 | }), |
12 | pull.take(100), |
13 | pull.collect(function (err, array) { |
14 | t.equal(array.length, 100) |
15 | array.forEach(function (d) { |
16 | t.ok(d > 0.5) |
17 | t.ok(d <= 1) |
18 | }) |
19 | console.log(array) |
20 | t.end() |
21 | }) |
22 | ) |
23 | }) |
24 | |
25 | test('filter with regexp', function (t) { |
26 | pull( |
27 | pull.infinite(), |
28 | pull.map(function (d) { |
29 | return Math.round(d * 1000).toString(16) |
30 | }), |
31 | pull.filter(/^[^e]+$/i), //no E |
32 | pull.take(37), |
33 | pull.collect(function (err, array) { |
34 | t.equal(array.length, 37) |
35 | console.log(array) |
36 | array.forEach(function (d) { |
37 | t.equal(d.indexOf('e'), -1) |
38 | }) |
39 | t.end() |
40 | }) |
41 | ) |
42 | }) |
43 | |
44 | test('inverse filter with regexp', function (t) { |
45 | pull( |
46 | pull.infinite(), |
47 | pull.map(function (d) { |
48 | return Math.round(d * 1000).toString(16) |
49 | }), |
50 | pull.filterNot(/^[^e]+$/i), //no E |
51 | pull.take(37), |
52 | pull.collect(function (err, array) { |
53 | t.equal(array.length, 37) |
54 | array.forEach(function (d) { |
55 | t.notEqual(d.indexOf('e'), -1) |
56 | }) |
57 | t.end() |
58 | }) |
59 | ) |
60 | }) |
61 | |
62 |
Built with git-ssb-web