From c7b096020a5c6788e7030aabf8fd5e0c4d907299 Mon Sep 17 00:00:00 2001 From: StackDoubleFlow Date: Sun, 19 Jan 2025 00:11:41 -0500 Subject: [PATCH] tests: add test for 2t pulse gen using comparator --- tests/common/mod.rs | 26 +++++++++++++++++++++++--- tests/timings.rs | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 1d710f4c..c24d8326 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,5 +1,7 @@ use mchprs_blocks::block_entities::BlockEntity; -use mchprs_blocks::blocks::{Block, Lever, LeverFace, RedstoneRepeater}; +use mchprs_blocks::blocks::{ + Block, ComparatorMode, Lever, LeverFace, RedstoneComparator, RedstoneRepeater, +}; use mchprs_blocks::{BlockDirection, BlockPos}; use mchprs_redpiler::{BackendVariant, Compiler, CompilerOptions}; use mchprs_redstone::wire::make_cross; @@ -298,8 +300,6 @@ pub fn make_repeater( repeater: RedstoneRepeater { delay, facing: direction, - locked: false, - powered: false, ..Default::default() }, }, @@ -316,3 +316,23 @@ pub fn make_wire(world: &mut TestWorld, wire_pos: BlockPos) { }, ); } + +/// Creates a comparator at `comp_pos` with a block of sandstone below it +pub fn make_comparator( + world: &mut TestWorld, + comp_pos: BlockPos, + mode: ComparatorMode, + facing: BlockDirection, +) { + place_on_block( + world, + comp_pos, + Block::RedstoneComparator { + comparator: RedstoneComparator { + mode, + facing, + ..Default::default() + }, + }, + ); +} diff --git a/tests/timings.rs b/tests/timings.rs index f62bab1d..a2560fe3 100644 --- a/tests/timings.rs +++ b/tests/timings.rs @@ -1,10 +1,11 @@ mod common; use common::*; -use mchprs_blocks::BlockDirection; + +use mchprs_blocks::{blocks::ComparatorMode, BlockDirection}; test_all_backends!(repeater_t_flip_flop); fn repeater_t_flip_flop(backend: TestBackend) { - // RS -> Repeater South + // RN -> Repeater North // Layout: // W RN W // W RN RE @@ -42,3 +43,36 @@ fn repeater_t_flip_flop(backend: TestBackend) { runner.use_block(lever_pos); runner.check_powered_for(output_pos, false, 10); } + +test_all_backends!(pulse_gen_2t); +fn pulse_gen_2t(backend: TestBackend) { + let output_pos = pos(4, 1, 1); + let lever_pos = pos(0, 1, 1); + + let mut world = TestWorld::new(1); + + make_wire(&mut world, pos(1, 1, 0)); + make_repeater(&mut world, pos(2, 1, 0), 2, BlockDirection::West); + make_wire(&mut world, pos(3, 1, 0)); + + make_lever(&mut world, lever_pos); + make_wire(&mut world, pos(1, 1, 1)); + make_wire(&mut world, pos(2, 1, 1)); + make_comparator( + &mut world, + pos(3, 1, 1), + ComparatorMode::Subtract, + BlockDirection::West, + ); + place_on_block(&mut world, output_pos, trapdoor()); + + let mut runner = BackendRunner::new(world, backend); + + runner.use_block(lever_pos); + runner.check_powered_for(output_pos, false, 1); + runner.check_powered_for(output_pos, true, 2); + runner.check_powered_for(output_pos, false, 10); +} + +test_all_backends!(pulse_gen_1t); +fn pulse_gen_1t(backend: TestBackend) {}