You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Bugs found in test_complex.py
list comprehensions from 3.x closures didn't handle nested for's before 3.6. Handle nanj and infj.
This commit is contained in:
41
test/simple_source/bug31/10_complex.py
Normal file
41
test/simple_source/bug31/10_complex.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Greatly simplified from from 3.3 test_complex.py
|
||||
|
||||
# RUNNABLE!
|
||||
def assertCloseAbs(x, y, eps=1e-09):
|
||||
"""Return true iff floats x and y "are close\""""
|
||||
if abs(x) > abs(y):
|
||||
x, y = y, x
|
||||
if y == 0:
|
||||
return abs(x) < eps
|
||||
if x == 0:
|
||||
return abs(y) < eps
|
||||
assert abs((x - y) / y) < eps
|
||||
|
||||
def assertClose(x, y, eps=1e-09):
|
||||
"""Return true iff complexes x and y "are close\""""
|
||||
assertCloseAbs(x.real, y.real, eps)
|
||||
assertCloseAbs(x.imag, y.imag, eps)
|
||||
|
||||
def check_div(x, y):
|
||||
"""Compute complex z=x*y, and check that z/x==y and z/y==x."""
|
||||
z = x * y
|
||||
if x != 0:
|
||||
q = z / x
|
||||
assertClose(q, y)
|
||||
q = z.__truediv__(x)
|
||||
assertClose(q, y)
|
||||
if y != 0:
|
||||
q = z / y
|
||||
assertClose(q, x)
|
||||
q = z.__truediv__(y)
|
||||
assertClose(q, x)
|
||||
|
||||
def test_truediv():
|
||||
simple_real = [float(i) for i in range(-5, 6)]
|
||||
simple_complex = [complex(x, y) for x in simple_real for y in simple_real]
|
||||
for x in simple_complex:
|
||||
for y in simple_complex:
|
||||
check_div(x, y)
|
||||
|
||||
z2 = -1e1000j # Check that we can handle -inf as a complex number
|
||||
test_truediv()
|
Reference in New Issue
Block a user