`timescale 1ns/1ps
module test_modulo_count;
    reg [3:0] keys = 4'b1111;
    wire [9:0] twenty, five;
    integer count;
    modulo_count normal(keys, twenty);
    modulo_count #(.WIDTH(3), .MODULUS(5)) short_period(keys, five);
    task check;
        input integer n;
        reg [9:0] a, b;
        begin
            a = (n % 20) + ((n % 20 == 19) ? 512 : 0);
            b = (n % 5) + ((n % 5 == 4) ? 512 : 0);
            if (twenty !== a || five !== b) begin
                $display("FAIL count %0d outputs %h %h", n, twenty, five);
                $finish;
            end
        end
    endtask
    initial begin
        #2; keys[0] = 0; #2; check(0); keys[0] = 1;
        for (count = 1; count <= 42; count = count + 1) begin
            #2; keys[1] = 0; #3; check(count);
            keys[1] = 1; #3; check(count);
        end
        keys[0] = 0; #2; check(0);
        keys[1] = 0; #2; check(0); keys[1] = 1; keys[0] = 1;
        #2; keys[1] = 0; #2; check(1);
        $display("PASS two moduli, 42 press/release pairs and asynchronous reset");
        $finish;
    end
endmodule
