Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jtroo committed Nov 11, 2023
1 parent eee2408 commit 0e3127c
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions keyberon/src/action/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,66 @@ fn switch_historical_1() {
false
);
}

#[test]
fn switch_historical_bools() {
let opcodes_true_and = [
OpCode::new_bool(And, 3),
OpCode::new_key_history(KeyCode::A, 0),
OpCode::new_key_history(KeyCode::B, 1),
];
let opcodes_false_and1 = [
OpCode::new_bool(And, 3),
OpCode::new_key_history(KeyCode::A, 0),
OpCode::new_key_history(KeyCode::B, 2),
];
let opcodes_false_and2 = [
OpCode::new_bool(And, 3),
OpCode::new_key_history(KeyCode::B, 2),
OpCode::new_key_history(KeyCode::A, 0),
];
let opcodes_true_or1 = [
OpCode::new_bool(Or, 3),
OpCode::new_key_history(KeyCode::A, 0),
OpCode::new_key_history(KeyCode::B, 1),
];
let opcodes_true_or2 = [
OpCode::new_bool(Or, 3),
OpCode::new_key_history(KeyCode::A, 0),
OpCode::new_key_history(KeyCode::B, 2),
];
let opcodes_true_or3 = [
OpCode::new_bool(Or, 3),
OpCode::new_key_history(KeyCode::B, 2),
OpCode::new_key_history(KeyCode::A, 0),
];
let opcodes_false_or = [
OpCode::new_bool(Or, 3),
OpCode::new_key_history(KeyCode::A, 1),
OpCode::new_key_history(KeyCode::B, 2),
];
let hist_keycodes = [
KeyCode::A,
KeyCode::B,
KeyCode::C,
KeyCode::D,
KeyCode::E,
KeyCode::F,
KeyCode::G,
KeyCode::H,
];

let test = |opcodes: &[OpCode], expectation: bool| {
assert_eq!(
evaluate_boolean(opcodes, [].iter().copied(), hist_keycodes.iter().copied(),),
expectation
);
};
test(&opcodes_true_and, true);
test(&opcodes_true_or1, true);
test(&opcodes_true_or2, true);
test(&opcodes_true_or3, true);
test(&opcodes_false_and1, false);
test(&opcodes_false_and2, false);
test(&opcodes_false_or, false);
}

0 comments on commit 0e3127c

Please sign in to comment.