-
Notifications
You must be signed in to change notification settings - Fork 1
/
puzzle-solver-unit-tests.py
71 lines (57 loc) · 3.14 KB
/
puzzle-solver-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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import unittest
from puzzle_functions import find_number, move, measure_mean_std_dev
import numpy as np
class FindNumberTestCase(unittest.TestCase):
def test_number_zero(self):
test_array = [[5,2,7,3],[9,1,15,4],[10,6,8,12],[13,11,14,0]]
zero_location = (3,3)
self.assertEqual(zero_location, find_number(0,test_array))
class Move(unittest.TestCase):
def test_top_row(self):
test_array = [[5,0,7,3],[9,1,15,4],[10,6,8,12],[13,11,14,2]]
self.assertEqual(1, move(test_array,'u'))
def test_move_up(self):
test_array = [[5,2,7,3],[9,1,15,4],[10,6,8,12],[13,11,14,0]]
result_array = [[5,2,7,3],[9,1,15,4],[10,6,8,0],[13,11,14,12]]
self.assertEqual(result_array, move(test_array,'u'))
def test_bottom_row(self):
test_array = [[5,11,7,3],[9,1,15,4],[10,6,8,12],[13,0,14,2]]
self.assertEqual(1, move(test_array,'d'))
def test_move_down(self):
test_array = [[5,2,7,3],[9,1,15,4],[10,6,8,0],[13,11,14,12]]
result_array = [[5,2,7,3],[9,1,15,4],[10,6,8,12],[13,11,14,0]]
self.assertEqual(result_array, move(test_array,'d'))
def test_left_column(self):
test_array = [[5,11,7,3],[9,1,15,4],[10,6,8,12],[0,13,14,2]]
self.assertEqual(1, move(test_array,'l'))
def test_move_left(self):
test_array = [[5,2,7,3],[9,1,15,4],[10,6,8,0],[13,11,14,12]]
result_array = [[5,2,7,3],[9,1,15,4],[10,6,0,8],[13,11,14,12]]
self.assertEqual(result_array, move(test_array,'l'))
def test_right_column(self):
test_array = [[5,11,7,3],[9,1,15,4],[10,6,8,12],[2,13,14,0]]
self.assertEqual(1, move(test_array,'r'))
def test_move_right(self):
test_array = [[5,2,7,3],[9,1,15,4],[10,6,0,8],[13,11,14,12]]
result_array = [[5,2,7,3],[9,1,15,4],[10,6,8,0],[13,11,14,12]]
self.assertEqual(result_array, move(test_array,'r'))
class MeasureStdDev(unittest.TestCase):
def test_solved(self):
result_array = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,0]]
input_array = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,0]]
self.assertEqual(0,measure_mean_std_dev(input_array, result_array)["std_dev"])
def test_one_move_left(self):
result_array = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]]
input_array = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 0, 15]]
self.assertEqual(np.std([0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1]), measure_mean_std_dev(input_array, result_array)["std_dev"])
class MeasureMean(unittest.TestCase):
def test_solved(self):
result_array = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,0]]
input_array = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,0]]
self.assertEqual(0,measure_mean_std_dev(input_array, result_array)["mean"])
def test_one_move_left(self):
result_array = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]]
input_array = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 0, 15]]
self.assertEqual(np.mean([0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1]), measure_mean_std_dev(input_array, result_array)["mean"])
if __name__ == '__main__':
unittest.main()