summaryrefslogtreecommitdiff
path: root/test/reduce.js
diff options
context:
space:
mode:
authorAlexander Early <alexander.early@gmail.com>2018-06-02 18:35:23 -0700
committerAlexander Early <alexander.early@gmail.com>2018-06-02 18:35:32 -0700
commitbd86f42a7d71552d9a502b50235ffc090a1b4a98 (patch)
treef5170115927ad4097f1a393d34b8a52f5c9bbfeb /test/reduce.js
parentb149f7dcc7daba4d7bac5a313bdf6d1a85210cb1 (diff)
downloadasync-bd86f42a7d71552d9a502b50235ffc090a1b4a98.tar.gz
move mocha_tests/ to test/
Diffstat (limited to 'test/reduce.js')
-rw-r--r--test/reduce.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/reduce.js b/test/reduce.js
new file mode 100644
index 0000000..f5dce59
--- /dev/null
+++ b/test/reduce.js
@@ -0,0 +1,66 @@
+var async = require('../lib');
+var expect = require('chai').expect;
+var assert = require('assert');
+
+describe('reduce', function() {
+
+ it('reduce', function(done) {
+ var call_order = [];
+ async.reduce([1,2,3], 0, function(a, x, callback){
+ call_order.push(x);
+ callback(null, a + x);
+ }, function(err, result){
+ assert(err === null, err + " passed instead of 'null'");
+ expect(result).to.equal(6);
+ expect(call_order).to.eql([1,2,3]);
+ done();
+ });
+ });
+
+ it('reduce async with non-reference memo', function(done) {
+ async.reduce([1,3,2], 0, function(a, x, callback){
+ setTimeout(function(){callback(null, a + x);}, Math.random()*100);
+ }, function(err, result){
+ expect(result).to.equal(6);
+ done();
+ });
+ });
+
+ it('reduce error', function(done) {
+ async.reduce([1,2,3], 0, function(a, x, callback){
+ callback('error');
+ }, function(err){
+ expect(err).to.equal('error');
+ });
+ setTimeout(done, 50);
+ });
+
+ it('inject alias', function(done) {
+ expect(async.inject).to.equal(async.reduce);
+ done();
+ });
+
+ it('foldl alias', function(done) {
+ expect(async.foldl).to.equal(async.reduce);
+ done();
+ });
+
+ it('reduceRight', function(done) {
+ var call_order = [];
+ var a = [1,2,3];
+ async.reduceRight(a, 0, function(a, x, callback){
+ call_order.push(x);
+ callback(null, a + x);
+ }, function(err, result){
+ expect(result).to.equal(6);
+ expect(call_order).to.eql([3,2,1]);
+ expect(a).to.eql([1,2,3]);
+ done();
+ });
+ });
+
+ it('foldr alias', function(done) {
+ expect(async.foldr).to.equal(async.reduceRight);
+ done();
+ });
+});