This repository has been archived by the owner on Mar 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·145 lines (126 loc) · 2.58 KB
/
test.sh
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
set -eu
. ./swi.sh
success() {
printf '[GOOD] %s\n' "$1" >&2
}
fail() {
printf '[FAIL] %s\n' "$1" >&2
}
assert_equal() {
expected=$1
actual=$2
tag=$3
if [ "$actual" != "$expected" ]; then
fail "$tag"
printf 'EXPECTED:\n%s\nACTUAL:\n%s' "$expected" "$actual"
return 1
else
success "$tag"
return 0
fi
}
test_flip() {
expected=$(list 1 2 3 4 5)
actual=$(seq 5 | map printf '%s.txt' | map flip basename .txt)
tag=test_flip
assert_equal "$expected" "$actual" "$tag"
}
test_flip
test_list() {
expected=$(printf '1\n3')
actual=$(list 1 3)
tag=test_list
assert_equal "$expected" "$actual" "$tag"
}
test_list
test_list_empty() {
expected=''
actual=$(list '' | map printf ':%s')
tag=test_list_empty
assert_equal "$expected" "$actual" "$tag"
}
test_list_empty
test_unlist() {
expected=$(printf '1 2 3 4 5')
actual=$(seq 5 | unlist)
tag=test_unlist
assert_equal "$expected" "$actual" "$tag"
}
test_unlist
test_map() {
expected=$(list 3 4 5 6 7)
actual=$(seq 5 | map add 2)
tag=test_map
assert_equal "$expected" "$actual" "$tag"
}
test_map
test_filter() {
expected=$(list 3 6 9)
actual=$(seq 10 | filter is_divisible_by 3)
tag=test_filter
assert_equal "$expected" "$actual" "$tag"
}
test_filter
test_remove() {
expected=$(list 1 2 4 5 7 8 10)
actual=$(seq 10 | remove is_divisible_by 3)
tag=test_remove
assert_equal "$expected" "$actual" "$tag"
}
test_remove
test_reduce() {
expected=15
actual=$(seq 5 | reduce add)
tag=test_reduce
assert_equal "$expected" "$actual" "$tag"
}
test_reduce
test_drop() {
expected=$(list 3 4 5)
actual=$(seq 5 | drop 2)
tag=test_drop
assert_equal "$expected" "$actual" "$tag"
}
test_drop
test_drop_while() {
expected=$(list 4 5)
actual=$(seq 5 | drop_while gt 4)
tag=test_drop_while
assert_equal "$expected" "$actual" "$tag"
}
test_drop_while
test_take() {
expected=$(list 1 2 3)
actual=$(seq 5 | take 3)
tag=test_take
assert_equal "$expected" "$actual" "$tag"
}
test_take
test_append() {
expected=$(list 1 2 3 a b c)
actual=$(seq 3 | append a b c)
tag=test_append
assert_equal "$expected" "$actual" "$tag"
}
test_append
test_prepend() {
expected=$(list a b c 1 2 3)
actual=$(seq 3 | prepend a b c)
tag=test_prepend
assert_equal "$expected" "$actual" "$tag"
}
test_prepend
test_count() {
expected=10
actual=$(seq 10 | count)
tag=test_count
assert_equal "$expected" "$actual" "$tag"
}
test_count
test_take_while() {
expected=$(list 1 2 3)
actual=$(seq 5 | take_while gt 4)
tag=test_take_while
assert_equal "$expected" "$actual" "$tag"
}
test_take_while