This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
76 lines (63 loc) · 3.01 KB
/
test.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
import unittest
from DDBFile import DDBFile
from diffupdatematcher import DiffUpdateMatcher
from lcs_function import lcs, lcsr
from diffupdate import main
class TestFunctions(unittest.TestCase):
def test_lcs(self):
self.assertEqual(lcs("abcdef", "abc"), "abc")
self.assertEqual(lcs("a", "b"), "")
self.assertEqual(lcs("a", "a"), "a")
self.assertEqual(lcs("abc", "ac"), "ac")
self.assertEqual(lcs("abcdef", "abc"), "abc")
self.assertEqual(lcs("abcdef", "acf"), "acf")
# self.assertEqual(lcs("anothertest", "notatest"), "test")
# self.assertEqual(lcs("132535365", "123456789"), "12356")
# self.assertEqual(lcs("finaltest", "zzzfinallyzzz"), "final")
def test_lcs2(self):
# self.assertEqual(lcsr("abcdef", "abc"), "abc")
# self.assertEqual(lcsr("a", "b"), "")
# self.assertEqual(lcsr("a", "a"), "a")
# self.assertEqual(lcsr("abc", "ac"), "ac")
# self.assertEqual(lcsr("abcdef", "abc"), "abc")
# self.assertEqual(lcsr("abcdef", "acf"), "acf")
# self.assertEqual(lcsr("anothertest", "notatest"), "test")
# self.assertEqual(lcsr("132535365", "123456789"), "12356")
# self.assertEqual(lcsr("finaltest", "zzzfinallyzzz"), "final")
# lcsr returns length of the longest subsequence not the actual sequence
pass
class DefaultDiffTester(unittest.TestCase):
# algoritm bazat pe insertii si stergeri
def test_create(self):
d = DiffUpdateMatcher()
d.do_diff(b'BDCABA', b'ABCBDAB')
# print(lcs2('BDCABA', 'ABCBDAB'))
self.assertEqual(b'ABCBDAB', d.apply_diff(b'BDCABA'))
d.do_diff(b'', b'')
self.assertEqual(b'', d.apply_diff(b''))
class DBTester(unittest.TestCase):
def test_save(self):
db = DDBFile('test_fixtures/test', ['test_fixtures/a', 'test_fixtures/b', 'test_fixtures/c'])
db.dump()
open('test_fixtures/test.ddb', 'rb').close()
def test_load(self):
db = DDBFile('test_fixtures/test', ['test_fixtures/a', 'test_fixtures/b', 'test_fixtures/c'])
db.dump()
db = DDBFile('test_fixtures/test')
db.update('test_fixtures/b')
with open('test_fixtures/a', 'rb') as f:
self.assertEqual(f.read(), db.updated)
class EndToEndTester(unittest.TestCase):
def test_create_update(self):
main(['diffupdate.py', 'create', 'test_fixtures/abc.latest', 'test_fixtures/abc.ver1', 'test_fixtures/abc.ver2', 'test_fixtures/abc.ver3',
'--name', 'test_fixtures/abc.ddb'])
main(['diffupdate.py', 'update', 'test_fixtures/abc.ver2_2', 'test_fixtures/abc.ddb'])
with open('test_fixtures/abc.ver2_2', 'rb') as f:
with open('test_fixtures/abc.latest', 'rb') as f2:
self.assertEqual(f.read(), f2.read())
with open('test_fixtures/abc.ver2_2', 'wb') as f:
with open('test_fixtures/abc.ver2', 'rb') as f2:
f.write(f2.read())
# talk about files sizes
if __name__ == "__main__":
unittest.main()