Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
636 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding: utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from unittest import TestCase | ||
from six import PY2, PY3 | ||
|
||
|
||
class UTCase(TestCase): | ||
def assertItemsEqual(self, a, b): | ||
if PY2: | ||
return super(UTCase, self).assertItemsEqual(a, b) | ||
|
||
elif PY3: | ||
return self.assertCountEqual(a, b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from link.crdt.test.base import UTCase | ||
from unittest import main | ||
|
||
from link.crdt.counter import Counter | ||
|
||
|
||
class TestCounter(UTCase): | ||
def test_increment(self): | ||
crdt = Counter(value=5) | ||
self.assertEqual(crdt.current, 5) | ||
|
||
crdt.increment() | ||
|
||
self.assertEqual(crdt.current, 6) | ||
self.assertEqual(crdt._increment, 1) | ||
self.assertEqual(crdt._vclock, 1) | ||
self.assertTrue(crdt.isdirty()) | ||
self.assertEqual(crdt.mutation(), {'increment': 1}) | ||
|
||
crdt.decrement() | ||
|
||
self.assertEqual(crdt.current, 5) | ||
self.assertEqual(crdt._increment, 0) | ||
self.assertEqual(crdt._vclock, 2) | ||
self.assertFalse(crdt.isdirty()) | ||
self.assertEqual(crdt.mutation(), {'increment': 0}) | ||
|
||
def test_merge(self): | ||
a = Counter(value=5) | ||
b = Counter(value=5) | ||
|
||
b.increment(3) | ||
b.increment(2) | ||
a.increment(2) | ||
|
||
c = Counter.merge(a, b) | ||
|
||
self.assertEqual(c.current, 12) | ||
self.assertEqual(c._increment, 7) | ||
self.assertEqual(c._vclock, 3) | ||
self.assertTrue(c.isdirty()) | ||
self.assertEqual(c.mutation(), {'increment': 7}) | ||
|
||
def test_fail_merge(self): | ||
a = Counter(value=5) | ||
b = Counter(value=7) | ||
|
||
with self.assertRaises(ValueError): | ||
Counter.merge(a, b) | ||
|
||
def test_fail_type(self): | ||
with self.assertRaises(TypeError): | ||
Counter(value='not int') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.