Created
July 8, 2016 00:33
-
-
Save alanrsoares/5e59afeddb91d1af928545a1ff958832 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
const assert = f => ([a, b]) => | |
(x => x === b | |
? { passed: true } | |
: { | |
failed: true, | |
message: `- expected f(${a}) to be ${b}, but was ${x}` | |
} | |
)(f(a)) | |
const runTests = (cases, f) => { | |
const results = cases.map(assert(f)) | |
const [passed, failed] = ['passed', 'failed'].map( | |
p => results.filter(x => x[p]) | |
) | |
return { passed, failed } | |
} | |
const failureSummary = failed => [ | |
`${failed.length} test${failed.length > 1 ? 's' : ''} have failed:`, | |
failed.map(x => x.message).join('\n\t') | |
].join('\n\t') | |
const report = ({ passed, failed }) => { | |
console.log( | |
`${passed.length} tests passed` | |
) | |
if (failed.length) { | |
const summary = failureSummary(failed) | |
console.error(summary) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment