Пример #1
0
 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'])
Пример #2
0
 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')
Пример #3
0
 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'])
Пример #4
0
    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']))
Пример #5
0
    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'])
Пример #6
0
    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))
Пример #7
0
 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']))
Пример #8
0
 def test_adding_to_crdt(self):
     crdt = GSet()
     crdt.add('A')
     self.assertEqual(set(crdt.values()), OrderedSet(['A']))
Пример #9
0
 def test_iterator_type(self):
     crdt = GSet()
     self.assertTrue(
         isinstance(crdt.values(), type(OrderedSet().__iter__())))