summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-06 22:07:50 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-06 22:07:50 (GMT)
commit419670dc6017b5b463c88b08b4855aa7c9d396a3 (patch)
treef374bcf11ce2b0ced034967b58bc14b6a4bd1169
parent4bd810aaf215028fd0f512fd646e86ed6e27038d (diff)
downloadcpython-419670dc6017b5b463c88b08b4855aa7c9d396a3.zip
cpython-419670dc6017b5b463c88b08b4855aa7c9d396a3.tar.gz
cpython-419670dc6017b5b463c88b08b4855aa7c9d396a3.tar.bz2
Rewrite to use test_support's fine fcmp instead -- I didn't know that
existed when I wrote this test.
-rw-r--r--Lib/test/test_complex.py19
1 files changed, 3 insertions, 16 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index 9faab71..0e268ab 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -1,26 +1,13 @@
-from test_support import TestFailed
+from test_support import TestFailed, fcmp
from random import random
# XXX need many, many more tests here.
nerrors = 0
-def check_close_real(x, y, eps=1e-9):
- """Return true iff floats x and y "are close\""""
- # put the one with larger magnitude second
- if abs(x) > abs(y):
- x, y = y, x
- if y == 0:
- return abs(x) < eps
- if x == 0:
- return abs(y) < eps
- # check that relative difference < eps
- return abs((x-y)/y) < eps
-
-def check_close(x, y, eps=1e-9):
+def check_close(x, y):
"""Return true iff complexes x and y "are close\""""
- return check_close_real(x.real, y.real, eps) and \
- check_close_real(x.imag, y.imag, eps)
+ return fcmp(x.real, y.real) == 0 == fcmp(x.imag, y.imag)
def test_div(x, y):
"""Compute complex z=x*y, and check that z/x==y and z/y==x."""