MCPcopy Create free account
hub / github.com/python/cpython / test_relative_symmetry

Method test_relative_symmetry

Lib/test/test_statistics.py:316–330  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

314 # Test symmetry of approx_equal.
315
316 def test_relative_symmetry(self):
317 # Check that approx_equal treats relative error symmetrically.
318 # (a-b)/a is usually not equal to (a-b)/b. Ensure that this
319 # doesn't matter.
320 #
321 # Note: the reason for this test is that an early version
322 # of approx_equal was not symmetric. A relative error test
323 # would pass, or fail, depending on which value was passed
324 # as the first argument.
325 #
326 args1 = [2456, 37.8, -12.45, Decimal('2.54'), Fraction(17, 54)]
327 args2 = [2459, 37.2, -12.41, Decimal('2.59'), Fraction(15, 54)]
328 assert len(args1) == len(args2)
329 for a, b in zip(args1, args2):
330 self.do_relative_symmetry(a, b)
331
332 def do_relative_symmetry(self, a, b):
333 a, b = min(a, b), max(a, b)

Callers

nothing calls this directly

Calls 3

do_relative_symmetryMethod · 0.95
DecimalClass · 0.90
FractionClass · 0.90

Tested by

no test coverage detected