You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.2 KiB

var test = require('tape')
var pull = require('../')
test('filtered randomnes', function (t) {
pull(
pull.infinite(),
pull.filter(function (d) {
console.log('f', d)
return d > 0.5
}),
pull.take(100),
pull.collect(function (err, array) {
t.equal(array.length, 100)
array.forEach(function (d) {
t.ok(d > 0.5)
t.ok(d <= 1)
})
console.log(array)
t.end()
})
)
})
test('filter with regexp', function (t) {
pull(
pull.infinite(),
pull.map(function (d) {
return Math.round(d * 1000).toString(16)
}),
pull.filter(/^[^e]+$/i), //no E
pull.take(37),
pull.collect(function (err, array) {
t.equal(array.length, 37)
console.log(array)
array.forEach(function (d) {
t.equal(d.indexOf('e'), -1)
})
t.end()
})
)
})
test('inverse filter with regexp', function (t) {
pull(
pull.infinite(),
pull.map(function (d) {
return Math.round(d * 1000).toString(16)
}),
pull.filterNot(/^[^e]+$/i), //no E
pull.take(37),
pull.collect(function (err, array) {
t.equal(array.length, 37)
array.forEach(function (d) {
t.notEqual(d.indexOf('e'), -1)
})
t.end()
})
)
})