deno.land / x / rambda@v9.1.1 / source / flip.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { flip } from './flip.js'import { subtract } from './subtract.js'import { update } from './update.js'
test('function with arity of 2', () => { const subtractFlipped = flip(subtract)
expect(subtractFlipped(1)(7)).toBe(6) expect(subtractFlipped(1, 7)).toBe(6) expect(subtractFlipped( 1, 7, 9 )).toBe(6)})
test('function with arity of 3', () => { const updateFlipped = flip(update)
const result = updateFlipped( 88, 0, [ 1, 2, 3 ] ) const curriedResult = updateFlipped(88, 0)([ 1, 2, 3 ]) const tripleCurriedResult = updateFlipped(88)(0)([ 1, 2, 3 ]) expect(result).toEqual([ 88, 2, 3 ]) expect(curriedResult).toEqual([ 88, 2, 3 ]) expect(tripleCurriedResult).toEqual([ 88, 2, 3 ])})
test('function with arity of 4', () => { const testFunction = ( a, b, c, d ) => `${ a - b }==${ c - d }` const testFunctionFlipped = flip(testFunction)
const result = testFunction( 1, 2, 3, 4 ) const flippedResult = testFunctionFlipped( 2, 1, 3, 4 ) expect(result).toEqual(flippedResult) expect(result).toBe('-1==-1')})
test('function with arity of 5', () => { const testFunction = ( a, b, c, d, e ) => `${ a - b }==${ c - d - e }` const testFunctionFlipped = flip(testFunction)
expect(() => testFunctionFlipped( 1, 2, 3, 4, 5 )).toThrowErrorMatchingInlineSnapshot('"R.flip doesn\'t work with arity > 4"')})
rambda

Version Info

Tagged at
2 months ago