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
|
`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_task4();
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);
if (~err)
$display("All tests passed.");
#10;
$stop;
end
endmodule: tb_task4
|