Skip to content

Commit 0a1a60e

Browse files
committed
Changed the number of decimal places printed from fixed to variable.
I changed the number of decimal places printed for a failure from a fixed "3" to the precision being tested +1. This will allow it to work with any other level of precision that is passed in to the function. In addition it will show errors where they are only different by a rounded part (causing the assertion, but looking the same). For example 3.1415 and 3.1414 will throw an assertion (round to 3.142 and 3.141) but will both print as 3.141 with %.3f. ...%." + str(precision) + "f... will print the extra digit that determines rounding.
1 parent 01b78c0 commit 0a1a60e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

homework6.3/test.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def compare_matrices(self, expected, got, name, precision = 3):
6363
for i, (xrow, yrow) in enumerate(zip(x.value, y.value)):
6464
for j, (xel, yel) in enumerate(zip(xrow, yrow)):
6565
self.assertAlmostEqual(xel, yel, precision,
66-
"The element at (%d, %d) in %s matrix differs: expected %.3f, got %.3f" % (i, j, name, xel, yel))
66+
("The element at (%d, %d) in %s matrix differs: expected %." +
67+
str(precision+1) + "f, got %." + str(precision+1) +
68+
"f") % (i, j, name, xel, yel))
6769

6870
def solution_check(self, result, answer_mu, answer_omega):
6971
self.assertTrue(len(result) == 2,

0 commit comments

Comments
 (0)