moy-fp
Version:
A functional programming library.
84 lines (70 loc) • 2.4 kB
JavaScript
import __ from '../../src/Function/__'
/**
* Number -> ((a, b, ..., m) -> n) -> ((a, b, ..., m) -> n)
*/
import nAry from '../../src/Function/nAry'
test('nAry(not using __), the original arity is 0', () => {
expect(
nAry(0, () => [])()
).toEqual([])
})
test('nAry(not using __), the original arity is 1', () => {
expect(
nAry(1, (a) => [a])(1)
).toEqual([1])
})
test('nAry(not using __), the original arities are 2', () => {
expect(
nAry(2, (a, b) => [a, b])(1)(2)
).toEqual([1, 2])
})
test('nAry(not using __), the original arities are 3', () => {
expect(
nAry(3, (a, b, c) => [a, b, c])(1)(2)(3)
).toEqual([1, 2, 3])
})
test('nAry(not using __), the original arities are 4', () => {
expect(
nAry(4, (a, b, c, d) => [a, b, c, d])(1)(2)(3)(4)
).toEqual([1, 2, 3, 4])
})
test('nAry(not using __), the original arities are 5', () => {
expect(
nAry(5, (a, b, c, d, e) => [a, b, c, d, e])(1)(2)(3)(4)(5)
).toEqual([1, 2, 3, 4, 5])
})
test('nAry(not using __), the original arities are 6', () => {
expect(
nAry(6, (a, b, c, d, e, f) => [a, b, c, d, e, f])(1)(2)(3)(4)(5)(6)
).toEqual([1, 2, 3, 4, 5, 6])
})
test('nAry(not using __), the original arities are 7', () => {
expect(
nAry(7, (a, b, c, d, e, f, g) => [a, b, c, d, e, f, g])(1)(2)(3)(4)(5)(6)(7)
).toEqual([1, 2, 3, 4, 5, 6, 7])
})
test('nAry(not using __), the original arities are 8', () => {
expect(
nAry(8, (a, b, c, d, e, f, g, h) => [a, b, c, d, e, f, g, h])(1)(2)(3)(4)(5)(6)(7)(8)
).toEqual([1, 2, 3, 4, 5, 6, 7, 8])
})
test('nAry(not using __), the original arities are 9', () => {
expect(
nAry(9, (a, b, c, d, e, f, g, h, i) => [a, b, c, d, e, f, g, h, i])(1)(2)(3)(4)(5)(6)(7)(8)(9)
).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
})
test('nAry(not using __), the original arities are 10', () => {
expect(
nAry(10, (a, b, c, d, e, f, g, h, i, j) => [a, b, c, d, e, f, g, h, i, j])(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)
).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
})
test('nAry(not using __), the original arities are more than 10', () => {
expect(
nAry(11, (a, b, c, d, e, f, g, h, i, j, k) => [a, b, c, d, e, f, g, h, i, j, k])(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
})
test('nary(using __), the original arities are 2', () => {
expect(
nAry(__, (a, b) => [a, b])(2)(1)(2)
).toEqual([1, 2])
})