module crc_gen_tb;
    parameter CRCBITS=7;
    parameter COMMANDLEN=40;
    parameter POLYNOMIAL='h89;

    logic clk, reset, start, ready;
    logic [COMMANDLEN-1:0] num;
    logic [CRCBITS-1:0] crc;

    logic [CRCBITS-1:0] test_cases [logic [COMMANDLEN-1:0]];

    crc_gen #(CRCBITS,COMMANDLEN,POLYNOMIAL) dut (.*);

    initial begin
        clk = 0;
        forever #10 clk = ~clk;
    end

    initial begin
        test_cases = '{
            'h1234567890: 'h10,
            'hBEEFB05535: 'h05,
            'h5544992211: 'h17,
            '0: '0
        };

        reset = 1;
        start = 0;
        repeat (2) @(posedge clk);
        reset = 0;
        @(posedge clk);
        foreach (test_cases[key]) begin
            wait (ready);
            num = key;
            @(posedge clk);
            start = 1;
            @(posedge clk);
            start = 0;
            @(posedge clk);
            wait(ready);
            assert (crc === test_cases[key])
                else $error("Invalid crc, found 0x%x but expected 0x%x",crc,test_cases[key]);
        end

        $finish;

    end

endmodule
