module tb; timeunit 1ns; timeprecision 1ps; logic clk=0, reset=0, enable=0; logic [3:0] count; int checks=0; counter dut(.*); always #5 clk=~clk; task automatic step(input bit r,input bit e); @(negedge clk); reset=r; enable=e; @(posedge clk); #1; endtask initial begin for(int state=0;state<16;state++) begin for(int r=0;r<2;r++) begin for(int e=0;e<2;e++) begin step(1,0); repeat(state) step(0,1); if(int'(count)!=state) $fatal(1,"State setup failed"); step(1'(r),1'(e)); if(int'(count)!=((r!=0) ? 0 : ((e!=0) ? (state+1)%16 : state))) $fatal(1,"Transition failed: state=%0d reset=%0d enable=%0d",state,r,e); checks++; end end end $display("PASS: %0d state/control transitions",checks); $finish; end endmodule