Skip to content

Commit d886d5d

Browse files
Add missing tests
1 parent 454f6ed commit d886d5d

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

cons/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def cons_merge(cls, car_part, cdr_part):
122122
return chain((car_part,), cdr_part)
123123

124124
def __hash__(self):
125-
return hash([self.car, self.cdr])
125+
return hash((self.car, self.cdr))
126126

127127
def __eq__(self, other):
128128
return (

tests/test_cons.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22

3-
from functools import reduce
43
from itertools import chain, cycle
54
from collections import OrderedDict, UserList
65
from collections.abc import Iterator
@@ -11,14 +10,6 @@
1110
from cons.core import ConsPair, MaybeCons, ConsNull, ConsError, NonCons
1211

1312

14-
def assert_all_equal(*tests):
15-
def _equal(x, y):
16-
assert x, y
17-
return y
18-
19-
reduce(_equal, tests)
20-
21-
2213
def test_noncons_type():
2314

2415
with pytest.raises(TypeError):
@@ -83,8 +74,7 @@ def test_cons_join():
8374
cons("a")
8475

8576
assert cons(1, 2, 3, 4) == cons(1, cons(2, cons(3, 4)))
86-
87-
assert_all_equal(cons("a", None), cons("a", []), ["a"])
77+
assert cons("a", None) == cons("a", []) == ["a"]
8878
assert cons("a", ()) == ("a",)
8979
assert cons("a", []) == ["a"]
9080
assert cons(None, "a").car is None
@@ -124,7 +114,9 @@ def __add__(self, a):
124114
assert cons(1, CustomList([2, 3])) is clist_res
125115

126116

127-
def test_cons_str():
117+
def test_cons_class():
118+
c = cons(1, 2)
119+
assert {c: 1}[c] == 1
128120
assert repr(cons(1, 2)) == "ConsPair(1, 2)"
129121
assert str(cons(1, 2, 3)) == "(1 . (2 . 3))"
130122

@@ -257,6 +249,10 @@ def test_unification():
257249
assert res[car_lv] == 1
258250
assert list(res[cdr_lv]) == []
259251

252+
res = unify(cons(car_lv, cdr_lv), iter([1]), {})
253+
assert res[car_lv] == 1
254+
assert list(res[cdr_lv]) == []
255+
260256
res = unify(OrderedDict([("a", 1), ("b", 2)]), cons(car_lv, cdr_lv), {})
261257
assert res[car_lv] == ("a", 1)
262258
assert res[cdr_lv] == [("b", 2)]

0 commit comments

Comments
 (0)