# /*Testbench*/
-if __name__ == '__main__':
- arr = [5,2,8,1,3,7,9,4]
- print("search list", arr)
- result = m2(arr)
- print("Index of the maximum value in an array is: %d" % result)
- assert (result == 6)
-
- arr = [5,2,8,9,9,7,9,4]
- print("search list", arr)
- result = m2(arr)
- print("Index of the maximum value in an array is: %d" % result)
- assert (result == 3)
+test_data = [
+ ([5,2,8,1,3,7,9,4], 6),
+ ([5,2,8,9,9,7,9,4], 3),
+ ([0,0,0,0,0,0,0,0], 0),
+ ([5,5,5,5,5,5,5,5], 0),
+]
- arr = [0,0,0,0,0,0,0,0]
- print("search list", arr)
- result = m2(arr)
- print("Index of the maximum value in an array is: %d" % result)
- assert (result == 0)
-
- arr = [5,5,5,5,5,5,5,5]
- print("search list", arr)
- result = m2(arr)
- print("Index of the maximum value in an array is: %d" % result)
- assert (result == 0)
+if __name__ == '__main__':
+ for arr, expected in test_data:
+ print("search list", arr)
+ result = m2(arr)
+ print("Index of the maximum value in an array is: %d" % result)
+ assert (result == expected)