Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3585fc5
commit 36e42f3
Showing
8 changed files
with
135 additions
and
165 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
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
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
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 |
---|---|---|
@@ -1,30 +1,33 @@ | ||
'use strict'; | ||
|
||
var teep = require('../teep.js'); | ||
var validation = teep.validation; | ||
var valid = teep.validation.valid; | ||
var invalid = teep.validation.invalid; | ||
var jsc = require('jsverify'); | ||
|
||
function inc(x) { return 1 + x; } | ||
|
||
exports['validation'] = { | ||
'map': function(test) { | ||
test.expect(2); | ||
test.equal(validation.valid(41).map(inc).toString(), 'valid(42)', 'should be 42.'); | ||
test.equal(validation.invalid(['wat']).map(inc).toString(), 'invalid(wat)', 'should be invalid(wat).'); | ||
exports.validation = { | ||
'map()': function (test) { | ||
jsc.assert(jsc.forall('number -> number', 'number', function (f, x) { | ||
return valid(x).map(f).toString() === valid(f(x)).toString() && | ||
invalid(['wat']).map(f).toString() === 'invalid(wat)'; | ||
})); | ||
test.done(); | ||
}, | ||
'flatMap': function(test) { | ||
function incLift(x) { return validation.valid(1 + x); } | ||
test.expect(2); | ||
test.equal(validation.valid(41).flatMap(incLift).toString(), 'valid(42)', 'should be 42.'); | ||
test.equal(validation.invalid(['wat']).flatMap(incLift).toString(), 'invalid(wat)', 'should be invalid(wat).'); | ||
'flatMap()': function (test) { | ||
function liftM0(f) { return function (x) { return valid(f(x)); }; } | ||
jsc.assert(jsc.forall('number -> number', 'number', function (f, x) { | ||
return valid(x).flatMap(liftM0(f)).toString() === liftM0(f)(x).toString() && | ||
invalid(['wat']).flatMap(liftM0(f)).toString() === 'invalid(wat)'; | ||
})); | ||
test.done(); | ||
}, | ||
'ap': function(test) { | ||
test.expect(4); | ||
test.equal(validation.valid(inc).ap(validation.valid(41)).toString(), 'valid(42)', 'should be 42.'); | ||
test.equal(validation.valid(inc).ap(validation.invalid(['wat'])).toString(), 'invalid(wat)', 'should be invalid(wat).'); | ||
test.equal(validation.invalid(['wat']).ap(validation.valid(41)).toString(), 'invalid(wat)', 'should be invalid(wat).'); | ||
test.equal(validation.invalid(['wat']).ap(validation.invalid(['nope'])).toString(), 'invalid(wat,nope)', 'should be invalid(wat).'); | ||
'ap()': function (test) { | ||
jsc.assert(jsc.forall('number -> number', 'number', function (f, x) { | ||
return valid(f).ap(valid(x)).toString() === valid(f(x)).toString() && | ||
valid(f).ap(invalid(['wat'])).toString() === 'invalid(wat)' && | ||
invalid(['wat']).ap(valid(x)).toString() === 'invalid(wat)' && | ||
invalid(['wat']).ap(invalid(['nope'])).toString() === 'invalid(wat,nope)'; | ||
})); | ||
test.done(); | ||
}, | ||
}; |