parent
2e6f7c012e
commit
db3a5e829f
@ -0,0 +1,52 @@
|
||||
#[macro_export]
|
||||
macro_rules! load_test {
|
||||
( $path:expr ) => {{
|
||||
let path = format!("{}/{}", env!("CARGO_MANIFEST_DIR"), $path);
|
||||
let raw = std::fs::read_to_string(&path).unwrap_or_else(|err| {
|
||||
panic!("Couldn't load {}: {}", &path, err);
|
||||
});
|
||||
let world: stackline::prelude::World = serde_json::from_str(&raw).expect("Couldn't parse World");
|
||||
world
|
||||
}}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! run {
|
||||
( $world:expr ) => {
|
||||
$world.step();
|
||||
};
|
||||
|
||||
( $world:expr, $steps:expr ) => {
|
||||
for _step in 0..$steps {
|
||||
$world.step();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! assert_signal {
|
||||
( $world:expr, $x:expr, $y:expr ) => {{
|
||||
let guard = $world
|
||||
.get(($x, $y))
|
||||
.expect(&format!("Couldn't get tile at {}:{}", $x, $y));
|
||||
let signal = guard.signal();
|
||||
assert!(signal.is_some(), "Expected signal at {}:{}!\n{}", $x, $y, $world);
|
||||
signal
|
||||
}};
|
||||
|
||||
( $world:expr, $x:expr, $y:expr, [ $( $data:expr ),* ] ) => {{
|
||||
let signal = assert_signal!($pane, $x, $y);
|
||||
// TODO: check that signal.data == data
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! assert_no_signal {
|
||||
( $world:expr, $x:expr, $y:expr ) => {{
|
||||
let guard = $world
|
||||
.get(($x, $y))
|
||||
.expect(&format!("Couldn't get tile at {}:{}", $x, $y));
|
||||
let signal = guard.signal();
|
||||
assert!(signal.is_none(), "Expected no signal at {}:{}!\n{}", $x, $y, $world);
|
||||
}};
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
use stackline::prelude::*;
|
||||
mod common;
|
||||
|
||||
#[test]
|
||||
fn test_wire_loop() {
|
||||
let mut world = load_test!("tests/wire/loop.json");
|
||||
|
||||
run!(world, 6);
|
||||
assert_no_signal!(world, 0, 0);
|
||||
assert_signal!(world, 3, 3);
|
||||
|
||||
run!(world, 6);
|
||||
assert_signal!(world, 0, 0);
|
||||
assert_no_signal!(world, 3, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_diode_loop() {
|
||||
let mut world = load_test!("tests/wire/diode-loop.json");
|
||||
|
||||
run!(world, 2);
|
||||
assert_no_signal!(world, 0, 0);
|
||||
assert_signal!(world, 1, 1);
|
||||
|
||||
run!(world, 4);
|
||||
assert_signal!(world, 1, 1);
|
||||
}
|
@ -0,0 +1 @@
|
||||
{"panes":{"main":{"tiles":[{"cell":{"Diode":"Right"},"signal":null,"state":"Idle","updated":false},{"cell":{"Wire":"Any"},"signal":null,"state":"Idle","updated":false},{"cell":{"Diode":"Left"},"signal":{"direction":"Left","position":[2,0],"stack":[]},"state":"Active","updated":false},{"cell":{"Diode":"Up"},"signal":null,"state":"Idle","updated":false},{"cell":{"Diode":"Left"},"signal":null,"state":"Idle","updated":false},{"cell":null,"signal":null,"state":"Idle","updated":false}],"width":3,"height":2,"position":[0,0],"signals":[]}}}
|
@ -0,0 +1 @@
|
||||
{"panes":{"main":{"tiles":[{"cell":{"Diode":"Right"},"signal":{"direction":"Right","position":[0,0],"stack":[]},"state":"Active","updated":false},{"cell":{"Wire":"Horizontal"},"signal":null,"state":"Idle","updated":false},{"cell":{"Wire":"Horizontal"},"signal":null,"state":"Idle","updated":false},{"cell":{"Diode":"Down"},"signal":null,"state":"Idle","updated":false},{"cell":{"Wire":"Vertical"},"signal":null,"state":"Idle","updated":false},{"cell":null,"signal":null,"state":"Idle","updated":false},{"cell":null,"signal":null,"state":"Idle","updated":false},{"cell":{"Wire":"Vertical"},"signal":null,"state":"Idle","updated":false},{"cell":{"Wire":"Vertical"},"signal":null,"state":"Idle","updated":false},{"cell":null,"signal":null,"state":"Idle","updated":false},{"cell":null,"signal":null,"state":"Idle","updated":false},{"cell":{"Wire":"Vertical"},"signal":null,"state":"Idle","updated":false},{"cell":{"Diode":"Up"},"signal":null,"state":"Idle","updated":false},{"cell":{"Wire":"Horizontal"},"signal":null,"state":"Idle","updated":false},{"cell":{"Wire":"Horizontal"},"signal":null,"state":"Idle","updated":false},{"cell":{"Diode":"Left"},"signal":null,"state":"Idle","updated":false}],"width":4,"height":4,"position":[0,0],"signals":[]}}}
|
Loading…
Reference in new issue