Correct Test

This commit is contained in:
eraden 2024-10-03 06:10:27 +02:00
parent 2e2bf8e35a
commit bb350d3ec7

View File

@ -426,16 +426,16 @@ impl<const X: usize, const Y: usize, const SIZE: usize> AsciiBroad<X, Y, SIZE> {
write!(bottom_line, "#").unwrap(); write!(bottom_line, "#").unwrap();
for x in 0..X { for x in 0..X {
write!(top_line, " ").unwrap(); write!(top_line, ".").unwrap();
let east_boundary = if grid.is_carved((x, y), Cell::EAST) { let east_boundary = if grid.is_carved((x, y), Cell::EAST) {
" " "."
} else { } else {
"#" "#"
}; };
write!(top_line, "{east_boundary}").unwrap(); write!(top_line, "{east_boundary}").unwrap();
let south_boundary = if grid.is_carved((x, y), Cell::SOUTH) { let south_boundary = if grid.is_carved((x, y), Cell::SOUTH) {
" " "."
} else { } else {
"#" "#"
}; };
@ -577,10 +577,7 @@ impl<const X: usize, const Y: usize, const SIZE: usize> BinaryMapVisitor<X, Y, S
let mut bw = BufWriter::new(buffer); let mut bw = BufWriter::new(buffer);
bw.push(MazePart::Wall); bw.push(MazePart::Wall);
(0..X).into_iter().for_each(|_| { bw.copy(&[MazePart::Wall; X]);
bw.push(MazePart::Wall);
bw.push(MazePart::Wall);
});
let mut top_line = [MazePart::Noop; SIZE]; let mut top_line = [MazePart::Noop; SIZE];
let mut bottom_line = [MazePart::Noop; SIZE]; let mut bottom_line = [MazePart::Noop; SIZE];
@ -607,7 +604,11 @@ impl<const X: usize, const Y: usize, const SIZE: usize> BinaryMapVisitor<X, Y, S
} else { } else {
MazePart::Wall MazePart::Wall
}); });
tl.push(MazePart::Wall);
} }
assert!(top_line.iter().any(|b| *b != MazePart::Noop));
assert!(bottom_line.iter().any(|b| *b != MazePart::Noop));
bw.copy(&top_line); bw.copy(&top_line);
bw.copy(&bottom_line); bw.copy(&bottom_line);
} }
@ -684,53 +685,57 @@ mod print_tests {
#[test] #[test]
fn binary_map() { fn binary_map() {
let mut g = Grid::<5, 5, 25>::new(); let mut g = Grid::<5, 5, 25>::new();
g.cells[0] = Cell::EAST; g.cells[0] = Cell::EAST | Cell::SOUTH;
g.cells[1] = Cell::default(); g.cells[1] = Cell::EAST | Cell::SOUTH;
g.cells[2] = Cell::EAST; g.cells[2] = Cell::WEST | Cell::SOUTH;
g.cells[3] = Cell::WEST; g.cells[3] = Cell::EAST | Cell::SOUTH;
g.cells[4] = Cell::default(); g.cells[4] = Cell::WEST | Cell::SOUTH;
g.cells[5] = Cell::EAST | Cell::WEST; g.cells[5] = Cell::WEST | Cell::SOUTH;
g.cells[6] = Cell::EAST | Cell::WEST; g.cells[6] = Cell::WEST | Cell::SOUTH;
g.cells[7] = Cell::EAST | Cell::WEST; g.cells[7] = Cell::WEST | Cell::NORTH;
g.cells[8] = Cell::EAST | Cell::WEST; g.cells[8] = Cell::WEST | Cell::SOUTH;
g.cells[9] = Cell::EAST | Cell::WEST; g.cells[9] = Cell::WEST | Cell::SOUTH;
g.cells[10] = Cell::EAST | Cell::WEST; g.cells[10] = Cell::WEST | Cell::SOUTH;
g.cells[11] = Cell::SOUTH; g.cells[11] = Cell::EAST | Cell::NORTH;
g.cells[12] = Cell::NORTH; g.cells[12] = Cell::EAST | Cell::SOUTH;
g.cells[13] = Cell::WEST | Cell::SOUTH; g.cells[13] = Cell::WEST | Cell::NORTH;
g.cells[14] = Cell::EAST | Cell::WEST; g.cells[14] = Cell::WEST | Cell::SOUTH;
g.cells[15] = Cell::WEST; g.cells[15] = Cell::EAST | Cell::SOUTH;
g.cells[16] = Cell::WEST | Cell::NORTH | Cell::SOUTH; g.cells[16] = Cell::WEST | Cell::NORTH;
g.cells[17] = Cell::WEST | Cell::SOUTH; g.cells[17] = Cell::EAST | Cell::NORTH;
g.cells[18] = Cell::EAST | Cell::NORTH; g.cells[18] = Cell::WEST | Cell::SOUTH;
g.cells[19] = Cell::EAST | Cell::WEST; g.cells[19] = Cell::WEST | Cell::SOUTH;
g.cells[20] = Cell::WEST | Cell::SOUTH; g.cells[20] = Cell::EAST | Cell::NORTH;
g.cells[21] = Cell::SOUTH | Cell::NORTH; g.cells[21] = Cell::EAST | Cell::NORTH;
g.cells[22] = Cell::SOUTH | Cell::NORTH; g.cells[22] = Cell::EAST | Cell::NORTH;
g.cells[23] = Cell::SOUTH | Cell::EAST; g.cells[23] = Cell::WEST | Cell::NORTH;
g.cells[24] = Cell::WEST | Cell::SOUTH; g.cells[24] = Cell::WEST | Cell::NORTH;
let mut map = BinaryMap::<12, 12, 144>::new(); let mut map = BinaryMap::<11, 11, 121>::new();
BinaryMapVisitor.format(&mut g, &mut map.0); BinaryMapVisitor.format(&g, &mut map.0);
let mut s = heapless::String::<144>::new();
AsciiBroad.format(&g, &mut s);
println!("{s}");
use MazePart::Passage as P; use MazePart::Passage as P;
use MazePart::Wall as W; use MazePart::Wall as W;
use MazePart::*; use MazePart::*;
#[derive(PartialEq)] #[derive(PartialEq)]
struct MB([MazePart; 144]); struct MB([MazePart; 121]);
impl std::fmt::Debug for MB { impl std::fmt::Debug for MB {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "\n"); write!(f, "\n");
for x in 0..12 { for x in 0..11 {
for y in 0..12 { for y in 0..11 {
let c = match self.0[y * 12 + x] { let c = match self.0[y * 11 + x] {
P => ' ', P => '.',
W => '#', W => '#',
Noop => '?', Noop => '?',
Player => 'O', Player => 'O',
@ -746,18 +751,17 @@ mod print_tests {
assert_eq!( assert_eq!(
MB(map.0), MB(map.0),
MB([ MB([
W, W, W, W, W, W, W, W, W, W, W, W, // W, W, W, W, W, W, W, W, W, W, W, //
W, P, P, P, P, P, P, P, P, P, P, W, // W, P, P, P, P, P, W, P, P, P, W, //
W, P, P, P, P, P, P, P, P, P, P, W, // W, P, W, P, W, P, W, P, W, P, W, //
W, P, P, P, P, P, P, P, P, P, P, W, // W, P, W, P, W, P, W, P, W, P, W, //
W, P, P, P, P, P, P, P, P, P, P, W, // W, P, W, P, W, W, W, P, W, P, W, //
W, P, P, P, P, P, P, P, P, P, P, W, // W, P, W, P, P, P, P, P, W, P, W, //
W, P, P, P, P, P, P, P, P, P, P, W, // W, P, W, W, W, P, W, W, W, P, W, //
W, P, P, P, P, P, P, P, P, P, P, W, // W, P, P, P, W, P, P, P, W, P, W, //
W, P, P, P, P, P, P, P, P, P, P, W, // W, P, W, W, W, W, W, P, W, P, W, //
W, P, P, P, P, P, P, P, P, P, P, W, // W, P, P, P, P, P, P, P, W, P, W, //
W, P, P, P, P, P, P, P, P, P, P, W, // W, W, W, W, W, W, W, W, W, W, W,
W, W, W, W, W, W, W, W, W, W, W, W,
]) ])
); );
} }