def test_merge_same_set(self): crdt1 = GSet() crdt2 = GSet() crdt1.add('A') crdt2.add('A') crdt1 = crdt1.merge(crdt2) self.assertEqual(list(crdt1.values()), ['A'])
def test_iterator_functionality(self): crdt = GSet() crdt.add('A') crdt.add('B') iterator = crdt.values() self.assertEqual(next(iterator), 'A') self.assertEqual(next(iterator), 'B')
def test_merge(self): crdt1 = GSet() crdt2 = GSet() crdt1.add('A') crdt2.add('B') crdt2.add('C') crdt1 = crdt1.merge(crdt2) self.assertEqual(list(crdt1.values()), ['A', 'B', 'C'])
def test_no_removal(self): crdt = GSet() crdt.add('A') try: crdt.discard('A') except NotImplementedError as error: s = str(error) self.assertEqual(s, "This is a grow-only set") self.assertEqual(set(crdt.values()), set(['A']))
def test_merge_four_sets(self): crdt1 = GSet() crdt2 = GSet() crdt3 = GSet() crdt4 = GSet() crdt1.add('A') crdt2.add('B') crdt3.add('C') crdt4.add('D') crdt1 = crdt1.merge(crdt2) crdt1 = crdt1.merge(crdt3) crdt1 = crdt1.merge(crdt4) self.assertEqual(list(crdt1.values()), ['A', 'B', 'C', 'D'])
def test_only_unique_items(self): crdt = GSet() crdt.add(1) crdt.add('A') # crdt.add('A') crdt.add(1) # crdt.add('A') obj = {"hello": 'ABC'} crdt.add(json.dumps(obj)) crdt.add(json.dumps(obj)) crdt.add(json.dumps({"hello": 'ABCD'})) expectedResult = [ 'A', 1, json.dumps({"hello": 'ABC'}), json.dumps({"hello": 'ABCD'}) ] self.assertEqual(set(crdt.values()), set(expectedResult))
def test_adding_multiple(self): crdt = GSet() crdt.add('A') crdt.add('B') crdt.add('C') self.assertEqual(set(crdt.values()), OrderedSet(['A', 'B', 'C']))
def test_adding_to_crdt(self): crdt = GSet() crdt.add('A') self.assertEqual(set(crdt.values()), OrderedSet(['A']))
def test_iterator_type(self): crdt = GSet() self.assertTrue( isinstance(crdt.values(), type(OrderedSet().__iter__())))