Skip to content

Instantly share code, notes, and snippets.

@andrew--r
Last active July 11, 2017 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrew--r/2cb3c6f66d02e74936b6240c922606ed to your computer and use it in GitHub Desktop.
Save andrew--r/2cb3c6f66d02e74936b6240c922606ed to your computer and use it in GitHub Desktop.
function assert(description, condition) {
return `${condition ? '✓' : '×'} ${description}`;
}
function If(bool) {
return (a) => (b) => bool(a, b);
}
function True(a, b) {
return a;
}
function False(a, b) {
return b;
}
console.log('\nstart testing If...');
console.log(assert('should return 1 when true', If(True)(1)(2) === 1));
console.log(assert('should return 2 when false', If(False)(1)(2) === 2));
console.log('end testing If\n');
function And(a) {
return (b) => If(a)(If(b)(True)(False))(False);
}
console.log('\nstart testing And...');
console.log(assert('1 && 1 === 1', And(True)(True) === True));
console.log(assert('1 && 0 === 0', And(True)(False) === False));
console.log(assert('0 && 1 === 0', And(False)(True) === False));
console.log(assert('0 && 0 === 0', And(False)(False) === False));
console.log('end testing And\n');
function Or(a) {
return (b) => If(a)(True)(If(b)(True)(False));
}
console.log('\nstart testing Or...');
console.log(assert('1 || 1 === 1', Or(True)(True) === True));
console.log(assert('1 || 0 === 1', Or(True)(False) === True));
console.log(assert('0 || 1 === 1', Or(False)(True) === True));
console.log(assert('0 || 0 === 0', Or(False)(False) === False));
console.log('end testing Or\n');
function Not(bool) {
return If(bool)(False)(True);
}
console.log('\nstart testing Not...');
console.log(assert('!True === False', Not(True) === False));
console.log(assert('!False === True', Not(False) === True));
console.log('end testing Not\n');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment