-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiona.test.js
More file actions
114 lines (101 loc) · 2.78 KB
/
fiona.test.js
File metadata and controls
114 lines (101 loc) · 2.78 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import {
constant,
every,
some,
take,
drop,
partition,
range,
cat,
split,
append,
nth,
first,
second,
} from "./fiona";
test("constant", () => {
expect(constant(1)(null)).toBe(1);
expect(constant(1)("blah")).toBe(1);
expect(constant("thunder")(42)).toBe("thunder");
const a = [1, 2, 3];
expect(constant(a)(42)).toBe(a);
});
test("every", () => {
const isOdd = (x) => x % 2 !== 0;
expect(every(isOdd, undefined)).toBe(true);
expect(every(isOdd, [])).toBe(true);
expect(every(isOdd, [1])).toBe(true);
expect(every(isOdd, [2])).toBe(false);
expect(every(isOdd, [1, 2, 3])).toBe(false);
expect(every(isOdd, [1, 3, 5, 7, 9, 11, 13, 132])).toBe(false);
expect(every(isOdd, [1, 3, 5, 7, 9, 11, 13, 131])).toBe(true);
});
test("some", () => {
const isOdd = (x) => x % 2 !== 0;
expect(some(isOdd, undefined)).toBe(false);
expect(some(isOdd, [])).toBe(false);
expect(some(isOdd, [1])).toBe(true);
expect(some(isOdd, [2])).toBe(false);
expect(some(isOdd, [1, 2, 3])).toBe(true);
expect(some(isOdd, [1, 3, 5, 7, 9, 11, 13, 132])).toBe(true);
expect(some(isOdd, [2, 4, 6, 8, 10, 12, 14, 28])).toBe(false);
});
test("take", () => {
expect(take(2, [0])).toEqual([0]);
expect(take(2, [])).toEqual([]);
expect(take(2, [0, 1, 2, 3, 4, 5])).toEqual([0, 1]);
expect(take(10, [0, 1, 2, 3, 4, 5])).toEqual([0, 1, 2, 3, 4, 5]);
});
test("drop", () => {
expect(drop(2, [0])).toEqual([]);
expect(drop(2, [])).toEqual([]);
expect(drop(2, [0, 1, 2, 3, 4, 5])).toEqual([2, 3, 4, 5]);
});
test("partition", () => {
expect(partition(2, [0, 1, 2, 3, 4, 5])).toEqual([
[0, 1],
[2, 3],
[4, 5],
]);
expect(partition(2, [0, 1, 2, 3, 4])).toEqual([[0, 1], [2, 3], [4]]);
});
test("range", () => {
expect(range(0)).toEqual([]);
expect(range(1)).toEqual([0]);
expect(range(10)).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
});
test("cat", () => {
expect(cat("", "")).toEqual("");
expect(cat("abc", "def")).toEqual("abcdef");
});
test("split", () => {
expect(split("", "abc")).toEqual(["a", "b", "c"]);
expect(split(" ", "A faint clap of thunder")).toEqual([
"A",
"faint",
"clap",
"of",
"thunder",
]);
});
test("append", () => {
expect(append(0, [])).toEqual([0]);
expect(append(4, [1, 2, 3])).toEqual([1, 2, 3, 4]);
});
test("nth", () => {
expect(nth(0, null)).toEqual(null);
expect(nth(0, [])).toEqual(undefined);
expect(nth(0, [1, 2, 3])).toEqual(1);
expect(nth(1, [1, 2, 3])).toEqual(2);
expect(nth(2, [1, 2, 3])).toEqual(3);
});
test("first", () => {
expect(first(null)).toEqual(null);
expect(first([])).toEqual(undefined);
expect(first([1, 2, 3])).toEqual(1);
});
test("second", () => {
expect(second(null)).toEqual(null);
expect(second([])).toEqual(undefined);
expect(second([1, 2, 3])).toEqual(2);
});