Passed
Push — master ( d0203a...db8646 )
by Ken M.
01:09
created

test_colder_warmer.Tests.test_Basics()   A

Complexity

Conditions 2

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
import unittest
2
from math import hypot
3
4
from colder_warmer import checkio
5
6
7
MAX_STEP = 12
8
9
10 View Code Duplication
def check_solution(func, goal, start):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
    prev_steps = [start]
12
    for step in range(MAX_STEP):
13
        row, col = func([s[:] for s in prev_steps])
14
        if [row, col] == goal:
15
            return True
16
        if 10 <= row or 0 > row or 10 <= col or 0 > col:
17
            print("You gave wrong coordinates.")
18
            return False
19
        prev_distance = hypot(prev_steps[-1][0] - goal[0], prev_steps[-1][1] - goal[1])
20
        distance = hypot(row - goal[0], col - goal[1])
21
        alteration = (
22
            0 if prev_distance == distance else (1 if prev_distance > distance else -1)
23
        )
24
        prev_steps.append([row, col, alteration])
25
    print("Too many steps")
26
    return False
27
28
29
class Tests(unittest.TestCase):
30
    TESTS = {
31
        "1st": {"input": [[5, 5, 0]], "goal": [7, 7]},
32
        "2nd": {"input": [[0, 0, 0]], "goal": [5, 6]},
33
        "3rd": {"input": [[0, 0, 0]], "goal": [9, 9]},
34
        "4th": {"input": [[7, 7, 0]], "goal": [2, 4]},
35
        "5th": {"input": [[0, 9, 0]], "goal": [9, 0]},
36
    }
37
38
    def test_Basics(self):
39
        for i in self.TESTS:
40
            assert check_solution(
41
                checkio, self.TESTS[i]['goal'], self.TESTS[i]['input'][0]
42
            )
43
44
45
if __name__ == "__main__":  # pragma: no cover
46
    unittest.main()
47