test_pawn_brotherhood   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 54
dl 0
loc 88
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Tests.test_Extra() 0 3 2
A Tests.test_Edge() 0 3 2
A Tests.test_Basics() 0 3 2
1
import unittest
2
3
from pawn_brotherhood import safe_pawns
4
5
6
class Tests(unittest.TestCase):
7
    TESTS = {
8
        "Basics": [
9
            {
10
                "input": ["b4", "d4", "f4", "c3", "e3", "g5", "d2"],
11
                "answer": 6,
12
                "explanation": ["d2"],
13
            },
14
            {
15
                "input": ["b4", "c4", "d4", "e4", "f4", "g4", "e5"],
16
                "answer": 1,
17
                "explanation": ["b4", "c4", "d4", "e4", "f4", "g4"],
18
            },
19
        ],
20
        "Edge": [
21
            {"input": ["e4"], "answer": 0, "explanation": ["e4"]},
22
            {"input": ["e8"], "answer": 0, "explanation": ["e8"]},
23
            {
24
                "input": ["a1", "b2", "c3", "d4", "e5", "f6", "g7", "h8"],
25
                "answer": 7,
26
                "explanation": ["a1"],
27
            },
28
            {
29
                "input": ["a8", "b7", "c6", "d5", "e4", "f3", "g2", "h1"],
30
                "answer": 7,
31
                "explanation": ["h1"],
32
            },
33
            {
34
                "input": ["a1", "b2", "c3", "d4", "e5", "f6", "g7", "h8"],
35
                "answer": 7,
36
                "explanation": ["a1"],
37
            },
38
            {
39
                "input": ["a2", "b2", "c2", "d2", "e2", "f2", "g2", "h2"],
40
                "answer": 0,
41
                "explanation": ["a2", "b2", "c2", "d2", "e2", "f2", "g2", "h2"],
42
            },
43
            {
44
                "input": ["a1", "a2", "a3", "a4", "h1", "h2", "h3", "h4"],
45
                "answer": 0,
46
                "explanation": ["a1", "a2", "a3", "a4", "h1", "h2", "h3", "h4"],
47
            },
48
        ],
49
        "Extra": [
50
            {
51
                "input": ["b4", "c4", "d4", "e4", "f4", "g4", "e3"],
52
                "answer": 2,
53
                "explanation": ["b4", "c4", "e4", "g4", "e3"],
54
            },
55
            {
56
                "input": ["e7", "e6", "d5", "f5", "c4", "e4", "g4", "e8"],
57
                "answer": 3,
58
                "explanation": ["e8", "e7", "c4", "e4", "g4"],
59
            },
60
            {
61
                "input": ["a2", "b4", "c6", "d8", "e1", "f3", "g5", "h8"],
62
                "answer": 0,
63
                "explanation": ["a2", "b4", "c6", "d8", "e1", "f3", "g5", "h8"],
64
            },
65
            {
66
                "input": ["b6", "a7", "b8", "c7", "g1", "f2", "h2", "g3"],
67
                "answer": 6,
68
                "explanation": ["b6", "g1"],
69
            },
70
        ],
71
    }
72
73
    def test_Basics(self):
74
        for i in self.TESTS['Basics']:
75
            assert safe_pawns(i['input']) == i['answer'], i['input']
76
77
    def test_Edge(self):
78
        for i in self.TESTS['Edge']:
79
            assert safe_pawns(i['input']) == i['answer'], i['input']
80
81
    def test_Extra(self):
82
        for i in self.TESTS['Extra']:
83
            assert safe_pawns(i['input']) == i['answer'], i['input']
84
85
86
if __name__ == "__main__":  # pragma: no cover
87
    unittest.main()
88