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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
`define ACE 7'b0001000
`define TWO 7'b0100100
`define THREE 7'b0110000
`define FOUR 7'b0011001
`define FIVE 7'b0010010
`define SIX 7'b0000010
`define SEVEN 7'b1111000
`define EIGHT 7'b0000000
`define NINE 7'b0010000
`define TEN 7'b1000000
`define JACK 7'b1100001
`define QUEEN 7'b0011000
`define KING 7'b0001001
`define BLANK 7'b1111111
module tb_task5();
logic err, resetb, slow_clock, CLOCK_50;
logic [3:0] KEY;
logic [6:0] HEX0, HEX1, HEX2, HEX3, HEX4, HEX5;
logic [9:0] LEDR;
assign KEY[0] = slow_clock;
assign KEY[3] = resetb;
task5 DUT(CLOCK_50, KEY, LEDR, HEX5, HEX4, HEX3, HEX2, HEX1, HEX0);
task check;
input logic [6:0] expected_HEX0, expected_HEX1, expected_HEX2,
expected_HEX3, expected_HEX4, expected_HEX5;
input logic [9:0] expected_LEDR;
if (HEX0 !== expected_HEX0) begin
err = 1;
$display("FAILED: HEX0 is incorrect.",);
end
if (HEX1 !== expected_HEX1) begin
err = 1;
$display("FAILED: HEX1 is incorrect.",);
end
if (HEX2 !== expected_HEX2) begin
err = 1;
$display("FAILED: HEX2 is incorrect.",);
end
if (HEX3 !== expected_HEX3) begin
err = 1;
$display("FAILED: HEX3 is incorrect.",);
end
if (HEX4 !== expected_HEX4) begin
err = 1;
$display("FAILED: HEX4 is incorrect.",);
end
if (HEX5 !== expected_HEX5) begin
err = 1;
$display("FAILED: HEX5 is incorrect.",);
end
if (LEDR !== expected_LEDR) begin
err = 1;
$display("FAILED: LEDR is incorrect.",);
end
endtask: check
initial forever begin
slow_clock = 1'b0;
#5;
slow_clock = 1'b1;
#5;
end
initial begin
err = 0;
/* Reset. */
$display("Test 1");
resetb = 1'b0;
#10;
resetb = 1'b1;
check(`BLANK, `BLANK, `BLANK, `BLANK, `BLANK, `BLANK, 10'b00_0000_0000);
/* Test for natural win. Player: 9T, dealer: A2. */
$display("Test 2.1");
force tb_task5.DUT.dp.new_card = 4'd9;
#10;
check(`NINE, `BLANK, `BLANK, `BLANK, `BLANK, `BLANK, 10'b00_0000_1001);
$display("Test 2.2");
force tb_task5.DUT.dp.new_card = 4'd1;
#10;
check(`NINE, `BLANK, `BLANK, `ACE, `BLANK, `BLANK, 10'b00_0001_1001);
$display("Test 2.3");
force tb_task5.DUT.dp.new_card = 4'd10;
#10;
check(`NINE, `TEN, `BLANK, `ACE, `BLANK, `BLANK, 10'b00_0001_1001);
$display("Test 2.4");
force tb_task5.DUT.dp.new_card = 4'd2;
#10;
check(`NINE, `TEN, `BLANK, `ACE, `TWO, `BLANK, 10'b00_0011_1001);
$display("Test 2.5");
/* Load anything. */
force tb_task5.DUT.dp.new_card = 4'd10;
#10;
check(`NINE, `TEN, `BLANK, `ACE, `TWO, `BLANK, 10'b01_0011_1001);
$display("Test 2.6");
resetb = 1'b0;
#10;
resetb = 1'b1;
check(`BLANK, `BLANK, `BLANK, `BLANK, `BLANK, `BLANK, 10'b00_0000_0000);
/* Test for player stand, dealer hit. Player: 34, dealer: 678. */
$display("Test 3.1");
force tb_task5.DUT.dp.new_card = 4'd3;
#10;
check(`THREE, `BLANK, `BLANK, `BLANK, `BLANK, `BLANK, 10'b00_0000_0011);
$display("Test 3.2");
force tb_task5.DUT.dp.new_card = 4'd6;
#10;
check(`THREE, `BLANK, `BLANK, `SIX, `BLANK, `BLANK, 10'b00_0110_0011);
$display("Test 3.3");
force tb_task5.DUT.dp.new_card = 4'd4;
#10;
check(`THREE, `FOUR, `BLANK, `SIX, `BLANK, `BLANK, 10'b00_0110_0111);
$display("Test 3.4");
force tb_task5.DUT.dp.new_card = 4'd7;
#10;
check(`THREE, `FOUR, `BLANK, `SIX, `SEVEN, `BLANK, 10'b00_0011_0111);
$display("Test 3.5");
force tb_task5.DUT.dp.new_card = 4'd8;
#10;
check(`THREE, `FOUR, `BLANK, `SIX, `SEVEN, `EIGHT, 10'b01_0001_0111);
$display("Test 3.6");
resetb = 1'b0;
#10;
resetb = 1'b1;
check(`BLANK, `BLANK, `BLANK, `BLANK, `BLANK, `BLANK, 10'b00_0000_0000);
/* Test for player hit, dealer hit. Player: 4JQ, dealer: 672. */
$display("Test 4.1");
force tb_task5.DUT.dp.new_card = 4'd4;
#10;
check(`FOUR, `BLANK, `BLANK, `BLANK, `BLANK, `BLANK, 10'b00_0000_0100);
$display("Test 4.2");
force tb_task5.DUT.dp.new_card = 4'd6;
#10;
check(`FOUR, `BLANK, `BLANK, `SIX, `BLANK, `BLANK, 10'b00_0110_0100);
$display("Test 4.3");
force tb_task5.DUT.dp.new_card = 4'd11;
#10;
check(`FOUR, `JACK, `BLANK, `SIX, `BLANK, `BLANK, 10'b00_0110_0100);
$display("Test 4.4");
force tb_task5.DUT.dp.new_card = 4'd7;
#10;
check(`FOUR, `JACK, `BLANK, `SIX, `SEVEN, `BLANK, 10'b00_0011_0100);
$display("Test 4.5");
force tb_task5.DUT.dp.new_card = 4'd12;
#10;
check(`FOUR, `JACK, `QUEEN, `SIX, `SEVEN, `BLANK, 10'b00_0011_0100);
$display("Test 4.6");
force tb_task5.DUT.dp.new_card = 4'd2;
#10;
check(`FOUR, `JACK, `QUEEN, `SIX, `SEVEN, `BLANK, 10'b01_0011_0100);
$display("Test 4.7");
resetb = 1'b0;
#10;
resetb = 1'b1;
check(`BLANK, `BLANK, `BLANK, `BLANK, `BLANK, `BLANK, 10'b00_0000_0000);
if (~err)
$display("All tests passed.");
#10;
$stop;
end
endmodule: tb_task5
|