fix input being consumed even when marble creation is blocked; made multiple simultaneous inputs use the same value

This commit is contained in:
Crispy 2025-04-20 20:35:22 +02:00
parent f0b878e93d
commit 80ab3b676e
4 changed files with 33 additions and 11 deletions

View file

@ -1,8 +1,9 @@
use marble_machinations::marble_engine::{grid::Grid, Machine};
fn no_input_test(steps: usize, output: &[u8], grid: &str) {
fn do_test(steps: usize, input: &[u8], output: &[u8], grid: &str) {
let mut engine = Machine::new_empty();
engine.set_grid(Grid::from_ascii(grid));
engine.set_input(input.to_owned());
for _ in 0..(steps - 1) {
engine.step();
}
@ -11,11 +12,25 @@ fn no_input_test(steps: usize, output: &[u8], grid: &str) {
assert_eq!(engine.output(), output, "expected output");
}
fn no_input_test(steps: usize, output: &[u8], grid: &str) {
do_test(steps, &[], output, grid)
}
#[test]
fn creating_marbles_cause_indirect_claim() {
no_input_test(3, &[1], " o \n|-*-|\n| 1 |\n-B B-\n I\n");
}
#[test]
fn bug_input_consumed_when_marble_creation_blocked() {
do_test(
4,
&[1, 2, 3],
&[1, 1],
"# +-+\nIIo| I\n *+B\nII\n++*\n# #\n",
);
}
#[test]
fn bug_overlapping_marble_creation_blocks_tile_forever() {
no_input_test(