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
#[derive(Eq, PartialEq, Debug, Copy, Clone, Hash)]
pub struct Axial (pub i8, pub i8);
impl Into<Cube> for Axial {
fn into(self) -> Cube {
Cube(self.0, self.1, -self.0 - self.1)
}
}
#[derive(Eq, PartialEq, Debug, Copy, Clone, Hash)]
pub struct Cube (pub i8, pub i8, pub i8);
impl Into<Axial> for Cube {
fn into(self) -> Axial {
Axial(self.0, self.1)
}
}
#[cfg(test)]
mod test {
use super::*;
use crate::neighbours::*;
use crate::distance::*;
#[test]
fn coords_of_cube_sum_to_0() {
let x = Cube(0, 0, 0);
let neighbours: Vec<Cube> = x.neighbours().collect();
assert_eq!(neighbours.len(), 6);
for (i, y) in neighbours.iter().enumerate() {
assert_eq!(y.0 + y.1 + y.2, 0);
assert_ne!(*y, x);
assert_eq!(y.dist(&x), 1);
for z in neighbours[i + 1..].iter() {
assert_ne!(*y, *z);
}
}
}
}