-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
64 lines (55 loc) · 2.68 KB
/
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
from Posn import Posn
from unittest import TestCase
# examples and tests
class Test(TestCase):
# test for Posn
def test_posn(self):
# in_range
self.assertFalse(Posn(1, 10).in_range(5, 5))
self.assertFalse(Posn(10, 1).in_range(5, 5))
self.assertFalse(Posn(10, 10).in_range(5, 5))
self.assertFalse(Posn(-3, 10).in_range(5, 5))
self.assertFalse(Posn(-10, 10).in_range(5, 5))
self.assertFalse(Posn(2, -10).in_range(5, 5))
self.assertFalse(Posn(-5, -5).in_range(5, 5))
self.assertFalse(Posn(5, 5).in_range(5, 5))
self.assertTrue(Posn(1, 1).in_range(5, 5))
self.assertTrue(Posn(1, 3).in_range(5, 5))
self.assertTrue(Posn(3, 1).in_range(5, 5))
self.assertTrue(Posn(0, 0).in_range(5, 5))
self.assertTrue(Posn(0, 4).in_range(5, 5))
self.assertTrue(Posn(4, 0).in_range(5, 5))
self.assertTrue(Posn(4, 4).in_range(5, 5))
# surrounding
self.assertEqual(Posn(0, 0).surrounding(),
[Posn(-1, -1), Posn(-1, 0), Posn(-1, 1),
Posn(0, -1), Posn(0, 1),
Posn(1, -1), Posn(1, 0), Posn(1, 1)])
self.assertEqual(Posn(10, 10).surrounding(),
[Posn(9, 9), Posn(9, 10), Posn(9, 11),
Posn(10, 9), Posn(10, 11),
Posn(11, 9), Posn(11, 10), Posn(11, 11)])
# surrounding_in_range
self.assertEqual(Posn(0, 0).surrounding_in_range(0, 0), [])
self.assertEqual(Posn(0, 0).surrounding_in_range(1, 1), [])
self.assertEqual(Posn(0, 0).surrounding_in_range(2, 2),
[Posn(0, 1), Posn(1, 0), Posn(1, 1)])
self.assertEqual(Posn(10, 10).surrounding_in_range(100, 100),
Posn(10, 10).surrounding())
self.assertEqual(Posn(10, 10).surrounding_in_range(11, 11),
[Posn(9, 9), Posn(9, 10),
Posn(10, 9)])
# equal
self.assertTrue(Posn(10, 10).__eq__(Posn(10, 10)))
self.assertTrue(Posn(3, 3).__eq__(Posn(3, 3)))
self.assertFalse(Posn(0, 0).__eq__(Posn(1, 0)))
self.assertFalse(Posn(0, 0).__eq__(Posn(0, 1)))
self.assertFalse(Posn(0, 0).__eq__(Posn(1, 1)))
self.assertFalse(Posn(0, 0).__eq__(Posn(-1, -1)))
self.assertFalse(Posn(0, 0).__eq__(5))
self.assertFalse(Posn(0, 0).__eq__('hi'))
# str
self.assertEqual(Posn(0, 0).coordinates(), '(0, 0)')
self.assertEqual(Posn(3, 4).coordinates(), '(4, 3)')
self.assertEqual(str(Posn(0, 0)), 'Posn(row = 0, col = 0)')
self.assertEqual(str(Posn(3, 4)), 'Posn(row = 3, col = 4)')