summaryrefslogtreecommitdiffstats
path: root/aoc/tests
diff options
context:
space:
mode:
Diffstat (limited to 'aoc/tests')
-rw-r--r--aoc/tests/__init__.py0
-rw-r--r--aoc/tests/test_datastructures.py79
2 files changed, 79 insertions, 0 deletions
diff --git a/aoc/tests/__init__.py b/aoc/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/aoc/tests/__init__.py
diff --git a/aoc/tests/test_datastructures.py b/aoc/tests/test_datastructures.py
new file mode 100644
index 0000000..42cc44d
--- /dev/null
+++ b/aoc/tests/test_datastructures.py
@@ -0,0 +1,79 @@
1# -*- coding: utf-8 -*-
2from aoc.datastructures import Coordinate, Coordinate3
3
4
5class TestCoordinate:
6 def test_addition(self):
7 c1 = Coordinate(1, 1)
8 c2 = Coordinate(2, 2)
9 assert c1 + c2 == Coordinate(3, 3)
10
11 def test_subtraction(self):
12 c1 = Coordinate(2, 2)
13 c2 = Coordinate(1, 1)
14 assert c1 - c2 == Coordinate(1, 1)
15
16 def test_manhattan_distance(self):
17 c1 = Coordinate(1, 1)
18 c2 = Coordinate(3, 3)
19 assert c1.manhattan_distance(c2) == 4
20
21 def test_polarity(self):
22 c1 = Coordinate(2, -3)
23 assert c1.polarity == Coordinate(1, -1)
24
25 def test_neighbours(self):
26 c = Coordinate(0, 0)
27 neighbours = {Coordinate(-1, 0), Coordinate(1, 0), Coordinate(0, -1), Coordinate(0, 1),
28 Coordinate(-1, -1), Coordinate(-1, 1), Coordinate(1, -1), Coordinate(1, 1)}
29 assert set(c.neighbours()) == neighbours
30
31 def test_neighbours_no_diagonal(self):
32 c = Coordinate(0, 0)
33 neighbours_no_diagonal = {Coordinate(-1, 0), Coordinate(1, 0), Coordinate(0, -1), Coordinate(0, 1)}
34 assert set(c.neighbours(no_diagonal=True)) == neighbours_no_diagonal
35
36
37class TestCoordinate3:
38 def test_addition(self):
39 c1 = Coordinate3(1, 1, 1)
40 c2 = Coordinate3(2, 2, 2)
41 assert c1 + c2 == Coordinate3(3, 3, 3)
42
43 def test_subtraction(self):
44 c1 = Coordinate3(2, 2, 2)
45 c2 = Coordinate3(1, 1, 1)
46 assert c1 - c2 == Coordinate3(1, 1, 1)
47
48 def test_manhattan_distance(self):
49 c1 = Coordinate3(1, 1, 1)
50 c2 = Coordinate3(3, 3, 3)
51 assert c1.manhattan_distance(c2) == 6
52
53 def test_polarity(self):
54 c1 = Coordinate3(2, -3, 0)
55 assert c1.polarity == Coordinate3(1, -1, 0)
56
57 def test_neighbours(self):
58 c = Coordinate3(0, 0, 0)
59 neighbours = {
60 Coordinate3(-1, -1, -1), Coordinate3(-1, -1, 0), Coordinate3(-1, -1, 1),
61 Coordinate3(-1, 0, -1), Coordinate3(-1, 0, 0), Coordinate3(-1, 0, 1),
62 Coordinate3(-1, 1, -1), Coordinate3(-1, 1, 0), Coordinate3(-1, 1, 1),
63 Coordinate3(0, -1, -1), Coordinate3(0, -1, 0), Coordinate3(0, -1, 1),
64 Coordinate3(0, 0, -1), Coordinate3(0, 0, 1),
65 Coordinate3(0, 1, -1), Coordinate3(0, 1, 0), Coordinate3(0, 1, 1),
66 Coordinate3(1, -1, -1), Coordinate3(1, -1, 0), Coordinate3(1, -1, 1),
67 Coordinate3(1, 0, -1), Coordinate3(1, 0, 0), Coordinate3(1, 0, 1),
68 Coordinate3(1, 1, -1), Coordinate3(1, 1, 0), Coordinate3(1, 1, 1)
69 }
70 assert set(c.neighbours()) == neighbours
71
72 def test_neighbours_no_diagonal(self):
73 c = Coordinate3(0, 0, 0)
74 neighbours_no_diagonal = {
75 Coordinate3(-1, 0, 0), Coordinate3(1, 0, 0),
76 Coordinate3(0, -1, 0), Coordinate3(0, 1, 0),
77 Coordinate3(0, 0, -1), Coordinate3(0, 0, 1)
78 }
79 assert set(c.neighbours(no_diagonal=True)) == neighbours_no_diagonal