diff options
Diffstat (limited to '')
| -rw-r--r-- | task5/tb_scorehand.sv | 109 |
1 files changed, 105 insertions, 4 deletions
diff --git a/task5/tb_scorehand.sv b/task5/tb_scorehand.sv index 0d8f9d8..721cfb0 100644 --- a/task5/tb_scorehand.sv +++ b/task5/tb_scorehand.sv @@ -1,7 +1,108 @@ module tb_scorehand(); + logic err; + logic [3:0] card1, card2, card3, total; + scorehand DUT(card1, card2, card3, total); -// Your testbench goes here. Make sure your tests exercise the entire design -// in the .sv file. Note that in our tests the simulator will exit after -// 10,000 ticks (equivalent to "initial #10000 $finish();"). + task check; + input logic [3:0] expected; + if (total !== expected) begin + err = 1; + $display("FAILED: total is incorrect."); + end + endtask: check; -endmodule + initial begin + #10000; + $stop; + end + + initial begin + err = 0; + + /* (9 + 9 + 9) % 10 = 7. */ + + $display("Test 1"); + card1 = 4'd9; + card2 = 4'd9; + card3 = 4'd9; + #5; + check(4'd7); + #5; + + /* (9 + 9 + 0) % 10 = 8. */ + + $display("Test 2"); + card1 = 4'd9; + card2 = 4'd9; + card3 = 4'd0; + #5; + check(4'd8); + #5; + + /* (T + K + A) % 10 = 1. */ + + $display("Test 3"); + card1 = 4'd10; + card2 = 4'd13; + card3 = 4'd1; + #5; + check(4'd1); + #5; + + /* (J + Q + K) % 10 = 0. */ + + $display("Test 4"); + card1 = 4'd11; + card2 = 4'd12; + card3 = 4'd13; + #5; + check(4'd0); + #5; + + /* (A + 2 + 3) % 10 = 6. */ + + $display("Test 5"); + card1 = 4'd1; + card2 = 4'd2; + card3 = 4'd3; + #5; + check(4'd6); + #5; + + /* (9 + 0 + 0) % 10 = 9. */ + + $display("Test 6"); + card1 = 4'd9; + card2 = 4'd0; + card3 = 4'd0; + #5; + check(4'd9); + #5; + + /* (9 + T + 0) % 10 = 9. */ + + $display("Test 7"); + card1 = 4'd9; + card2 = 4'd10; + card3 = 4'd0; + #5; + check(4'd9); + #5; + + /* (9 + A + 0) % 10 = 0. */ + + $display("Test 8"); + card1 = 4'd9; + card2 = 4'd1; + card3 = 4'd0; + #5; + check(4'd0); + #5; + + if (~err) + $display("All tests passed."); + + #10; + $stop; + end +endmodule: tb_scorehand |