Correct Test
This commit is contained in:
parent
2e2bf8e35a
commit
bb350d3ec7
106
maze/src/lib.rs
106
maze/src/lib.rs
@ -426,16 +426,16 @@ impl<const X: usize, const Y: usize, const SIZE: usize> AsciiBroad<X, Y, SIZE> {
|
||||
write!(bottom_line, "#").unwrap();
|
||||
|
||||
for x in 0..X {
|
||||
write!(top_line, " ").unwrap();
|
||||
write!(top_line, ".").unwrap();
|
||||
let east_boundary = if grid.is_carved((x, y), Cell::EAST) {
|
||||
" "
|
||||
"."
|
||||
} else {
|
||||
"#"
|
||||
};
|
||||
write!(top_line, "{east_boundary}").unwrap();
|
||||
|
||||
let south_boundary = if grid.is_carved((x, y), Cell::SOUTH) {
|
||||
" "
|
||||
"."
|
||||
} 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);
|
||||
|
||||
bw.push(MazePart::Wall);
|
||||
(0..X).into_iter().for_each(|_| {
|
||||
bw.push(MazePart::Wall);
|
||||
bw.push(MazePart::Wall);
|
||||
});
|
||||
bw.copy(&[MazePart::Wall; X]);
|
||||
|
||||
let mut top_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 {
|
||||
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(&bottom_line);
|
||||
}
|
||||
@ -684,53 +685,57 @@ mod print_tests {
|
||||
#[test]
|
||||
fn binary_map() {
|
||||
let mut g = Grid::<5, 5, 25>::new();
|
||||
g.cells[0] = Cell::EAST;
|
||||
g.cells[1] = Cell::default();
|
||||
g.cells[2] = Cell::EAST;
|
||||
g.cells[3] = Cell::WEST;
|
||||
g.cells[4] = Cell::default();
|
||||
g.cells[0] = Cell::EAST | Cell::SOUTH;
|
||||
g.cells[1] = Cell::EAST | Cell::SOUTH;
|
||||
g.cells[2] = Cell::WEST | Cell::SOUTH;
|
||||
g.cells[3] = Cell::EAST | Cell::SOUTH;
|
||||
g.cells[4] = Cell::WEST | Cell::SOUTH;
|
||||
|
||||
g.cells[5] = Cell::EAST | Cell::WEST;
|
||||
g.cells[6] = Cell::EAST | Cell::WEST;
|
||||
g.cells[7] = Cell::EAST | Cell::WEST;
|
||||
g.cells[8] = Cell::EAST | Cell::WEST;
|
||||
g.cells[9] = Cell::EAST | Cell::WEST;
|
||||
g.cells[5] = Cell::WEST | Cell::SOUTH;
|
||||
g.cells[6] = Cell::WEST | Cell::SOUTH;
|
||||
g.cells[7] = Cell::WEST | Cell::NORTH;
|
||||
g.cells[8] = Cell::WEST | Cell::SOUTH;
|
||||
g.cells[9] = Cell::WEST | Cell::SOUTH;
|
||||
|
||||
g.cells[10] = Cell::EAST | Cell::WEST;
|
||||
g.cells[11] = Cell::SOUTH;
|
||||
g.cells[12] = Cell::NORTH;
|
||||
g.cells[13] = Cell::WEST | Cell::SOUTH;
|
||||
g.cells[14] = Cell::EAST | Cell::WEST;
|
||||
g.cells[10] = Cell::WEST | Cell::SOUTH;
|
||||
g.cells[11] = Cell::EAST | Cell::NORTH;
|
||||
g.cells[12] = Cell::EAST | Cell::SOUTH;
|
||||
g.cells[13] = Cell::WEST | Cell::NORTH;
|
||||
g.cells[14] = Cell::WEST | Cell::SOUTH;
|
||||
|
||||
g.cells[15] = Cell::WEST;
|
||||
g.cells[16] = Cell::WEST | Cell::NORTH | Cell::SOUTH;
|
||||
g.cells[17] = Cell::WEST | Cell::SOUTH;
|
||||
g.cells[18] = Cell::EAST | Cell::NORTH;
|
||||
g.cells[19] = Cell::EAST | Cell::WEST;
|
||||
g.cells[15] = Cell::EAST | Cell::SOUTH;
|
||||
g.cells[16] = Cell::WEST | Cell::NORTH;
|
||||
g.cells[17] = Cell::EAST | Cell::NORTH;
|
||||
g.cells[18] = Cell::WEST | Cell::SOUTH;
|
||||
g.cells[19] = Cell::WEST | Cell::SOUTH;
|
||||
|
||||
g.cells[20] = Cell::WEST | Cell::SOUTH;
|
||||
g.cells[21] = Cell::SOUTH | Cell::NORTH;
|
||||
g.cells[22] = Cell::SOUTH | Cell::NORTH;
|
||||
g.cells[23] = Cell::SOUTH | Cell::EAST;
|
||||
g.cells[24] = Cell::WEST | Cell::SOUTH;
|
||||
g.cells[20] = Cell::EAST | Cell::NORTH;
|
||||
g.cells[21] = Cell::EAST | Cell::NORTH;
|
||||
g.cells[22] = Cell::EAST | Cell::NORTH;
|
||||
g.cells[23] = Cell::WEST | Cell::NORTH;
|
||||
g.cells[24] = Cell::WEST | Cell::NORTH;
|
||||
|
||||
let mut map = BinaryMap::<12, 12, 144>::new();
|
||||
BinaryMapVisitor.format(&mut g, &mut map.0);
|
||||
let mut map = BinaryMap::<11, 11, 121>::new();
|
||||
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::Wall as W;
|
||||
use MazePart::*;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
struct MB([MazePart; 144]);
|
||||
struct MB([MazePart; 121]);
|
||||
|
||||
impl std::fmt::Debug for MB {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\n");
|
||||
for x in 0..12 {
|
||||
for y in 0..12 {
|
||||
let c = match self.0[y * 12 + x] {
|
||||
P => ' ',
|
||||
for x in 0..11 {
|
||||
for y in 0..11 {
|
||||
let c = match self.0[y * 11 + x] {
|
||||
P => '.',
|
||||
W => '#',
|
||||
Noop => '?',
|
||||
Player => 'O',
|
||||
@ -746,18 +751,17 @@ mod print_tests {
|
||||
assert_eq!(
|
||||
MB(map.0),
|
||||
MB([
|
||||
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, P, P, P, P, P, W, //
|
||||
W, P, P, P, P, P, P, P, P, P, P, W, //
|
||||
W, P, P, P, P, P, P, P, P, P, P, W, //
|
||||
W, P, P, P, P, P, P, P, P, P, P, W, //
|
||||
W, P, P, P, P, P, P, P, P, P, P, W, //
|
||||
W, P, P, P, P, P, P, P, P, P, P, W, //
|
||||
W, P, P, P, P, P, P, P, P, P, P, W, //
|
||||
W, P, P, P, P, P, P, P, P, P, 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, //
|
||||
W, P, P, P, P, P, W, P, P, P, W, //
|
||||
W, P, W, P, W, P, W, P, W, P, W, //
|
||||
W, P, W, P, W, P, W, P, W, P, W, //
|
||||
W, P, W, P, W, W, W, P, W, P, W, //
|
||||
W, P, W, P, P, P, P, P, W, P, W, //
|
||||
W, P, W, W, W, P, W, W, W, P, W, //
|
||||
W, P, P, P, W, P, P, P, W, P, W, //
|
||||
W, P, W, W, W, W, W, P, W, P, W, //
|
||||
W, P, P, P, P, P, P, P, W, P, W, //
|
||||
W, W, W, W, W, W, W, W, W, W, W,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user