-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlcs_test.py
35 lines (28 loc) · 930 Bytes
/
lcs_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
import rene
import sys
import unittest
from importlib.util import module_from_spec, spec_from_loader
def new_module(code, name):
module = module_from_spec(spec_from_loader(name, loader=None))
exec(code, module.__dict__)
sys.modules[name] = module
return module
class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
code = rene.generate_code(source_file="lcs.rene")
cls.lcs = new_module(code, "lcs").lcs
def test_strings(self):
""" test strings """
x = "asd"
y = "affd"
actual = Test.lcs(len(x), len(y), x, y)
self.assertEqual(actual, 2, f"x={x} ; y={y}")
def test_lists(self):
""" test lists """
x = [1, 4, 5, 1, 2]
y = [4, 1, 3, 2, 1, 5]
actual = Test.lcs(len(x), len(y), x, y)
self.assertEqual(actual, 3, f"x={x} ; y={y}")
if __name__ == "__main__":
unittest.main(verbosity=1)