-
Notifications
You must be signed in to change notification settings - Fork 114
/
curry-spec.js
41 lines (36 loc) · 1.38 KB
/
curry-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
describe('curry function', function () {
var fn1, fn2, curried1, curried2
beforeEach(function () {
fn1 = function (a, b, c) {
return a + b + c;
}
fn2 = function (a, b) {
return a * b;
}
curried1 = Monet.curry(fn1)
curried2 = Monet.curry(fn2)
})
afterEach(function () {
fn = curried = undefined
})
it('should return function that works as original without curring', function () {
expect(curried1(1, 1, 1)).toBe(fn1(1, 1, 1))
expect(curried2(2, 2)).toBe(fn2(2, 2))
})
it('should return properly curried function', function () {
expect(curried1(1)(1, 1)).toBe(fn1(1, 1, 1))
expect(curried1(1)(2, 3)).toBe(fn1(1, 2, 3))
expect(curried1(1, 2)(1)).toBe(fn1(1, 2, 1))
expect(curried1(2)(1)(2)).toBe(fn1(2, 1, 2))
expect(curried2(2)(3)).toBe(fn2(2, 3))
})
it('should provide curried function with not higher arity', function () {
expect(curried1(1, 1, 1, 5, 22)).toBe(fn1(1, 1, 1))
expect(curried1(1)(1, 1, 3)).toBe(fn1(1, 1, 1))
expect(curried1(1)(2, 3, 5)).toBe(fn1(1, 2, 3))
expect(curried1(1, 2)(1, 1)).toBe(fn1(1, 2, 1))
expect(curried1(2)(1)(2, 3, 5, 7, 8)).toBe(fn1(2, 1, 2))
expect(curried2(2)(3, 22)).toBe(fn2(2, 3))
expect(curried2(2, 2, 3, 4)).toBe(fn2(2, 2))
})
})