-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_shikaku.py
123 lines (106 loc) · 4.05 KB
/
test_shikaku.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Модуль с тестами"""
import unittest
from solver import is_prime
import numpy as np
from solver import return_result_matrix
from parsing import parse_input
from process_str_matrix import process_res_matrix
from get_dict_with_values import get_matrix_with_color
from get_count_solutions import get_count_solutions
class Tests(unittest.TestCase):
def test_for_anytask_1(self):
"""Чтобы запустились тесты на таске"""
self.assertEqual(1, 1)
def test_for_anytask_2(self):
self.assertEqual(2, 2)
def test_prime_number(self):
res = is_prime(5)
self.assertEqual(True, res)
def test_not_prime_number(self):
res = is_prime(10)
self.assertEqual(False, res)
def test_right_solve_1(self):
state = np.array([[2, 0], [2, 0]])
res = str(return_result_matrix(state))
exp = """Result matrix:
[[2 2]
[2 2]]"""
self.assertEqual(exp, res)
def test_right_solve_2(self):
state = np.array([[2, 0, 4, 0, 0, 2, 0], [0, 0, 0, 6, 0, 0, 0], [4, 0, 2, 0, 4, 4, 0], [0, 0, 0, 0, 0, 4, 0],
[0, 0, 4, 0, 2, 0, 0], [0, 2, 0, 0, 0, 0, 2], [0, 0, 0, 4, 3, 0, 0]])
res = str(return_result_matrix(state))
exp = """Result matrix:
[[2 4 4 6 4 2 2]
[2 4 4 6 4 4 4]
[4 2 2 6 4 4 4]
[4 4 4 6 4 4 4]
[4 4 4 6 2 4 4]
[4 2 2 6 2 2 2]
[4 4 4 4 3 3 3]]"""
self.assertEqual(exp, res)
def test_right_solve_3(self):
state = np.array([[2, 0, 0, 0, 0], [2, 2, 0, 0, 0], [0, 0, 0, 0, 9], [4, 0, 0, 4, 0], [0, 0, 2, 0, 0]])
res = str(return_result_matrix(state))
exp = """Result matrix:
[[2 2 9 9 9]
[2 2 9 9 9]
[2 2 9 9 9]
[4 4 2 4 4]
[4 4 2 4 4]]"""
self.assertEqual(exp, res)
def test_right_solve_4(self):
state = np.array([[2, 0, 0, 0, 0], [2, 2, 0, 0, 0], [0, 0, 0, 0, 9]])
res = return_result_matrix(state)
self.assertEqual(None, res)
def test_right_parse_1(self):
data = '2 0 0 0 0 | 2 2 0 0 0 | 0 0 0 0 9 | 4 0 0 4 0 | 0 0 2 0 0'
exp = str([[2, 0, 0, 0, 0], [2, 2, 0, 0, 0], [0, 0, 0, 0, 9], [4, 0, 0, 4, 0], [0, 0, 2, 0, 0]])
res = str(parse_input(data))
self.assertEqual(exp, res)
def test_right_parse_2(self):
data = '2 0 | 2 0'
exp = str([[2, 0], [2, 0]])
res = str(parse_input(data))
self.assertEqual(exp, res)
def test_process_matrix_1(self):
matrix_str = """Result matrix:
[[2 2]
[2 2]]"""
exp = [['2', '2'], ['2', '2']]
res = process_res_matrix(matrix_str)
self.assertEqual(exp, res)
def test_process_matrix_2(self):
matrix_str = """Result matrix:
[[2 2 9 9 9]
[2 2 9 9 9]
[2 2 9 9 9]
[4 4 2 4 4]
[4 4 2 4 4]]"""
exp = [['2', '2', '9', '9', '9'], ['2', '2', '9', '9', '9'], ['2', '2', '9', '9', '9'], ['4', '4', '2', '4', '4'], ['4', '4', '2', '4', '4']]
res = process_res_matrix(matrix_str)
self.assertEqual(exp, res)
def test_get_dict_1(self):
mt = [['2', '2'], ['2', '2']]
exp = {(0, 0): ('2', 'blue'), (0, 1): ('2', 'blue'), (1, 0): ('2', 'coral1'), (1, 1): ('2', 'coral1')}
res = get_matrix_with_color(mt, 1, 2, 2)
self.assertEqual(exp, res)
def test_get_dict21(self):
mt = [['2', '2'], ['2', '2']]
exp = {(0, 0): ('2', 'blue'), (1, 0): ('2', 'blue'), (0, 1): ('2', 'coral1'), (1, 1): ('2', 'coral1')}
res = get_matrix_with_color(mt, 2, 2, 2)
self.assertEqual(exp, res)
def test_get_count_1(self):
raw = [['1', '1', '3'], ['2', '0', '0'], ['0', '2', '0']]
arr = [['1', '1', '3'], ['2', '2', '3'], ['2', '2', '3']]
exp = 2
res = get_count_solutions(arr, raw)
self.assertEqual(exp, res)
def test_get_count_2(self):
raw = [['1', '1', '3'], ['2', '0', '0'], ['2', '0', '0']]
arr = [['1', '1', '3'], ['2', '2', '3'], ['2', '2', '3']]
exp = 1
res = get_count_solutions(arr, raw)
self.assertEqual(exp, res)