Skip to content

Commit

Permalink
tests: add test for 2t pulse gen using comparator
Browse files Browse the repository at this point in the history
  • Loading branch information
StackDoubleFlow committed Jan 19, 2025
1 parent e63c7b1 commit c7b0960
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
26 changes: 23 additions & 3 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -298,8 +300,6 @@ pub fn make_repeater(
repeater: RedstoneRepeater {
delay,
facing: direction,
locked: false,
powered: false,
..Default::default()
},
},
Expand All @@ -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()
},
},
);
}
38 changes: 36 additions & 2 deletions tests/timings.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {}

0 comments on commit c7b0960

Please sign in to comment.