forked from tmalsburg/py-span-task
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_tests.py
executable file
·51 lines (41 loc) · 3.12 KB
/
unit_tests.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
#!/usr/bin/env python
import unittest
from pyspantask import calculate_score
class TestTask(unittest.TestCase):
def test_calculate_score(self):
# Perfect match:
self.assertEqual(calculate_score(["AA", "BB", "CC", "DD"], ["AA", "BB", "CC", "DD"], False, False), 4)
self.assertEqual(calculate_score(["AA", "BB", "CC", "DD"], ["AA", "BB", "CC", "DD"], False, True), 4)
self.assertEqual(calculate_score(["AA", "BB", "CC", "DD"], ["AA", "BB", "CC", "DD"], True, False), 4)
self.assertEqual(calculate_score(["AA", "BB", "CC", "DD"], ["AA", "BB", "CC", "DD"], True, True), 4)
# Order violated:
self.assertEqual(calculate_score(["BB", "AA", "CC", "DD"], ["AA", "BB", "CC", "DD"], False, False), 4)
self.assertEqual(calculate_score(["BB", "AA", "CC", "DD"], ["AA", "BB", "CC", "DD"], False, True), 2)
self.assertEqual(calculate_score(["BB", "AA", "CC", "DD"], ["AA", "BB", "CC", "DD"], True, False), 4)
self.assertEqual(calculate_score(["BB", "AA", "CC", "DD"], ["AA", "BB", "CC", "DD"], True, True), 2)
# Typos:
self.assertEqual(calculate_score(["AA", "BX", "CC", "DD"], ["AA", "BB", "CC", "DD"], False, False), 3)
self.assertEqual(calculate_score(["AA", "BX", "CC", "DD"], ["AA", "BB", "CC", "DD"], False, True), 3)
self.assertEqual(calculate_score(["AA", "BX", "CC", "DD"], ["AA", "BB", "CC", "DD"], True, False), 4)
self.assertEqual(calculate_score(["AA", "BX", "CC", "DD"], ["AA", "BB", "CC", "DD"], True, True), 4)
# Order violated and typos:
self.assertEqual(calculate_score(["BB", "AA", "CC", "DX"], ["AA", "BB", "CC", "DD"], False, False), 3)
self.assertEqual(calculate_score(["BB", "AA", "CC", "DX"], ["AA", "BB", "CC", "DD"], False, True), 1)
self.assertEqual(calculate_score(["BB", "AA", "CC", "DX"], ["AA", "BB", "CC", "DD"], True, False), 4)
self.assertEqual(calculate_score(["BB", "AA", "CC", "DX"], ["AA", "BB", "CC", "DD"], True, True), 2)
# Order violated and typos and too many responses:
self.assertEqual(calculate_score(["XX", "BB", "AA", "CC", "DX"], ["AA", "BB", "CC", "DD"], False, False), 3)
self.assertEqual(calculate_score(["XX", "BB", "AA", "CC", "DX"], ["AA", "BB", "CC", "DD"], False, True), 1)
self.assertEqual(calculate_score(["XX", "BB", "AA", "CC", "DX"], ["AA", "BB", "CC", "DD"], True, False), 4)
self.assertEqual(calculate_score(["XX", "BB", "AA", "CC", "DX"], ["AA", "BB", "CC", "DD"], True, True), 2)
# Corner case: empty lists
self.assertEqual(calculate_score([], ["AA", "BB", "CC", "DD"], False, False), 0)
self.assertEqual(calculate_score([], ["AA", "BB", "CC", "DD"], False, False), 0)
self.assertEqual(calculate_score([], ["AA", "BB", "CC", "DD"], False, True), 0)
self.assertEqual(calculate_score([], ["AA", "BB", "CC", "DD"], True, False), 0)
self.assertEqual(calculate_score(["AA", "BB", "CC", "DD"], [], True, True), 0)
self.assertEqual(calculate_score(["AA", "BB", "CC", "DD"], [], False, True), 0)
self.assertEqual(calculate_score(["AA", "BB", "CC", "DD"], [], True, False), 0)
self.assertEqual(calculate_score(["AA", "BB", "CC", "DD"], [], True, True), 0)
if __name__ == '__main__':
unittest.main()