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_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_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_no_overwrite_on_merge(self): a = OrderedSet() a.add('A') a.add('Z') a.add('B') print(a) crdt1 = GSet() crdt2 = GSet() crdt1.add('A') crdt2.add('B') crdt1 = crdt1.merge(crdt2) print(crdt1._payload) crdt1.add('AA') crdt2.add('BB') crdt1 = crdt1.merge(crdt2) print(crdt1._payload) self.assertEqual(crdt1._payload, ['A', 'B', 'AA', 'BB']) self.assertEqual(crdt2._payload, ['B', 'BB'])
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']))