-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_core.py
118 lines (88 loc) · 3.46 KB
/
test_core.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import unittest
from py_matching_pattern import PatternMatchStore, KeyNotFound
class CoreTest(unittest.TestCase):
def test_basic(self):
mm = PatternMatchStore(keysize=3)
_=mm.default
mm.put(keys=["a","b","c"],value=1)
mm.put(keys=["a","b","b"],value=2)
mm.put(keys=["a","b",_],value=3)
mm.put(keys=["a",_,_],value=4)
mm.put(keys=["a",None,"c"],value=5)
mm.commit()
self.assertEqual(1,mm.get(keys=["a","b","c"]))
self.assertEqual(2,mm.get(keys=["a","b","b"]))
self.assertEqual(3,mm.get(keys=["a","b","d"]))
self.assertEqual(4,mm.get(keys=["a","c","d"]))
self.assertEqual(5,mm.get(keys=["a",None,"c"]))
def test_break_out_of_loop(self):
mm = PatternMatchStore(keysize=3)
_=mm.default
mm.put(keys=["a","b","c"],value=1)
mm.put(keys=["a","b","b"],value=2)
mm.put(keys=["a","b",_],value=3)
#mm.put(keys=["a",_,_],value=4)
mm.commit()
self.assertEqual(None,mm.get(keys=["a","c","d"]))
def test_back_and_forth(self):
mm = PatternMatchStore(keysize=3)
_=mm.default
mm.put(keys=["a","b","c"],value=1)
mm.put(keys=["a","b","b"],value=2)
mm.put(keys=["a","b",_],value=3)
mm.put(keys=["a",_,"d"],value=4)
mm.put(keys=["a",_,_],value=5)
mm.put(keys=[_,_,"d"],value=6)
mm.commit()
self.assertEqual(1,mm.get(keys=["a","b","c"]))
self.assertEqual(2,mm.get(keys=["a","b","b"]))
self.assertEqual(3,mm.get(keys=["a","b","d"]))
self.assertEqual(4,mm.get(keys=["a","c","d"]))
self.assertEqual(5,mm.get(keys=["a","c","e"]))
self.assertEqual(4,mm.get(keys=["a","d","d"]))
self.assertEqual(5,mm.get(keys=["a","d","e"]))
self.assertEqual(6,mm.get(keys=["d","d","d"]))
self.assertEqual(None,mm.get(keys=["d","d","e"]))
def test_basic_unordered(self):
mm = PatternMatchStore(keysize=3)
d=mm.default
mm.put(keys=["a","b",d],value=3)
mm.put(keys=["a",'b',"b"],value=2)
mm.put(keys=["a",d,d],value=4)
mm.put(keys=["a","b","c"],value=1)
mm.commit()
self.assertEqual(1,mm.get(keys=["a","b","c"]))
self.assertEqual(2,mm.get(keys=["a","b","b"]))
self.assertEqual(3,mm.get(keys=["a","b","d"]))
self.assertEqual(4,mm.get(keys=["a","c","d"]))
def test_basic_clean(self):
mm = PatternMatchStore(keysize=3,raise_notfound=True)
mm.put(keys=["a","b","c"],value=1)
mm.commit()
self.assertEqual(1,mm.get(keys=["a","b","c"]))
mm.clean()
mm.commit()
with self.assertRaises(KeyNotFound):
mm.get(keys=["a","b","c"])
def test_uncommited(self):
mm = PatternMatchStore(keysize=3,raise_notfound=True)
mm.put(keys=["a","b","c"],value=1)
with self.assertRaises(KeyNotFound):
mm.get(keys=["a","b","c"])
def test_uncommited_clean(self):
mm = PatternMatchStore(keysize=3)
mm.put(keys=["a","b","c"],value=1)
mm.commit()
self.assertEqual(1,mm.get(keys=["a","b","c"]))
mm.clean()
self.assertEqual(1,mm.get(keys=["a","b","c"]))
def test_validate_all_leaf_have_default(self):
pass
def test_validate_conflicts(self):
pass
def test_invalid_keycount(self):
pass
def test_invalid_keysize(self):
pass
def test_value_not_found(self):
pass