@@ -110,37 +110,35 @@ def test_contains():
110110 ]:
111111 assert (x in y ) == expected
112112
113- # TODO: Re-enable this if we ever add the ability to hash arbs.
114- # def test_hash():
115- # """`x` and `y` hash to the same value if they have the same midpoint and radius.
116-
117- # Args:
118- # x: An arb.
119- # y: An arb.
120- # expected: Whether `x` and `y` should hash to the same value.
121- # """
122- # def arb_pi(prec):
123- # """Helper to calculate arb to a given precision."""
124- # with ctx.workprec(prec):
125- # return arb.pi()
126- # for x, y, expected in [
127- # (arb(10), arb(10), True),
128- # (arb(10), arb(11), False),
129- # (arb(10.0), arb(10), True),
130- # (
131- # arb(mid=10, rad=2),
132- # arb(mid=10, rad=2),
133- # True,
134- # ),
135- # (
136- # arb(mid=10, rad=2),
137- # arb(mid=10, rad=3),
138- # False,
139- # ),
140- # (arb_pi(100), arb_pi(100), True),
141- # (arb_pi(100), arb_pi(1000), False),
142- # ]:
143- # assert (hash(x) == hash(y)) == expected
113+ def test_hash ():
114+ """`x` and `y` hash to the same value if they have the same midpoint and radius.
115+
116+ Args:
117+ x: An arb.
118+ y: An arb.
119+ expected: Whether `x` and `y` should hash to the same value.
120+ """
121+ def arb_pi (prec ):
122+ """Helper to calculate arb to a given precision."""
123+ with ctx .workprec (prec ):
124+ return arb .pi ()
125+ for x , y , expected in [
126+ (arb (10 ), arb (10 ), True ),
127+ (arb (10 ), arb (11 ), False ),
128+ (arb (10.0 ), arb (10 ), True ),
129+ ]:
130+ assert (hash (x ) == hash (y )) == expected
131+
132+ for x in [
133+ arb (mid = 10 , rad = 2 ),
134+ arb_pi (100 ),
135+ ]:
136+ try :
137+ hash (x )
138+ except ValueError :
139+ pass
140+ else :
141+ assert False , f"Expected { x } to raise an error if hashed, but succeeded."
144142
145143
146144
@@ -338,8 +336,7 @@ def test_no_tests_missing():
338336 test_lower ,
339337 test_upper ,
340338 test_contains ,
341- # TODO: Re-enable this if we ever add the ability to hash arbs.
342- # test_hash,
339+ test_hash ,
343340 test_arb_sub ,
344341 test_arb_add ,
345342 test_arb_mul ,
0 commit comments