Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('#fmapMemoize1', function () {
jsc.property('returns from cache on same input', 'json', function (a) {
var fn = _.fmapMemoize1(() => ({})),
r1 = fn(a),
r2 = fn(a);
return r1 === r2;
});
jsc.property('returns new value on different input', jsc.tuple([jsc.json, jsc.json]), function (a, b) {
var fn = _.fmapMemoize1(() => ({})),
r1 = fn(a),
r2 = fn(b);
return r1 !== r2;
});
// XXX create two objects slightly different & test that cache is used?
// create pairs of key/value, then select from set of pairs.
});
describe('#mmap', function () {
describe('#linear', function () {
jsc.property('returns values in range', extent, extent, 'number', function ([dstart, dend], [rstart, rend], input) {
if (rend === rstart || dend === dstart) {
return true; // report these positive until getting suchthat working.
}
var s = scale.linear([dstart, dend], [rstart, rend]),
output = s(input);
// Using assert so we can report the failure condition.
assert((rend > rstart && rstart <= output && rend >= output) ||
(rstart > rend && rstart >= output && rend <= output),
`Output ${output} not in range [${rstart} ${rend}] with domain [${dstart}, ${dend}] and input ${input}`); //eslint-disable-line comma-spacing
return true;
});
jsc.property('is monotonic', extent, extent, extent, function ([dstart, dend], [rstart, rend], [pt0, pt1]) {
if (rend === rstart || dend === dstart) {
return true; // report these positive until getting suchthat working.
}
var sign = (rend > rstart ? 1 : -1) * (dend > dstart ? 1 : -1) *
describe('#linear', function () {
jsc.property('returns values in range', extent, extent, 'number', function ([dstart, dend], [rstart, rend], input) {
if (rend === rstart || dend === dstart) {
return true; // report these positive until getting suchthat working.
}
var s = scale.linear([dstart, dend], [rstart, rend]),
output = s(input);
// Using assert so we can report the failure condition.
assert((rend > rstart && rstart <= output && rend >= output) ||
(rstart > rend && rstart >= output && rend <= output),
`Output ${output} not in range [${rstart} ${rend}] with domain [${dstart}, ${dend}] and input ${input}`); //eslint-disable-line comma-spacing
return true;
});
jsc.property('is monotonic', extent, extent, extent, function ([dstart, dend], [rstart, rend], [pt0, pt1]) {
if (rend === rstart || dend === dstart) {
return true; // report these positive until getting suchthat working.
}
var sign = (rend > rstart ? 1 : -1) * (dend > dstart ? 1 : -1) *
(pt1 > pt0 ? 1 : -1),
s = scale.linear([dstart, dend], [rstart, rend]),
out0 = s(pt0),
out1 = s(pt1);
// Using assert so we can report the failure condition.
assert((sign === 1 && out1 >= out0) ||
(sign === -1 && out0 >= out1),
`Output moves in wrong direction`); //eslint-disable-line comma-spacing
return true;
});
});
describe('#linearTicks', function () {
})
property('concat', 'string', 'string', function(a, b) {
return _.concat(b)(a) === (a.concat(b))
});
property('chain', 'json -> monad json', 'monad json', env, function(mf, ma) {
return _.chain(mf)(ma).equals(ma.chain(mf))
});
it('empty', function() {
var mock = { empty(){ return 1} }
assert(_.empty(mock) === mock.empty());
});
property('map', 'json -> json', 'functor json', env, function(f, ma) {
return _.map(f)(ma).equals(ma.map(f))
});
property('of', 'json', 'functor json', env, function(a, ma) {
return _.of(ma)(a).equals(ma.of(a))
});
property('equals', 'functor json', 'functor json', env, function(a, b) {
return _.equals(b)(a) === a.equals(b)
});
property('bimap', 'bifunctor json', 'json -> json', 'json -> json', env, function(a, f, g) {
return _.bimap(f, g)(a).equals(a.bimap(f, g))
});
});
describe('#map(f)', () => {
property('Just(a).map(f) = Just(f(a))', 'nat', 'nat -> nat', (a, f) => {
return Just(a).map(f).equals(Just(f(a)));
});
it('Nothing().map(f) = Nothing()', () => {
let called = false;
const f = () => { called = true };
Nothing().map(f);
$ASSERT(called === false);
});
});
describe('Functor', function () {
property('map', 'json', 'json -> json', function(a, f) {
return _.of(f(a)).equals(_.of(a).map(f))
});
property('Failure#map', 'json', 'json -> json', function(a, f) {
return _.Failure(a).map(f).equals(_.Failure(a))
});
});
describe('chain(validation, fn)', () => {
const lift = (f) => a => _.of(f(a));
property('chain', 'json', 'json -> json', (a, f) => {
return _.chain(_.Success(a), lift(f)).equals(lift(f)(a));
});
property('chain Failure', 'json', 'json -> json', (a, f) => {
return _.chain(_.Failure(a), lift(f)).equals(_.Failure(a));
});
});
describe('constructors', function () {
property('try#Left', 'json', function(a) {
return _.try((a) => {throw a })(a).equals(_.Left(a))
});
property('try#Right', 'json', function(a) {
return _.try(() => (a))(a).equals(_.Right(a))
});
});
describe('Conversions', () => {
property('Just#fromResult', 'json', (a) => {
return Maybe.fromResult(Just(a).toResult()).equals(Just(a));
});
property('Nothing#fromResult', 'json', (a) => {
return Maybe.fromResult(Nothing().toResult()).equals(Nothing());
});
});
var mock = { empty(){ return 1} }
assert(_.empty(mock) === mock.empty());
});
property('map', 'json -> json', 'functor json', env, function(f, ma) {
return _.map(f)(ma).equals(ma.map(f))
});
property('of', 'json', 'functor json', env, function(a, ma) {
return _.of(ma)(a).equals(ma.of(a))
});
property('equals', 'functor json', 'functor json', env, function(a, b) {
return _.equals(b)(a) === a.equals(b)
});
property('bimap', 'bifunctor json', 'json -> json', 'json -> json', env, function(a, f, g) {
return _.bimap(f, g)(a).equals(a.bimap(f, g))
});
});