Skip to content

Commit b5a9cb5

Browse files
committed
Test and fix SquareSet.{issuperset,issubset}() (fixes #838)
1 parent 65bf7ff commit b5a9cb5

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

chess/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,11 +3869,11 @@ def isdisjoint(self, other: IntoSquareSet) -> bool:
38693869

38703870
def issubset(self, other: IntoSquareSet) -> bool:
38713871
"""Tests if this square set is a subset of another."""
3872-
return not bool(~self & other)
3872+
return not bool(self & ~SquareSet(other))
38733873

38743874
def issuperset(self, other: IntoSquareSet) -> bool:
38753875
"""Tests if this square set is a superset of another."""
3876-
return not bool(self & ~SquareSet(other))
3876+
return not bool(~self & other)
38773877

38783878
def union(self, other: IntoSquareSet) -> SquareSet:
38793879
return self | other

test.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,24 +1796,30 @@ def test_arithmetic(self):
17961796
self.assertEqual(bb, chess.BB_C1)
17971797

17981798
def test_immutable_set_operations(self):
1799-
self.assertTrue(chess.SquareSet(chess.BB_RANK_1).isdisjoint(chess.BB_RANK_2))
1800-
self.assertFalse(chess.SquareSet(chess.BB_RANK_2).isdisjoint(chess.BB_FILE_E))
1801-
1802-
self.assertFalse(chess.SquareSet(chess.BB_A1).issubset(chess.BB_RANK_1))
1803-
self.assertTrue(chess.SquareSet(chess.BB_RANK_1).issubset(chess.BB_A1))
1804-
1805-
self.assertTrue(chess.SquareSet(chess.BB_A1).issuperset(chess.BB_RANK_1))
1806-
self.assertFalse(chess.SquareSet(chess.BB_RANK_1).issuperset(chess.BB_A1))
1807-
1808-
self.assertEqual(chess.SquareSet(chess.BB_A1).union(chess.BB_FILE_A), chess.BB_FILE_A)
1809-
1810-
self.assertEqual(chess.SquareSet(chess.BB_A1).intersection(chess.BB_A2), chess.BB_EMPTY)
1811-
1812-
self.assertEqual(chess.SquareSet(chess.BB_A1).difference(chess.BB_A2), chess.BB_A1)
1813-
1814-
self.assertEqual(chess.SquareSet(chess.BB_A1).symmetric_difference(chess.BB_A2), chess.BB_A1 | chess.BB_A2)
1799+
examples = [
1800+
chess.BB_EMPTY,
1801+
chess.BB_A1,
1802+
chess.BB_A2,
1803+
chess.BB_RANK_1,
1804+
chess.BB_RANK_2,
1805+
chess.BB_FILE_A,
1806+
chess.BB_FILE_E,
1807+
]
18151808

1816-
self.assertEqual(chess.SquareSet(chess.BB_C5).copy(), chess.BB_C5)
1809+
for a in examples:
1810+
self.assertEqual(chess.SquareSet(a).copy(), a)
1811+
1812+
for a in examples:
1813+
a = chess.SquareSet(a)
1814+
for b in examples:
1815+
b = chess.SquareSet(b)
1816+
self.assertEqual(set(a).isdisjoint(set(b)), a.isdisjoint(b))
1817+
self.assertEqual(set(a).issubset(set(b)), a.issubset(b))
1818+
self.assertEqual(set(a).issuperset(set(b)), a.issuperset(b))
1819+
self.assertEqual(set(a).union(set(b)), set(a.union(b)))
1820+
self.assertEqual(set(a).intersection(set(b)), set(a.intersection(b)))
1821+
self.assertEqual(set(a).difference(set(b)), set(a.difference(b)))
1822+
self.assertEqual(set(a).symmetric_difference(set(b)), set(a.symmetric_difference(b)))
18171823

18181824
def test_mutable_set_operations(self):
18191825
squares = chess.SquareSet(chess.BB_A1)

0 commit comments

Comments
 (0)