Created
December 16, 2019 01:48
-
-
Save victorkurauchi/e0a217cb543051a9a4d9943f1470a312 to your computer and use it in GitHub Desktop.
Testing clojures
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 secret = (msg) => () => msg; | |
// partialApply(targetFunction: Function, ...fixedArgs: Any[]) => | |
// functionWithFewerParams(...remainingArgs: Any[]) | |
const partialApply = (fn, ...fixedArgs) => { | |
return function (...remainingArgs) { | |
return fn.apply(this, fixedArgs.concat(remainingArgs)); | |
}; | |
}; | |
describe('testing clojure', () => { | |
test('secret', () => { | |
const msg = 'secret() should return a function that returns the passed secret.'; | |
const theSecret = 'Closures are easy.'; | |
const mySecret = secret(theSecret); | |
console.log(mySecret); | |
const actual = mySecret(); | |
const expected = theSecret; | |
expect(actual).toBe(expected); | |
}); | |
test('adds 1 + 1 = 2', () => { | |
const add = (a, b) => a + b; | |
const result = add(1, 1); | |
expect(result).toBe(2); | |
}); | |
test('partialApply() should partially apply functions', () => { | |
const add = (a, b) => a + b; | |
const add10 = partialApply(add, 10); | |
const actual = add10(5); | |
const expected = 15; | |
expect(actual).toBe(expected); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment