//----------------------------------------------------------------------------- // // Title : decimalAccumulator_tf // Design : test_fixtures // Author : // Company : // //----------------------------------------------------------------------------- // // File : z:\my_designs\AlternativeLab4\test_fixtures\src\decimalAccumulator_tf.v // Generated : Thu Oct 23 17:12:07 2014 // From : interface description file // By : Itf2Vhdl ver. 1.22 // //----------------------------------------------------------------------------- // // Description : // //----------------------------------------------------------------------------- `timescale 1 ns / 1 ps //{{ Section below this comment is automatically maintained // and may be overwritten //{module {decimalAccumulator_tf}} module decimalAccumulator_tf ( output reg clk, output reg [8:0] SW, output reg addsub, input [6:0] HEX0, input [6:0] HEX1); //}} End of automatically maintained section integer resultFile, errors; reg [7:0] i; reg [6:0] expectedHi; reg [6:0] expectedLo; initial begin resultFile = $fopen("FA_tf_output.txt"); if (resultFile == 0) begin $fdisplay(resultFile, "Error: Unable to open file."); $finish; end resultFile = resultFile | 1; errors = 0; SW[7:0] = 0; clk = 0; #10 SW[8] = 1; clk = 1; #10 clk = 0; SW[8] = 0; #10 if ((HEX0 != 64) || (HEX1 != 64)) begin $fdisplay(resultFile, "Error: Reset not functioning, returned %d and %d", HEX0, HEX1); errors = errors + 1; end else begin $fdisplay(resultFile, "Reset functionality test passed"); end //testing addition of 1 $fdisplay(resultFile, "Testing addition of 1"); addsub = 0; SW[7:0] = 1; #10 for (i = 1; i < 100; i = i + 1) begin clk = 1; #10 clk = 0; #10 case(i / 10) 7'd0: expectedHi = 63; 7'd1: expectedHi = 6; 7'd2: expectedHi = 91; 7'd3: expectedHi = 79; 7'd4: expectedHi = 102; 7'd5: expectedHi = 109; 7'd6: expectedHi = 125; 7'd7: expectedHi = 7; 7'd8: expectedHi = 127; 7'd9: expectedHi = 111; 7'd10: expectedHi = 119; 7'd11: expectedHi = 124; 7'd12: expectedHi = 57; 7'd13: expectedHi = 94; 7'd14: expectedHi = 121; 7'd15: expectedHi = 113; endcase case(i % 10) 7'd0: expectedLo = 63; 7'd1: expectedLo = 6; 7'd2: expectedLo = 91; 7'd3: expectedLo = 79; 7'd4: expectedLo = 102; 7'd5: expectedLo = 109; 7'd6: expectedLo = 125; 7'd7: expectedLo = 7; 7'd8: expectedLo = 127; 7'd9: expectedLo = 111; 7'd10: expectedLo = 119; 7'd11: expectedLo = 124; 7'd12: expectedLo = 57; 7'd13: expectedLo = 94; 7'd14: expectedLo = 121; 7'd15: expectedLo = 113; endcase if (HEX0 !== ~expectedHi) begin $fdisplay(resultFile, "Error: Expected %d - Got: %b for the first digit", i, HEX0); errors = errors + 1; end else begin if (HEX1 !== ~expectedLo) begin $fdisplay(resultFile, "Error: Expected %d - Got: %b for the second digit", i, HEX1); errors = errors + 1; end else begin $fdisplay(resultFile, "Case %d passed", i); end end end $fdisplay(resultFile, "Testing addition of 11"); //testing subtraction of 11 addsub = 1; SW[7:0] = 11; #10 for (i = 99 - 11; i > 0; i = i - 11) begin clk = 1; #10 clk = 0; #10 case(i / 10) 7'd0: expectedHi = 63; 7'd1: expectedHi = 6; 7'd2: expectedHi = 91; 7'd3: expectedHi = 79; 7'd4: expectedHi = 102; 7'd5: expectedHi = 109; 7'd6: expectedHi = 125; 7'd7: expectedHi = 7; 7'd8: expectedHi = 127; 7'd9: expectedHi = 111; 7'd10: expectedHi = 119; 7'd11: expectedHi = 124; 7'd12: expectedHi = 57; 7'd13: expectedHi = 94; 7'd14: expectedHi = 121; 7'd15: expectedHi = 113; endcase case(i % 10) 7'd0: expectedLo = 63; 7'd1: expectedLo = 6; 7'd2: expectedLo = 91; 7'd3: expectedLo = 79; 7'd4: expectedLo = 102; 7'd5: expectedLo = 109; 7'd6: expectedLo = 125; 7'd7: expectedLo = 7; 7'd8: expectedLo = 127; 7'd9: expectedLo = 111; 7'd10: expectedLo = 119; 7'd11: expectedLo = 124; 7'd12: expectedLo = 57; 7'd13: expectedLo = 94; 7'd14: expectedLo = 121; 7'd15: expectedLo = 113; endcase if (HEX0 !== ~expectedHi) begin $fdisplay(resultFile, "Error: Expected %d - Got: %b for the first digit", i, HEX0); errors = errors + 1; end else begin if (HEX1 !== ~expectedLo) begin $fdisplay(resultFile, "Error: Expected %d - Got: %b for the second digit", i, HEX1); errors = errors + 1; end else begin $fdisplay(resultFile, "Case %d passed", i); end end end $fdisplay(resultFile, "End of test - %d errors found.", errors); $fclose(resultFile); end endmodule