Skip to content

Commit 0cae778

Browse files
Update tests to support latest V compiler (#287)
1 parent 4622c51 commit 0cae778

File tree

3 files changed

+179
-37
lines changed

3 files changed

+179
-37
lines changed

exercises/practice/connect/run_test.v

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn test_an_empty_board_has_no_winner() {
99
' . . . . .',
1010
]
1111
if _ := winner(board) {
12-
assert false, 'should return nothing'
12+
assert false, 'should return none'
1313
} else {
1414
assert true
1515
}
@@ -19,14 +19,22 @@ fn test_x_can_win_on_a_1x1_board() {
1919
board := [
2020
'X',
2121
]
22-
assert winner(board)! == `X`
22+
if res := winner(board) {
23+
assert res == `X`
24+
} else {
25+
assert false, 'should return X'
26+
}
2327
}
2428

2529
fn test_o_can_win_on_a_1x1_board() {
2630
board := [
2731
'O',
2832
]
29-
assert winner(board)! == `O`
33+
if res := winner(board) {
34+
assert res == `O`
35+
} else {
36+
assert false, 'should return O'
37+
}
3038
}
3139

3240
fn test_only_edges_does_not_make_a_winner() {
@@ -37,7 +45,7 @@ fn test_only_edges_does_not_make_a_winner() {
3745
' X O O O',
3846
]
3947
if _ := winner(board) {
40-
assert false, 'should return nothing'
48+
assert false, 'should return none'
4149
} else {
4250
assert true
4351
}
@@ -52,7 +60,7 @@ fn test_illegal_diagonal_does_not_make_a_winner() {
5260
' X X O O',
5361
]
5462
if _ := winner(board) {
55-
assert false, 'should return nothing'
63+
assert false, 'should return none'
5664
} else {
5765
assert true
5866
}
@@ -67,7 +75,7 @@ fn test_nobody_wins_crossing_adjacent_angles() {
6775
' . . O .',
6876
]
6977
if _ := winner(board) {
70-
assert false, 'should return nothing'
78+
assert false, 'should return none'
7179
} else {
7280
assert true
7381
}
@@ -81,7 +89,11 @@ fn test_x_wins_crossing_from_left_to_right() {
8189
' X X O X',
8290
' . O X .',
8391
]
84-
assert winner(board)! == `X`
92+
if res := winner(board) {
93+
assert res == `X`
94+
} else {
95+
assert false, 'should return X'
96+
}
8597
}
8698

8799
fn test_o_wins_crossing_from_top_to_bottom() {
@@ -92,7 +104,11 @@ fn test_o_wins_crossing_from_top_to_bottom() {
92104
' X X O X',
93105
' . O X .',
94106
]
95-
assert winner(board)! == `O`
107+
if res := winner(board) {
108+
assert res == `O`
109+
} else {
110+
assert false, 'should return O'
111+
}
96112
}
97113

98114
fn test_x_wins_using_a_convoluted_path() {
@@ -103,7 +119,11 @@ fn test_x_wins_using_a_convoluted_path() {
103119
' . X X . .',
104120
' O O O O O',
105121
]
106-
assert winner(board)! == `X`
122+
if res := winner(board) {
123+
assert res == `X`
124+
} else {
125+
assert false, 'should return X'
126+
}
107127
}
108128

109129
fn test_x_wins_using_a_spiral_path() {
@@ -118,5 +138,9 @@ fn test_x_wins_using_a_spiral_path() {
118138
' O O O O O O O X O',
119139
' X X X X X X X X O',
120140
]
121-
assert winner(board)! == `X`
141+
if res := winner(board) {
142+
assert res == `X`
143+
} else {
144+
assert false, 'should return X'
145+
}
122146
}

exercises/practice/simple-linked-list/run_test.v

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,18 @@ fn test_push_adds_element_to_the_list() {
99
mut list := new()
1010
list.push(1)
1111
list.push(2)
12-
assert list.pop()! == 2
13-
assert list.pop()! == 1
12+
13+
if res := list.pop() {
14+
assert res == 2
15+
} else {
16+
assert false, 'should return 2'
17+
}
18+
19+
if res := list.pop() {
20+
assert res == 1
21+
} else {
22+
assert false, 'should return 1'
23+
}
1424
}
1525

1626
fn test_push_increments_the_length() {
@@ -27,8 +37,19 @@ fn test_pop_returns_the_head_element_and_removes_it() {
2737
mut list := new()
2838
list.push(1)
2939
list.push(2)
30-
assert list.pop()! == 2
31-
assert list.pop()! == 1
40+
41+
if res := list.pop() {
42+
assert res == 2
43+
} else {
44+
assert false, 'should return 2'
45+
}
46+
47+
if res := list.pop() {
48+
assert res == 1
49+
} else {
50+
assert false, 'should return 1'
51+
}
52+
3253
assert list.is_empty()
3354
}
3455

@@ -58,8 +79,19 @@ fn test_pop_returns_nothing_if_the_list_is_empty() {
5879
fn test_peek_returns_the_head_element_without_removing_it() {
5980
mut list := new()
6081
list.push(1)
61-
assert list.peek()! == 1
62-
assert list.peek()! == 1
82+
83+
if res := list.peek() {
84+
assert res == 1
85+
} else {
86+
assert false, 'should return 1'
87+
}
88+
89+
if res := list.peek() {
90+
assert res == 1
91+
} else {
92+
assert false, 'should return 1'
93+
}
94+
6395
assert list.len == 1
6496
}
6597

@@ -90,8 +122,18 @@ fn test_from_array() {
90122
assert list.is_empty()
91123

92124
list = from_array([1, 2])
93-
assert list.pop()! == 2
94-
assert list.pop()! == 1
125+
126+
if res := list.pop() {
127+
assert res == 2
128+
} else {
129+
assert false, 'should return 2'
130+
}
131+
132+
if res := list.pop() {
133+
assert res == 1
134+
} else {
135+
assert false, 'should return 1'
136+
}
95137
}
96138

97139
fn test_to_array() {

exercises/practice/wordy/run_test.v

Lines changed: 95 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,97 +2,173 @@ module main
22

33
fn test_just_a_number() {
44
question := 'What is 5?'
5-
assert answer(question)! == 5
5+
if res := answer(question) {
6+
assert res == 5
7+
} else {
8+
assert false, 'should return 5, not an error'
9+
}
610
}
711

812
fn test_just_a_zero() {
913
question := 'What is 0?'
10-
assert answer(question)! == 0
14+
if res := answer(question) {
15+
assert res == 0
16+
} else {
17+
assert false, 'should return 0, not an error'
18+
}
1119
}
1220

1321
fn test_just_a_negative_number() {
1422
question := 'What is -123?'
15-
assert answer(question)! == -123
23+
if res := answer(question) {
24+
assert res == -123
25+
} else {
26+
assert false, 'should return -123, not an error'
27+
}
1628
}
1729

1830
fn test_addition() {
1931
question := 'What is 1 plus 1?'
20-
assert answer(question)! == 2
32+
if res := answer(question) {
33+
assert res == 2
34+
} else {
35+
assert false, 'should return 2, not an error'
36+
}
2137
}
2238

2339
fn test_addition_with_a_left_hand_zero() {
2440
question := 'What is 0 plus 2?'
25-
assert answer(question)! == 2
41+
if res := answer(question) {
42+
assert res == 2
43+
} else {
44+
assert false, 'should return 2, not an error'
45+
}
2646
}
2747

2848
fn test_addition_with_a_right_hand_zero() {
2949
question := 'What is 3 plus 0?'
30-
assert answer(question)! == 3
50+
if res := answer(question) {
51+
assert res == 3
52+
} else {
53+
assert false, 'should return 3, not an error'
54+
}
3155
}
3256

3357
fn test_more_addition() {
3458
question := 'What is 53 plus 2?'
35-
assert answer(question)! == 55
59+
if res := answer(question) {
60+
assert res == 55
61+
} else {
62+
assert false, 'should return 55, not an error'
63+
}
3664
}
3765

3866
fn test_addition_with_negative_numbers() {
3967
question := 'What is -1 plus -10?'
40-
assert answer(question)! == -11
68+
if res := answer(question) {
69+
assert res == -11
70+
} else {
71+
assert false, 'should return -11, not an error'
72+
}
4173
}
4274

4375
fn test_large_addition() {
4476
question := 'What is 123 plus 45678?'
45-
assert answer(question)! == 45801
77+
if res := answer(question) {
78+
assert res == 45801
79+
} else {
80+
assert false, 'should return 45801, not an error'
81+
}
4682
}
4783

4884
fn test_subtraction() {
4985
question := 'What is 4 minus -12?'
50-
assert answer(question)! == 16
86+
if res := answer(question) {
87+
assert res == 16
88+
} else {
89+
assert false, 'should return 16, not an error'
90+
}
5191
}
5292

5393
fn test_multiplication() {
5494
question := 'What is -3 multiplied by 25?'
55-
assert answer(question)! == -75
95+
if res := answer(question) {
96+
assert res == -75
97+
} else {
98+
assert false, 'should return -75, not an error'
99+
}
56100
}
57101

58102
fn test_division() {
59103
question := 'What is 33 divided by -3?'
60-
assert answer(question)! == -11
104+
if res := answer(question) {
105+
assert res == -11
106+
} else {
107+
assert false, 'should return -11, not an error'
108+
}
61109
}
62110

63111
fn test_multiple_additions() {
64112
question := 'What is 1 plus 1 plus 1?'
65-
assert answer(question)! == 3
113+
if res := answer(question) {
114+
assert res == 3
115+
} else {
116+
assert false, 'should return 3, not an error'
117+
}
66118
}
67119

68120
fn test_addition_and_subtraction() {
69121
question := 'What is 1 plus 5 minus -2?'
70-
assert answer(question)! == 8
122+
if res := answer(question) {
123+
assert res == 8
124+
} else {
125+
assert false, 'should return 8, not an error'
126+
}
71127
}
72128

73129
fn test_multiple_subtraction() {
74130
question := 'What is 20 minus 4 minus 13?'
75-
assert answer(question)! == 3
131+
if res := answer(question) {
132+
assert res == 3
133+
} else {
134+
assert false, 'should return 3, not an error'
135+
}
76136
}
77137

78138
fn test_subtraction_then_addition() {
79139
question := 'What is 17 minus 6 plus 3?'
80-
assert answer(question)! == 14
140+
if res := answer(question) {
141+
assert res == 14
142+
} else {
143+
assert false, 'should return 14, not an error'
144+
}
81145
}
82146

83147
fn test_multiple_multiplication() {
84148
question := 'What is 2 multiplied by -2 multiplied by 3?'
85-
assert answer(question)! == -12
149+
if res := answer(question) {
150+
assert res == -12
151+
} else {
152+
assert false, 'should return -12, not an error'
153+
}
86154
}
87155

88156
fn test_addition_and_multiplication() {
89157
question := 'What is -3 plus 7 multiplied by -2?'
90-
assert answer(question)! == -8
158+
if res := answer(question) {
159+
assert res == -8
160+
} else {
161+
assert false, 'should return -8, not an error'
162+
}
91163
}
92164

93165
fn test_multiple_division() {
94166
question := 'What is -12 divided by 2 divided by -3?'
95-
assert answer(question)! == 2
167+
if res := answer(question) {
168+
assert res == 2
169+
} else {
170+
assert false, 'should return 2, not an error'
171+
}
96172
}
97173

98174
fn test_unknown_operation() {

0 commit comments

Comments
 (0)