module test_adder_counter;
    reg [9:0] sw=0;
    reg [3:0] key=15;
    wire [6:0] digits[0:4-1];
    reg [6:0] glyphs[0:15];
    integer n;
    adder_counter dut(sw,key,digits[0],digits[1],digits[2],digits[3]);
    task check;
        input integer count;
        integer i;
        begin
            for(i=0;i<4;i=i+1)
                if(digits[i]!==glyphs[(count>>(4*i)) & 15]) begin
                    $display("FAIL expected %h at digit %d, pins %h",count,i,digits[i]);
                    $finish;
                end
        end
    endtask
    task pulse;
        begin key[0]=0; #2; key[0]=1; #2; end
    endtask
    initial begin
        glyphs[0]=7'h40; glyphs[1]=7'h79; glyphs[2]=7'h24; glyphs[3]=7'h30;
        glyphs[4]=7'h19; glyphs[5]=7'h12; glyphs[6]=7'h02; glyphs[7]=7'h78;
        glyphs[8]=7'h00; glyphs[9]=7'h10; glyphs[10]=7'h08; glyphs[11]=7'h03;
        glyphs[12]=7'h46; glyphs[13]=7'h21; glyphs[14]=7'h06; glyphs[15]=7'h0e;
        #2; pulse; check(0);
        sw=3;
        for(n=1;n<=(1<<16)+1;n=n+1) begin pulse; check(n); end
        sw=1; pulse; check(1);
        sw=2; #2; check(1);
        key[0]=0; #2; check(1);
        key[0]=1; #2; check(0);
        sw=3; pulse; check(1);
        $display("PASS full rollover, clock edge, hold, clear and restart"); $finish;
    end
endmodule
