Last active
July 11, 2017 05:09
-
-
Save andrew--r/2cb3c6f66d02e74936b6240c922606ed to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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