-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lih_tests): separate tests and add tests for each register;
- Loading branch information
Showing
5 changed files
with
120 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod equal; | ||
mod not_equal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use crate::{compilation::compile_to_binary, emulation::InteractiveState, utils::tuple_as_u12}; | ||
use arbitrary_int::{u12, u6}; | ||
|
||
#[test] | ||
fn jump_taken_when_a_is_not_one() { | ||
let mut state = InteractiveState::new(); | ||
let mc_result = compile_to_binary("LIH [A != 1] TEST\nHLT\nLAB TEST\nHLT"); | ||
assert_eq!(mc_result.diagnostics.len(), 0); | ||
state.memory.store_array(0, &mc_result.binary); | ||
state.consume_until_halt(); | ||
assert_eq!( | ||
Some(&tuple_as_u12(state.program_counter.as_tuple())), | ||
mc_result.symbol_table.get("TEST") | ||
); | ||
} | ||
|
||
#[test] | ||
fn jump_not_taken_when_a_is_one() { | ||
let mut state = InteractiveState::new(); | ||
let mc_result = compile_to_binary("LIH [A != 1] TEST\nHLT\nLAB TEST\nHLT"); | ||
assert_eq!(mc_result.diagnostics.len(), 0); | ||
state.memory.store_array(0, &mc_result.binary); | ||
state.a = u6::new(1); | ||
state.consume_until_halt(); | ||
assert_eq!( | ||
Some(&(tuple_as_u12(state.program_counter.as_tuple()) + u12::new(1))), | ||
mc_result.symbol_table.get("TEST") | ||
); | ||
} | ||
|
||
#[test] | ||
fn jump_taken_when_b_is_not_one() { | ||
let mut state = InteractiveState::new(); | ||
let mc_result = compile_to_binary("LIH [B != 1] TEST\nHLT\nLAB TEST\nHLT"); | ||
assert_eq!(mc_result.diagnostics.len(), 0); | ||
state.memory.store_array(0, &mc_result.binary); | ||
state.consume_until_halt(); | ||
assert_eq!( | ||
Some(&tuple_as_u12(state.program_counter.as_tuple())), | ||
mc_result.symbol_table.get("TEST") | ||
); | ||
} | ||
|
||
#[test] | ||
fn jump_not_taken_when_b_is_one() { | ||
let mut state = InteractiveState::new(); | ||
let mc_result = compile_to_binary("LIH [B != 1] TEST\nHLT\nLAB TEST\nHLT"); | ||
assert_eq!(mc_result.diagnostics.len(), 0); | ||
state.memory.store_array(0, &mc_result.binary); | ||
state.b = u6::new(1); | ||
state.consume_until_halt(); | ||
assert_eq!( | ||
Some(&(tuple_as_u12(state.program_counter.as_tuple()) + u12::new(1))), | ||
mc_result.symbol_table.get("TEST") | ||
); | ||
} | ||
|
||
#[test] | ||
fn jump_taken_when_c_is_not_one() { | ||
let mut state = InteractiveState::new(); | ||
let mc_result = compile_to_binary("LIH [C != 1] TEST\nHLT\nLAB TEST\nHLT"); | ||
assert_eq!(mc_result.diagnostics.len(), 0); | ||
state.memory.store_array(0, &mc_result.binary); | ||
state.consume_until_halt(); | ||
assert_eq!( | ||
Some(&tuple_as_u12(state.program_counter.as_tuple())), | ||
mc_result.symbol_table.get("TEST") | ||
); | ||
} | ||
|
||
#[test] | ||
fn jump_not_taken_when_c_is_one() { | ||
let mut state = InteractiveState::new(); | ||
let mc_result = compile_to_binary("LIH [C != 1] TEST\nHLT\nLAB TEST\nHLT"); | ||
assert_eq!(mc_result.diagnostics.len(), 0); | ||
state.memory.store_array(0, &mc_result.binary); | ||
state.c = u6::new(1); | ||
state.consume_until_halt(); | ||
assert_eq!( | ||
Some(&(tuple_as_u12(state.program_counter.as_tuple()) + u12::new(1))), | ||
mc_result.symbol_table.get("TEST") | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
mod halt_and_nop; | ||
mod lab_and_pc; | ||
mod logic_is_hard; | ||
mod lih; | ||
mod nor_and_or; | ||
mod nxor_and_xor; | ||
mod shift_and_rotate; |