-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_board.py
87 lines (78 loc) · 3.14 KB
/
test_board.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
from unittest import TestCase
from nose.tools import *
from Board import Board
class TestBoard(TestCase):
def test___init__(self):
with self.assertRaises(ValueError):
Board(-1, 0)
with self.assertRaises(ValueError):
Board(0, 0)
with self.assertRaises(ValueError):
Board(0, 1)
with self.assertRaises(ValueError):
Board(1, 0)
b = Board(1, 1)
assert_equal(b._mapa, [[-2]])
b = Board(2, 2)
assert_equal(b._mapa, [[-2, -2], [-2, -2]])
b = Board(2, 1)
assert_equal(b.height, 1)
assert_equal(b.width, 2)
assert_equal(b._mapa, [[-2, -2]])
b = Board(1, 2)
assert_equal(b._mapa, [[-2], [-2]])
assert_equal(b.height, 2)
assert_equal(b.width, 1)
assert_equal(b.state, 'empty')
def test_print(self):
b = Board(1, 1)
assert_equal(b.print(), "---\n| |\n---")
b = Board(1, 2)
assert_equal(b.print(), "---\n| |\n| |\n---")
b = Board(2, 1)
assert_equal(b.print(), "-----\n| | |\n-----")
b = Board(9, 1)
b._mapa = [[-2, -1, 100, 1, 2, 3, 4, 5, 6]]
assert_equal(b.print(), "-------------------\n| |x|!|1|2|3|4|5|6|\n-------------------")
def test_clear(self):
b = Board(5, 2)
b._mapa = [[-2, -1, 100, 1, 2], [1, 1, 1, 1, 1]]
b.clear()
assert_equal(b._mapa, [[-2, -2, -2, -2, -2], [-2, -2, -2, -2, -2]])
def test_set_bombs(self):
b = Board(5, 2)
b.set_bombs(0)
assert_equal(b._mapa, [[-2, -2, -2, -2, -2], [-2, -2, -2, -2, -2]])
assert_equal(b.state, 'armed')
b.set_bombs(1)
assert_equal(b._mapa, [[-1, -1, -1, -1, -1], [-1, -1, -1, -1, -1]])
assert_equal(b.state, 'armed')
def test_safe_print(self):
b = Board(1, 1)
assert_equal(b.safe_print(), "---\n| |\n---")
b = Board(1, 2)
assert_equal(b.safe_print(), "---\n| |\n| |\n---")
b = Board(2, 1)
assert_equal(b.safe_print(), "-----\n| | |\n-----")
b = Board(9, 1)
b._mapa = [[-2, -1, 100, 1, 2, 3, 4, 5, 6]]
assert_equal(b.safe_print(), "-------------------\n| | |!|1|2|3|4|5|6|\n-------------------")
def test_is_on_board(self):
b = Board(2, 5)
assert_equal(b.is_on_board(3, 1), False)
assert_equal(b.is_on_board(1, 1), True)
assert_equal(b.is_on_board(-1, 0), False)
assert_equal(b.is_on_board(0, -1), False)
assert_equal(b.is_on_board(-1, -1), False)
assert_equal(b.is_on_board(2, 5), False)
assert_equal(b.is_on_board(1, 4), True)
assert_equal(b.is_on_board(1, 5), False)
assert_equal(b.is_on_board(2, 4), False)
def test_change_value_on_board(self):
b = Board(5, 2)
b._mapa = [[-2, -1, 100, 1, 2], [1, 1, 1, 1, 1]]
b.change_value_on_board(row=1,column=0, value=100)
assert_equal(b._mapa, [[-2, -1, 100, 1, 2], [100, 1, 1, 1, 1]])
b._mapa = [[-2, -1, 100, 1, 2], [1, 1, 1, 1, 1]]
b.change_value_on_board(row=1,column=4, value=100)
assert_equal(b._mapa, [[-2, -1, 100, 1, 2], [1, 1, 1, 1, 100]])