(self)
| 229 | self.assertRaises(TypeError, f, arg) |
| 230 | |
| 231 | def test_cmath_matches_math(self): |
| 232 | # check that corresponding cmath and math functions are equal |
| 233 | # for floats in the appropriate range |
| 234 | |
| 235 | # test_values in (0, 1) |
| 236 | test_values = [0.01, 0.1, 0.2, 0.5, 0.9, 0.99] |
| 237 | |
| 238 | # test_values for functions defined on [-1., 1.] |
| 239 | unit_interval = test_values + [-x for x in test_values] + \ |
| 240 | [0., 1., -1.] |
| 241 | |
| 242 | # test_values for log, log10, sqrt |
| 243 | positive = test_values + [1.] + [1./x for x in test_values] |
| 244 | nonnegative = [0.] + positive |
| 245 | |
| 246 | # test_values for functions defined on the whole real line |
| 247 | real_line = [0.] + positive + [-x for x in positive] |
| 248 | |
| 249 | test_functions = { |
| 250 | 'acos' : unit_interval, |
| 251 | 'asin' : unit_interval, |
| 252 | 'atan' : real_line, |
| 253 | 'cos' : real_line, |
| 254 | 'cosh' : real_line, |
| 255 | 'exp' : real_line, |
| 256 | 'log' : positive, |
| 257 | 'log10' : positive, |
| 258 | 'sin' : real_line, |
| 259 | 'sinh' : real_line, |
| 260 | 'sqrt' : nonnegative, |
| 261 | 'tan' : real_line, |
| 262 | 'tanh' : real_line} |
| 263 | |
| 264 | for fn, values in test_functions.items(): |
| 265 | float_fn = getattr(math, fn) |
| 266 | complex_fn = getattr(cmath, fn) |
| 267 | for v in values: |
| 268 | z = complex_fn(v) |
| 269 | self.rAssertAlmostEqual(float_fn(v), z.real) |
| 270 | self.assertEqual(0., z.imag) |
| 271 | |
| 272 | # test two-argument version of log with various bases |
| 273 | for base in [0.5, 2., 10.]: |
| 274 | for v in positive: |
| 275 | z = cmath.log(v, base) |
| 276 | self.rAssertAlmostEqual(math.log(v, base), z.real) |
| 277 | self.assertEqual(0., z.imag) |
| 278 | |
| 279 | @requires_IEEE_754 |
| 280 | def test_specific_values(self): |
nothing calls this directly
no test coverage detected