I've implemented a function which calculate annual mortgage repayment, and I want to test whether it generates the correct results.
I've put input mortgage values in an array, such as:
input_array([ 50000., 100000., 150000., ...])
and the corresponding results in another array:
output_array([ 3200.60, 6401.20, 9601.79, ...])
I'd like to take each of the elements in the input array as the input of my function and test the result is the same as output_array.
Is it possible to do it automatically rather than input the mortgage value and expected output in the assertEqual
function manually?
Many thanks.
assertListEqual(map(f, input_array), output_array)
You have two options. The first, just compare whole arrays:
expected_list = [1, 2, 3, 4]
output_list = calc_mortgage([10, 20, 30, 42])
self.assertEqual(expected_list, output_list)
The second, you can compare each element:
expected_list = [1, 2, 3, 4]
output_list = calc_mortgage([10, 20, 30, 42])
for pair in zip(expected_list, output_list):
self.assertEqual(pair[0], pair[1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With