示例#1
0
文件: set.py 项目: linkdd/link.crdt
    def test_fail_type(self):
        with self.assertRaises(TypeError):
            not_set = 42
            Set(value=not_set)

        with self.assertRaises(TypeError):
            Set(value={42})
示例#2
0
文件: crdt.py 项目: linkdd/link.riak
def create_set(step, key, *vals):
    s = Set()

    for val in vals:
        if val is not None:
            s.add(val)

    world.store[key] = s
示例#3
0
文件: set.py 项目: linkdd/link.crdt
    def test_merge(self):
        a = Set(value={'1', '2'})
        b = Set(value={'1', '2'})

        b.add('3')
        a.discard('2')

        c = Set.merge(a, b)

        self.assertEqual(c.current, {'1', '3'})
        self.assertEqual(c._adds, {'3'})
        self.assertEqual(c._removes, {'2'})
        self.assertEqual(c._vclock, 2)
        self.assertTrue(c.isdirty())
        self.assertEqual(c.mutation(), {
            'adds': {'3'},
            'removes': {'2'}
        })
示例#4
0
文件: set.py 项目: linkdd/link.crdt
    def test_api(self):
        s = Set(value={'1', '2'})

        self.assertIn('1', s)
        self.assertEqual(len(s), 2)

        s2 = {item for item in s}
        self.assertEqual(s.current, s2)

        with self.assertRaises(TypeError):
            s.add(42)
示例#5
0
    def test_merge_different_types(self):
        c = Counter()
        f = Flag()
        r = Register()
        s = Set()
        m = Map()

        tuples = [(Counter, c, f), (Flag, f, r), (Register, r, s), (Set, s, m),
                  (Map, m, c)]

        for cls, a, b in tuples:
            with self.assertRaises(TypeError):
                cls.merge(a, b)
示例#6
0
文件: set.py 项目: linkdd/link.crdt
    def test_enable(self):
        crdt = Set(value={'1', '2'})

        self.assertEqual(crdt.current, {'1', '2'})

        crdt.add('3')
        crdt.discard('2')

        self.assertEqual(crdt.current, {'1', '3'})
        self.assertEqual(crdt._adds, {'3'})
        self.assertEqual(crdt._removes, {'2'})
        self.assertEqual(crdt._vclock, 2)
        self.assertTrue(crdt.isdirty())
        self.assertEqual(crdt.mutation(), {
            'adds': {'3'},
            'removes': {'2'}
        })
示例#7
0
文件: set.py 项目: linkdd/link.crdt
 def test_default(self):
     crdt = Set()
     self.assertEqual(crdt.current, set())
示例#8
0
文件: set.py 项目: linkdd/link.crdt
    def test_fail_merge(self):
        a = Set(value={'1'})
        b = Set(value={'2'})

        with self.assertRaises(ValueError):
            Set.merge(a, b)