Skip to content

Commit 2b922f0

Browse files
mrcfpscmccandless
authored andcommitted
pov: update tests to v1.2.0 (exercism#1339)
* pov: update tests to v1.2.0 * Move utility `assertTreeEquals` to right place * pov: apply 'snake_case' naming style
1 parent f383bbe commit 2b922f0

3 files changed

Lines changed: 24 additions & 23 deletions

File tree

exercises/pov/example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def remove(self, node):
4141
tree.children.append(child.remove(node))
4242
return tree
4343

44-
def fromPov(self, from_node):
44+
def from_pov(self, from_node):
4545
stack = [self]
4646
visited = set()
4747
while stack:
@@ -55,8 +55,8 @@ def fromPov(self, from_node):
5555
stack.append(child.add(tree.remove(child.label)))
5656
raise ValueError("Tree could not be reoriented")
5757

58-
def pathTo(self, from_node, to_node):
59-
reordered = self.fromPov(from_node)
58+
def path_to(self, from_node, to_node):
59+
reordered = self.from_pov(from_node)
6060
stack = reordered.children
6161
path = [from_node]
6262
while path[-1] != to_node:

exercises/pov/pov.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def __lt__(self, other):
1818
def __eq__(self, other):
1919
return self.__dict__() == other.__dict__()
2020

21-
def fromPov(self, from_node):
21+
def from_pov(self, from_node):
2222
pass
2323

24-
def pathTo(self, from_node, to_node):
24+
def path_to(self, from_node, to_node):
2525
pass

exercises/pov/pov_test.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
from pov import Tree
44

55

6-
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.1
6+
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0
77

88
class PovTest(unittest.TestCase):
9-
def assertTreeEquals(self, result, expected):
10-
self.assertEqual(result, expected,
11-
'{} != {}'.format(result, expected))
129

1310
def test_singleton_returns_same_tree(self):
1411
tree = Tree('x')
15-
self.assertTreeEquals(tree.fromPov('x'), tree)
12+
self.assertTreeEquals(tree.from_pov('x'), tree)
1613

1714
def test_can_reroot_tree_with_parent_and_one_sibling(self):
1815
tree = Tree('parent', [
@@ -24,7 +21,7 @@ def test_can_reroot_tree_with_parent_and_one_sibling(self):
2421
Tree('sibling')
2522
])
2623
])
27-
self.assertTreeEquals(tree.fromPov('x'), expected)
24+
self.assertTreeEquals(tree.from_pov('x'), expected)
2825

2926
def test_can_reroot_tree_with_parent_and_many_siblings(self):
3027
tree = Tree('parent', [
@@ -40,7 +37,7 @@ def test_can_reroot_tree_with_parent_and_many_siblings(self):
4037
Tree('c')
4138
])
4239
])
43-
self.assertTreeEquals(tree.fromPov('x'), expected)
40+
self.assertTreeEquals(tree.from_pov('x'), expected)
4441

4542
def test_can_reroot_a_tree_with_new_root_deeply_nested(self):
4643
tree = Tree('level-0', [
@@ -61,7 +58,7 @@ def test_can_reroot_a_tree_with_new_root_deeply_nested(self):
6158
])
6259
])
6360
])
64-
self.assertTreeEquals(tree.fromPov('x'), expected)
61+
self.assertTreeEquals(tree.from_pov('x'), expected)
6562

6663
def test_moves_children_of_new_root_to_same_level_as_former_parent(self):
6764
tree = Tree('parent', [
@@ -75,7 +72,7 @@ def test_moves_children_of_new_root_to_same_level_as_former_parent(self):
7572
Tree('kid-0'),
7673
Tree('kid-1')
7774
])
78-
self.assertTreeEquals(tree.fromPov('x'), expected)
75+
self.assertTreeEquals(tree.from_pov('x'), expected)
7976

8077
def test_can_reroot_complex_tree_with_cousins(self):
8178
tree = Tree('grandparent', [
@@ -106,12 +103,12 @@ def test_can_reroot_complex_tree_with_cousins(self):
106103
])
107104
])
108105
])
109-
self.assertTreeEquals(tree.fromPov('x'), expected)
106+
self.assertTreeEquals(tree.from_pov('x'), expected)
110107

111108
def test_errors_if_target_does_not_exist_in_singleton_tree(self):
112109
tree = Tree('x')
113110
with self.assertRaisesWithMessage(ValueError):
114-
tree.fromPov('nonexistent')
111+
tree.from_pov('nonexistent')
115112

116113
def test_errors_if_target_does_not_exist_in_large_tree(self):
117114
tree = Tree('parent', [
@@ -123,15 +120,15 @@ def test_errors_if_target_does_not_exist_in_large_tree(self):
123120
Tree('sibling-1')
124121
])
125122
with self.assertRaisesWithMessage(ValueError):
126-
tree.fromPov('nonexistent')
123+
tree.from_pov('nonexistent')
127124

128125
def test_find_path_between_two_nodes(self):
129126
tree = Tree('parent', [
130127
Tree('x'),
131128
Tree('sibling')
132129
])
133130
expected = ['x', 'parent']
134-
self.assertEqual(tree.pathTo('x', 'parent'), expected)
131+
self.assertEqual(tree.path_to('x', 'parent'), expected)
135132

136133
def test_can_find_path_to_sibling(self):
137134
tree = Tree('parent', [
@@ -141,7 +138,7 @@ def test_can_find_path_to_sibling(self):
141138
Tree('c')
142139
])
143140
expected = ['x', 'parent', 'b']
144-
self.assertEqual(tree.pathTo('x', 'b'), expected)
141+
self.assertEqual(tree.path_to('x', 'b'), expected)
145142

146143
def test_can_find_path_to_cousin(self):
147144
tree = Tree('grandparent', [
@@ -159,7 +156,7 @@ def test_can_find_path_to_cousin(self):
159156
])
160157
])
161158
expected = ['x', 'parent', 'grandparent', 'uncle', 'cousin-1']
162-
self.assertEqual(tree.pathTo('x', 'cousin-1'), expected)
159+
self.assertEqual(tree.path_to('x', 'cousin-1'), expected)
163160

164161
def test_can_find_path_from_nodes_other_than_x(self):
165162
tree = Tree('parent', [
@@ -169,7 +166,7 @@ def test_can_find_path_from_nodes_other_than_x(self):
169166
Tree('c')
170167
])
171168
expected = ['a', 'parent', 'c']
172-
self.assertEqual(tree.pathTo('a', 'c'), expected)
169+
self.assertEqual(tree.path_to('a', 'c'), expected)
173170

174171
def test_errors_if_destination_does_not_exist(self):
175172
tree = Tree('parent', [
@@ -181,7 +178,7 @@ def test_errors_if_destination_does_not_exist(self):
181178
Tree('sibling-1')
182179
])
183180
with self.assertRaisesWithMessage(ValueError):
184-
tree.pathTo('x', 'nonexistent')
181+
tree.path_to('x', 'nonexistent')
185182

186183
def test_errors_if_source_does_not_exist(self):
187184
tree = Tree('parent', [
@@ -193,7 +190,7 @@ def test_errors_if_source_does_not_exist(self):
193190
Tree('sibling-1')
194191
])
195192
with self.assertRaisesWithMessage(ValueError):
196-
tree.pathTo('nonexistent', 'x')
193+
tree.path_to('nonexistent', 'x')
197194

198195
# Utility functions
199196
def setUp(self):
@@ -205,6 +202,10 @@ def setUp(self):
205202
def assertRaisesWithMessage(self, exception):
206203
return self.assertRaisesRegex(exception, r".+")
207204

205+
def assertTreeEquals(self, result, expected):
206+
self.assertEqual(result, expected,
207+
'{} != {}'.format(result, expected))
208+
208209

209210
if __name__ == '__main__':
210211
unittest.main()

0 commit comments

Comments
 (0)