-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start tracking th examples in the `README.md` in a proof test.
- Loading branch information
1 parent
92772d5
commit b20b03b
Showing
2 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require('proof')(2, require('../..')(prove)) | ||
|
||
function prove (async, assert) { | ||
var cadence = require('../..') | ||
|
||
function echo (value, callback) { | ||
setImmediate(callback, null, value) | ||
} | ||
|
||
var deepEqual = assert.deepEqual | ||
|
||
async(function () { | ||
var next = async() | ||
|
||
var multiply = cadence(function (async, matrix) { | ||
async(function () { | ||
var i = 0, j = 0 | ||
async(function () { | ||
if (i == matrix.length) return [ async.break ] | ||
async(function () { | ||
if (j == matrix[i].length) return [ async.break ] | ||
echo(matrix[i][j] * 5, async()) | ||
}, function (value) { | ||
matrix[i][j] = value | ||
j++ | ||
})() | ||
}, function () { | ||
j = 0 | ||
i++ | ||
})() | ||
}, function () { | ||
return [ matrix ] | ||
}) | ||
}) | ||
|
||
multiply([[ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]], function (error, matrix) { | ||
if (error) throw error | ||
deepEqual(matrix, [[ 5, 10, 15 ], [ 20, 25, 30 ], [ 35, 40, 45 ]]) | ||
next() | ||
}) | ||
}, function () { | ||
var next = async() | ||
|
||
var multiply = cadence(function (async, matrix) { | ||
async.map(function (array) { | ||
async.map(function (value) { | ||
echo(value * 5, async()) | ||
})(array) | ||
})(matrix) | ||
}) | ||
|
||
multiply([[ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]], function (error, matrix) { | ||
if (error) throw error | ||
deepEqual(matrix, [[ 5, 10, 15 ], [ 20, 25, 30 ], [ 35, 40, 45 ]]) | ||
next() | ||
}) | ||
}) | ||
} |