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.py112
2 files changed, 112 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..1c291cc
--- /dev/null
+++ b/aoc/tests/test_datastructures.py
@@ -0,0 +1,112 @@
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 = {
28 Coordinate(-1, 0),
29 Coordinate(1, 0),
30 Coordinate(0, -1),
31 Coordinate(0, 1),
32 Coordinate(-1, -1),
33 Coordinate(-1, 1),
34 Coordinate(1, -1),
35 Coordinate(1, 1),
36 }
37 assert set(c.neighbours()) == neighbours
38
39 def test_neighbours_no_diagonal(self):
40 c = Coordinate(0, 0)
41 neighbours_no_diagonal = {
42 Coordinate(-1, 0),
43 Coordinate(1, 0),
44 Coordinate(0, -1),
45 Coordinate(0, 1),
46 }
47 assert set(c.neighbours(no_diagonal=True)) == neighbours_no_diagonal
48
49
50class TestCoordinate3:
51 def test_addition(self):
52 c1 = Coordinate3(1, 1, 1)
53 c2 = Coordinate3(2, 2, 2)
54 assert c1 + c2 == Coordinate3(3, 3, 3)
55
56 def test_subtraction(self):
57 c1 = Coordinate3(2, 2, 2)
58 c2 = Coordinate3(1, 1, 1)
59 assert c1 - c2 == Coordinate3(1, 1, 1)
60
61 def test_manhattan_distance(self):
62 c1 = Coordinate3(1, 1, 1)
63 c2 = Coordinate3(3, 3, 3)
64 assert c1.manhattan_distance(c2) == 6
65
66 def test_polarity(self):
67 c1 = Coordinate3(2, -3, 0)
68 assert c1.polarity == Coordinate3(1, -1, 0)
69
70 def test_neighbours(self):
71 c = Coordinate3(0, 0, 0)
72 neighbours = {
73 Coordinate3(-1, -1, -1),
74 Coordinate3(-1, -1, 0),
75 Coordinate3(-1, -1, 1),
76 Coordinate3(-1, 0, -1),
77 Coordinate3(-1, 0, 0),
78 Coordinate3(-1, 0, 1),
79 Coordinate3(-1, 1, -1),
80 Coordinate3(-1, 1, 0),
81 Coordinate3(-1, 1, 1),
82 Coordinate3(0, -1, -1),
83 Coordinate3(0, -1, 0),
84 Coordinate3(0, -1, 1),
85 Coordinate3(0, 0, -1),
86 Coordinate3(0, 0, 1),
87 Coordinate3(0, 1, -1),
88 Coordinate3(0, 1, 0),
89 Coordinate3(0, 1, 1),
90 Coordinate3(1, -1, -1),
91 Coordinate3(1, -1, 0),
92 Coordinate3(1, -1, 1),
93 Coordinate3(1, 0, -1),
94 Coordinate3(1, 0, 0),
95 Coordinate3(1, 0, 1),
96 Coordinate3(1, 1, -1),
97 Coordinate3(1, 1, 0),
98 Coordinate3(1, 1, 1),
99 }
100 assert set(c.neighbours()) == neighbours
101
102 def test_neighbours_no_diagonal(self):
103 c = Coordinate3(0, 0, 0)
104 neighbours_no_diagonal = {
105 Coordinate3(-1, 0, 0),
106 Coordinate3(1, 0, 0),
107 Coordinate3(0, -1, 0),
108 Coordinate3(0, 1, 0),
109 Coordinate3(0, 0, -1),
110 Coordinate3(0, 0, 1),
111 }
112 assert set(c.neighbours(no_diagonal=True)) == neighbours_no_diagonal