MCPcopy Index your code
hub / github.com/python/cpython / CMathTests

Class CMathTests

Lib/test/test_cmath.py:53–542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51 ]]
52
53class CMathTests(ComplexesAreIdenticalMixin, unittest.TestCase):
54 # list of all functions in cmath
55 test_functions = [getattr(cmath, fname) for fname in [
56 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh',
57 'cos', 'cosh', 'exp', 'log', 'log10', 'sin', 'sinh',
58 'sqrt', 'tan', 'tanh']]
59 # test first and second arguments independently for 2-argument log
60 test_functions.append(lambda x : cmath.log(x, 1729. + 0j))
61 test_functions.append(lambda x : cmath.log(14.-27j, x))
62
63 def setUp(self):
64 self.test_values = open(test_file, encoding="utf-8")
65
66 def tearDown(self):
67 self.test_values.close()
68
69 def rAssertAlmostEqual(self, a, b, rel_err = 2e-15, abs_err = 5e-323,
70 msg=None):
71 """Fail if the two floating-point numbers are not almost equal.
72
73 Determine whether floating-point values a and b are equal to within
74 a (small) rounding error. The default values for rel_err and
75 abs_err are chosen to be suitable for platforms where a float is
76 represented by an IEEE 754 double. They allow an error of between
77 9 and 19 ulps.
78 """
79
80 # special values testing
81 if math.isnan(a):
82 if math.isnan(b):
83 return
84 self.fail(msg or '{!r} should be nan'.format(b))
85
86 if math.isinf(a):
87 if a == b:
88 return
89 self.fail(msg or 'finite result where infinity expected: '
90 'expected {!r}, got {!r}'.format(a, b))
91
92 # if both a and b are zero, check whether they have the same sign
93 # (in theory there are examples where it would be legitimate for a
94 # and b to have opposite signs; in practice these hardly ever
95 # occur).
96 if not a and not b:
97 if math.copysign(1., a) != math.copysign(1., b):
98 self.fail(msg or 'zero has wrong sign: expected {!r}, '
99 'got {!r}'.format(a, b))
100
101 # if a-b overflows, or b is infinite, return False. Again, in
102 # theory there are examples where a is within a few ulps of the
103 # max representable float, and then b could legitimately be
104 # infinite. In practice these examples are rare.
105 try:
106 absolute_error = abs(b-a)
107 except OverflowError:
108 pass
109 else:
110 # test passes if either the absolute error or the relative

Callers

nothing calls this directly

Calls 2

appendMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…