module tb_mux4x1_selfcheck;
reg [3:0] in;
reg [1:0] sel;
wire out;
reg expected;
integer errors = 0;
mux4x1 uut (
.in(in),
.sel(sel),
.out(out)
);
initial begin
$display("Time\tin\t sel\t expected\t out\t Result");
// Loop through input and select lines
in = 4'b1010; // You can try other inputs too
for (sel = 0; sel < 4; sel = sel + 1) begin
#5;
expected = in[sel];
#1; // Small delay to allow output to settle
if (out !== expected)
begin
$display("%0t\t%b\t %b\t %b\t\t %b\t FAIL", $time, in, sel, expected, out);
errors = errors + 1;
end
else
$display("%0t\t%b\t %b\t %b\t\t %b\t PASS", $time, in, sel, expected, out);
end
if (errors == 0)
$display("Test Passed with 0 errors.");
else
$display("Test Failed with %0d errors.", errors);
$finish;
end
endmodule