Skip to content

Commit 677fb31

Browse files
committed
tests/float: Add tests for hashing float and complex numbers.
1 parent 19f2e47 commit 677fb31

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/float/builtin_float_hash.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# test builtin hash function with float args
2+
3+
# these should hash to an integer with a specific value
4+
for val in (
5+
'0.0',
6+
'1.0',
7+
'2.0',
8+
'-12.0',
9+
'12345.0',
10+
):
11+
print(val, hash(float(val)))
12+
13+
# just check that these values are hashable
14+
for val in (
15+
'0.1',
16+
'-0.1',
17+
'10.3',
18+
'inf',
19+
'-inf',
20+
'nan',
21+
):
22+
print(val, type(hash(float(val))))

tests/float/complex1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
print(abs(1j))
4242
print("%.5g" % abs(1j + 2))
4343

44+
# builtin hash
45+
print(hash(1 + 0j))
46+
print(type(hash(1j)))
47+
4448
# float on lhs should delegate to complex
4549
print(1.2 + 3j)
4650

0 commit comments

Comments
 (0)