Skip to content

Commit

Permalink
Add commutative property tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ldeluigi committed Jan 31, 2023
1 parent 7b9bab6 commit 6b6b471
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions backend/spellbook/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from spellbook.variants.list_utils import rotate, all_rotations, merge_sort_unique
from spellbook.variants.variant_trie import VariantTrie

def list_of_tuples_of_lists_to_set(l : list[tuple[list]]) -> set[tuple[tuple]]:
return set([tuple([tuple(x) for x in y]) for y in l])

class ListUtilsTests(TestCase):

def test_rotate(self):
Expand Down Expand Up @@ -80,7 +83,9 @@ def test_variant_trie_or(self):
trie2.add([1, 2, 3, 4, 5], [1])

trie3 = trie | trie2
self.assertEqual(trie3.variants(), [([1, 2, 3, 4], [1, 2, 3]), ([1, 2, 3, 4, 5], [1]), ([1, 2, 3], [1, 2, 3, 4])])
self.assertEqual(trie3.variants(True), [([1, 2, 3, 4], [1, 2, 3]), ([1, 2, 3, 4, 5], [1]), ([1, 2, 3], [1, 2, 3, 4])])
trie4 = trie2 | trie
self.assertSetEqual(list_of_tuples_of_lists_to_set(trie3.variants(True)), list_of_tuples_of_lists_to_set(trie4.variants(True)))

def test_variant_trie_and(self):
trie = VariantTrie()
Expand All @@ -91,4 +96,6 @@ def test_variant_trie_and(self):
trie2.add([1, 2, 3, 4, 5], [1])

trie3 = trie & trie2
self.assertEqual(trie3.variants(), [([1, 2, 3, 4], [1, 2, 3, 4]), ([1, 2, 3, 4, 5], [1, 2])])
self.assertEqual(trie3.variants(True), [([1, 2, 3, 4], [1, 2, 3, 4]), ([1, 2, 3, 4, 5], [1, 2])])
trie4 = trie2 & trie
self.assertSetEqual(list_of_tuples_of_lists_to_set(trie3.variants(True)), list_of_tuples_of_lists_to_set(trie4.variants(True)))

0 comments on commit 6b6b471

Please sign in to comment.