-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.bash
executable file
·188 lines (137 loc) · 3.14 KB
/
test.bash
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env bats
. ./impl.bash
bats_require_minimum_version "1.8.0"
function test_lhs() { #@test
run lhs "LHS RHS"
[ "$output" = "LHS" ]
run lhs
[ "$output" = "" ]
run lhs "LHS"
[ "$output" = "LHS" ]
}
function test_rhs() { #@test
run rhs "LHS RHS"
[ "$output" = "RHS" ]
run rhs
[ "$output" = "" ]
run rhs "LHS"
[ "$output" = "" ]
}
function test_translate() { #@test
run translate "A"
[ "$output" = "rock" ]
run translate "B"
[ "$output" = "paper" ]
run translate "C"
[ "$output" = "scissors" ]
run translate "H"
[ "$output" = "" ]
[ "$status" -eq 1 ]
run translate ""
[ "$output" = "" ]
[ "$status" -eq 1 ]
run translate
[ "$output" = "" ]
[ "$status" -eq 1 ]
}
function test_translate_instruction() { #@test
run translate_instruction "X"
[ "$output" = "lose" ]
run translate_instruction "Y"
[ "$output" = "draw" ]
run translate_instruction "Z"
[ "$output" = "win" ]
run translate_instruction "A"
[ "$output" = "" ]
[ "$status" -eq 1 ]
run translate_instruction
[ "$output" = "" ]
[ "$status" -eq 1 ]
}
function test_pick_points() { #@test
run pick_points scissors
[ "$output" -eq 3 ]
run pick_points paper
[ "$output" -eq 2 ]
run pick_points rock
[ "$output" -eq 1 ]
run pick_points NotHandled
[ "$output" = "" ]
[ "$status" -eq 1 ]
run pick_points
[ "$output" = "" ]
[ "$status" -eq 1 ]
}
function test_score_points() { #@test
run score_points win
[ "$output" -eq 6 ]
run score_points draw
[ "$output" -eq 3 ]
run score_points loss
[ "$output" -eq 0 ]
run score_points uhandled
[ "$output" = "" ]
[ "$status" -eq 1 ]
run score_points
[ "$output" = "" ]
[ "$status" -eq 1 ]
}
function test_play() { #@test
run play "paper" "rock"
[ "$output" = "loss" ]
run play "paper" "paper"
[ "$output" = "draw" ]
run play "paper" "scissors"
[ "$output" = "win" ]
run play "unhandled" "scissors"
[ "$output" = "" ]
[ "$status" -eq 1 ]
run play "paper" "unhandled"
[ "$output" = "" ]
[ "$status" -eq 1 ]
run play
[ "$output" = "" ]
[ "$status" -eq 1 ]
}
function test_needed_hand() { #@test
run needed_hand "win" "scissors"
[ "$output" = "rock" ]
run needed_hand "draw" "scissors"
[ "$output" = "scissors" ]
run needed_hand "loss" "scissors"
[ "$output" = "paper" ]
}
function test_solution_pt1() { #@test
run solution_pt1 "A Y"
[ "$output" -eq 8 ]
run solution_pt1 "B X"
[ "$output" -eq 1 ]
run solution_pt1 "C Z"
[ "$output" -eq 6 ]
run solution_pt1 "C"
[ "$output" -eq 0 ]
run solution_pt1 ""
[ "$output" -eq 0 ]
}
function test_solution_pt2() { #@test
run solution_pt2 "A Y"
[ "$output" -eq 4 ]
run solution_pt2 "B X"
[ "$output" -eq 1 ]
run solution_pt2 "C Z"
[ "$output" -eq 7 ]
}
function test_loop() { #@test
run loop "pt1" test_input.txt
[ "$output" -eq 15 ]
run loop "pt2" test_input.txt
[ "$output" -eq 12 ]
run loop "pt3" test_input.txt
[ "$status" -eq 1 ]
[ "$output" = "wrong solution picked" ]
run loop "pt1" file_doesnt_exist_txt
[ "$status" -eq 1 ]
[ "$output" = "input file doesn't exist" ]
run loop "pt1" ""
[ "$status" -eq 1 ]
}