|
|
@@ -2,20 +2,27 @@
|
|
|
|
|
|
const unit = require('heya-unit');
|
|
|
|
|
|
-const Chain = require('../index');
|
|
|
const {streamToArray, delay} = require('./helpers');
|
|
|
+const Chain = require('../src/index');
|
|
|
|
|
|
-const {fromIterable} = require('../utils/FromIterable');
|
|
|
-const fold = require('../utils/fold');
|
|
|
-const scan = require('../utils/scan');
|
|
|
-const {reduce} = require('../utils/Reduce');
|
|
|
+const {fromIterable} = require('../src/utils/FromIterable');
|
|
|
+const fold = require('../src/utils/fold');
|
|
|
+const scan = require('../src/utils/scan');
|
|
|
+const reduce = require('../src/utils/reduce');
|
|
|
+const {reduceStream} = require('../src/utils/ReduceStream');
|
|
|
+
|
|
|
+const {asStream} = Chain;
|
|
|
|
|
|
unit.add(module, [
|
|
|
function test_fold(t) {
|
|
|
const async = t.startAsync('test_fold');
|
|
|
|
|
|
const output = [],
|
|
|
- chain = new Chain([fromIterable([1, 2, 3]), fold((acc, x) => acc + x, 0), streamToArray(output)]);
|
|
|
+ chain = new Chain([
|
|
|
+ fromIterable([1, 2, 3]),
|
|
|
+ fold((acc, x) => acc + x, 0),
|
|
|
+ streamToArray(output)
|
|
|
+ ]);
|
|
|
|
|
|
chain.on('end', () => {
|
|
|
eval(t.TEST('t.unify(output, [6])'));
|
|
|
@@ -26,7 +33,14 @@ unit.add(module, [
|
|
|
const async = t.startAsync('test_foldAsync');
|
|
|
|
|
|
const output = [],
|
|
|
- chain = new Chain([fromIterable([1, 2, 3]), fold(delay((acc, x) => acc + x), 0), streamToArray(output)]);
|
|
|
+ chain = new Chain([
|
|
|
+ fromIterable([1, 2, 3]),
|
|
|
+ fold(
|
|
|
+ delay((acc, x) => acc + x),
|
|
|
+ 0
|
|
|
+ ),
|
|
|
+ streamToArray(output)
|
|
|
+ ]);
|
|
|
|
|
|
chain.on('end', () => {
|
|
|
eval(t.TEST('t.unify(output, [6])'));
|
|
|
@@ -37,7 +51,11 @@ unit.add(module, [
|
|
|
const async = t.startAsync('test_foldScan');
|
|
|
|
|
|
const output = [],
|
|
|
- chain = new Chain([fromIterable([1, 2, 3]), scan((acc, x) => acc + x, 0), streamToArray(output)]);
|
|
|
+ chain = new Chain([
|
|
|
+ fromIterable([1, 2, 3]),
|
|
|
+ scan((acc, x) => acc + x, 0),
|
|
|
+ streamToArray(output)
|
|
|
+ ]);
|
|
|
|
|
|
chain.on('end', () => {
|
|
|
eval(t.TEST('t.unify(output, [1, 3, 6])'));
|
|
|
@@ -48,7 +66,14 @@ unit.add(module, [
|
|
|
const async = t.startAsync('test_foldScanAsync');
|
|
|
|
|
|
const output = [],
|
|
|
- chain = new Chain([fromIterable([1, 2, 3]), scan(delay((acc, x) => acc + x), 0), streamToArray(output)]);
|
|
|
+ chain = new Chain([
|
|
|
+ fromIterable([1, 2, 3]),
|
|
|
+ scan(
|
|
|
+ delay((acc, x) => acc + x),
|
|
|
+ 0
|
|
|
+ ),
|
|
|
+ streamToArray(output)
|
|
|
+ ]);
|
|
|
|
|
|
chain.on('end', () => {
|
|
|
eval(t.TEST('t.unify(output, [1, 3, 6])'));
|
|
|
@@ -58,7 +83,40 @@ unit.add(module, [
|
|
|
function test_foldReduce(t) {
|
|
|
const async = t.startAsync('test_foldReduce');
|
|
|
|
|
|
- const r = reduce((acc, x) => acc + x, 0);
|
|
|
+ const output = [],
|
|
|
+ chain = new Chain([
|
|
|
+ fromIterable([1, 2, 3]),
|
|
|
+ fold((acc, x) => acc + x, 0),
|
|
|
+ streamToArray(output)
|
|
|
+ ]);
|
|
|
+
|
|
|
+ chain.on('end', () => {
|
|
|
+ eval(t.TEST('t.unify(output, [6])'));
|
|
|
+ async.done();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ function test_foldReduceAsync(t) {
|
|
|
+ const async = t.startAsync('test_foldReduceAsync');
|
|
|
+
|
|
|
+ const output = [],
|
|
|
+ chain = new Chain([
|
|
|
+ fromIterable([1, 2, 3]),
|
|
|
+ reduce(
|
|
|
+ delay((acc, x) => acc + x),
|
|
|
+ 0
|
|
|
+ ),
|
|
|
+ streamToArray(output)
|
|
|
+ ]);
|
|
|
+
|
|
|
+ chain.on('end', () => {
|
|
|
+ eval(t.TEST('t.unify(output, [6])'));
|
|
|
+ async.done();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ function test_foldReduceStream(t) {
|
|
|
+ const async = t.startAsync('test_foldReduceStream');
|
|
|
+
|
|
|
+ const r = reduceStream((acc, x) => acc + x, 0);
|
|
|
|
|
|
fromIterable([1, 2, 3]).pipe(r);
|
|
|
|
|
|
@@ -67,10 +125,10 @@ unit.add(module, [
|
|
|
async.done();
|
|
|
});
|
|
|
},
|
|
|
- function test_foldReduceAsync(t) {
|
|
|
- const async = t.startAsync('test_foldReduceAsync');
|
|
|
+ function test_foldReduceStreamAsync(t) {
|
|
|
+ const async = t.startAsync('test_foldReduceStreamAsync');
|
|
|
|
|
|
- const r = reduce({reducer: delay((acc, x) => acc + x), initial: 0});
|
|
|
+ const r = reduceStream({reducer: delay((acc, x) => acc + x), initial: 0});
|
|
|
|
|
|
fromIterable([1, 2, 3]).pipe(r);
|
|
|
|