Skip to content

Commit

Permalink
test(grid): add missing Grid tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Aug 28, 2024
1 parent 3c3f05f commit 0f6fe5c
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ fn resize() {
assert_eq!(g.vertices_len(), 9);
assert!(!g.resize(4, 4));
assert_eq!(g.vertices_len(), 9);
assert!(!g.resize(3, 4));
assert_eq!(g.vertices_len(), 9);
assert!(!g.resize(3, 3));
assert_eq!(g.vertices_len(), 9);
assert!(g.resize(2, 2));
Expand Down Expand Up @@ -267,6 +269,47 @@ fn neighbours_outside_vertex() {
assert_eq!(g.neighbours((10, 10)), vec![]);
}

#[test]
fn neighbours_of_border() {
let sort = |mut v: Vec<(usize, usize)>| {
v.sort();
v
};

let mut g = Grid::new(3, 3);
assert_eq!(g.neighbours((2, 2)), vec![]);
g.enable_diagonal_mode();
assert_eq!(g.neighbours((2, 2)), vec![]);
g.fill();
assert_eq!(sort(g.neighbours((2, 2))), vec![(1, 1), (1, 2), (2, 1)]);
g.disable_diagonal_mode();
assert_eq!(sort(g.neighbours((2, 2))), vec![(1, 2), (2, 1)]);

let mut g = Grid::new(3, 3);
assert_eq!(g.neighbours((2, 1)), vec![]);
g.enable_diagonal_mode();
assert_eq!(g.neighbours((2, 1)), vec![]);
g.fill();
assert_eq!(
sort(g.neighbours((2, 1))),
vec![(1, 0), (1, 1), (1, 2), (2, 0), (2, 2)]
);
g.disable_diagonal_mode();
assert_eq!(sort(g.neighbours((2, 1))), vec![(1, 1), (2, 0), (2, 2)]);

let mut g = Grid::new(3, 3);
assert_eq!(g.neighbours((1, 2)), vec![]);
g.enable_diagonal_mode();
assert_eq!(g.neighbours((1, 2)), vec![]);
g.fill();
assert_eq!(
sort(g.neighbours((1, 2))),
vec![(0, 1), (0, 2), (1, 1), (2, 1), (2, 2)]
);
g.disable_diagonal_mode();
assert_eq!(sort(g.neighbours((1, 2))), vec![(0, 2), (1, 1), (2, 2)]);
}

#[test]
fn totally_empty() {
let g = Grid::new(0, 0);
Expand Down Expand Up @@ -394,6 +437,20 @@ fn remove_borders_empty() {
assert_eq!(g.vertices_len(), 0);
assert_eq!(g.remove_borders(), 0);
assert_eq!(g.vertices_len(), 0);

let mut g = Grid::new(1, 0);
assert_eq!(g.vertices_len(), 0);
g.fill();
assert_eq!(g.vertices_len(), 0);
assert_eq!(g.remove_borders(), 0);
assert_eq!(g.vertices_len(), 0);

let mut g = Grid::new(0, 1);
assert_eq!(g.vertices_len(), 0);
g.fill();
assert_eq!(g.vertices_len(), 0);
assert_eq!(g.remove_borders(), 0);
assert_eq!(g.vertices_len(), 0);
}

#[test]
Expand Down

0 comments on commit 0f6fe5c

Please sign in to comment.