Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f8ef1c8

Browse files
updated a function in Point and added some tests
1 parent 6836ee9 commit f8ef1c8

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

‎Point.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ def get_state(self):
5050
def print_state(self):
5151
return " " if self.state.name == "E" else self.state.name
5252

53-
@property
54-
def coord(self):
55-
return self._index_to_coord[self.index]
56-
5753
@classmethod
5854
def get_index(cls, coord):
5955
assert (
@@ -66,6 +62,10 @@ def get_coord(cls, index):
6662
assert 0 <= index < 25, "Invalid index: %d" % index
6763
return cls._index_to_coord[index]
6864

65+
@property
66+
def coord(self):
67+
return Point.get_coord(self.index)
68+
6969
def __str__(self):
7070
return self.coord
7171

‎tests.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import unittest
2+
3+
from Point import Point
4+
5+
6+
class TestPoint(unittest.TestCase):
7+
def setUp(self):
8+
self.points = [Point(i) for i in range(25)]
9+
10+
def test_coord(self):
11+
self.assertEqual(self.points[0].coord, 'A1')
12+
self.assertEqual(self.points[12].coord, 'C3')
13+
self.assertEqual(self.points[24].coord, 'E5')
14+
15+
def test_index(self):
16+
self.assertEqual(self.points[0].index, 0)
17+
self.assertEqual(self.points[12].index, 12)
18+
19+
def test_get_index(self):
20+
self.assertEqual(Point.get_index('C3'), 12)
21+
self.assertEqual(Point.get_index('E4'), 19)
22+
23+
def test_set_state(self):
24+
self.points[0].set_state('T')
25+
self.assertEqual(self.points[0].state, Point.State.T)
26+
self.assertEqual(self.points[0].get_state(), Point.State.T)
27+
28+
def test_str(self):
29+
self.assertEqual(str(self.points[0]), 'A1')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /