Skip to content

Commit

Permalink
make this test take 5s instead of a 1 min by compiling one function, …
Browse files Browse the repository at this point in the history
…not 18
cfbolz committed Jan 6, 2024
1 parent b1a82d2 commit f449aa0
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions rpython/translator/c/test/test_genc.py
Original file line number Diff line number Diff line change
@@ -408,33 +408,39 @@ def test_nan_and_special_values():
assert math.isinf(inf)
nan = inf/inf
assert math.isnan(nan)

for value, checker in [
(inf, lambda x: math.isinf(x) and x > 0.0),
(-inf, lambda x: math.isinf(x) and x < 0.0),
(nan, math.isnan),
(42.0, isfinite),
(0.0, lambda x: not x and math.copysign(1., x) == 1.),
(-0.0, lambda x: not x and math.copysign(1., x) == -1.),
]:
def f():
return value
f1 = compile(f, [])
res = f1()
values_and_checkers = [
(inf, lambda x: math.isinf(x) and x > 0.0),
(-inf, lambda x: math.isinf(x) and x < 0.0),
(nan, math.isnan),
(42.0, isfinite),
(0.0, lambda x: not x and math.copysign(1., x) == 1.),
(-0.0, lambda x: not x and math.copysign(1., x) == -1.),
]
unrolling_values = unrolling_iterable(enumerate(values_and_checkers))
l = [[value] for value, _ in values_and_checkers]
l2 = [[(-value, -value), (value, value)] for value, _ in values_and_checkers]

def f(variant, index, x):
if variant == 0:
for i, (value, _) in unrolling_values:
if index == i:
return value
assert 0
if variant == 1:
return l[index][x]
if variant == 2:
return l2[index][x][1]
assert 0
f1 = compile(f, [int, int, int])

for index, (value, checker) in enumerate(values_and_checkers):
res = f1(0, index, -1)
assert checker(res)

l = [value]
def g(x):
return l[x]
g2 = compile(g, [int])
res = g2(0)
res = f1(1, index, 0)
assert checker(res)

l2 = [(-value, -value), (value, value)]
def h(x):
return l2[x][1]
h3 = compile(h, [int])
res = h3(1)
res = f1(2, index, 1)
assert checker(res)

def test_prebuilt_instance_with_dict():

0 comments on commit f449aa0

Please sign in to comment.