Asserts that two floats are near each other. Checks that |f1 - f2| < err and asserts a test failure if not. Args: f1: A float value. f2: A float value. err: A float value. msg: An optional string message to append to the failure message.
(self, f1, f2, err, msg=None)
| 2263 | # pylint: enable=invalid-name |
| 2264 | @py_func_if_in_function |
| 2265 | def assertNear(self, f1, f2, err, msg=None): |
| 2266 | """Asserts that two floats are near each other. |
| 2267 | |
| 2268 | Checks that |f1 - f2| < err and asserts a test failure |
| 2269 | if not. |
| 2270 | |
| 2271 | Args: |
| 2272 | f1: A float value. |
| 2273 | f2: A float value. |
| 2274 | err: A float value. |
| 2275 | msg: An optional string message to append to the failure message. |
| 2276 | """ |
| 2277 | # f1 == f2 is needed here as we might have: f1, f2 = inf, inf |
| 2278 | self.assertTrue( |
| 2279 | f1 == f2 or math.fabs(f1 - f2) <= err, "%f != %f +/- %f%s" % |
| 2280 | (f1, f2, err, " (%s)" % msg if msg is not None else "")) |
| 2281 | |
| 2282 | @py_func_if_in_function |
| 2283 | def assertArrayNear(self, farray1, farray2, err, msg=None): |
no outgoing calls
no test coverage detected