1module testbench;
2
3 function automatic int count_even(input int arr[]);
4//Write Your Code Here
5//Do not remove default Code
6 endfunction
7
8 int arr1[] = '{1,2,3,4};
9 int arr2[] = '{2,4,6};
10 int arr3[] = '{1,3,5};
11
12 int expected[3] = '{2,3,0};
13
14 initial begin
15 int res;
16
17 // ---------------- TEST 1 ----------------
18 $display("\n---- Running Test 1 ----");
19 $display("Input = %p", arr1);
20 res = count_even(arr1);
21 $display("Expected = %0d | Got = %0d", expected[0], res);
22
23 if (res != expected[0]) begin
24 $display("❌ FAIL: Test 1");
25 $fatal;
26 end else
27 $display("✅ PASS: Test 1");
28
29
30 // ---------------- TEST 2 ----------------
31 $display("\n---- Running Test 2 ----");
32 $display("Input = %p", arr2);
33 res = count_even(arr2);
34 $display("Expected = %0d | Got = %0d", expected[1], res);
35
36 if (res != expected[1]) begin
37 $display("❌ FAIL: Test 2");
38 $fatal;
39 end else
40 $display("✅ PASS: Test 2");
41
42
43 // ---------------- TEST 3 ----------------
44 $display("\n---- Running Test 3 ----");
45 $display("Input = %p", arr3);
46 res = count_even(arr3);
47 $display("Expected = %0d | Got = %0d", expected[2], res);
48
49 if (res != expected[2]) begin
50 $display("❌ FAIL: Test 3");
51 $fatal;
52 end else
53 $display("✅ PASS: Test 3");
54
55
56 $display("\n🎉 ALL TESTS PASSED");
57 $finish;
58 end
59
60endmodule