Skip to content

Commit

Permalink
feat(tests): add tests for lab and pc;
Browse files Browse the repository at this point in the history
  • Loading branch information
5-pebbles committed Sep 6, 2024
1 parent abc1509 commit 7aa9b5e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/tests/lab_and_pc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use arbitrary_int::{u12, u6};

use crate::{compilation::compile_to_binary, emulation::InteractiveState, utils::tuple_as_u12};

#[test]
fn pc() {
let mut state = InteractiveState::new();
let mc_result = compile_to_binary("PC 0 32");
assert_eq!(mc_result.diagnostics.len(), 0);
state.memory.store_array(0, &mc_result.binary);
state.consume_instruction();
assert_eq!(state.program_counter.as_tuple(), (u6::new(0), u6::new(32)));
}

#[test]
fn lab() {
let mc_result = compile_to_binary("LAB ZERO\nNOP\nNOP\nLAB TWO");
assert_eq!(mc_result.diagnostics.len(), 0);
assert_eq!(mc_result.symbol_table.get("ZERO"), Some(&u12::new(0)));
assert_eq!(mc_result.symbol_table.get("TWO"), Some(&u12::new(2)));
}

#[test]
fn pc_to_lab() {
let mut state = InteractiveState::new();
let mc_result = compile_to_binary("PC TEST\nNOP\nLAB TEST");
assert_eq!(mc_result.diagnostics.len(), 0);
state.memory.store_array(0, &mc_result.binary);
state.consume_instruction();
assert_eq!(
Some(&tuple_as_u12(state.program_counter.as_tuple())),
mc_result.symbol_table.get("TEST")
);
}
1 change: 1 addition & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod halt_and_nop;
mod lab_and_pc;
mod or_and_nor;
mod shift_and_rotate;

0 comments on commit 7aa9b5e

Please sign in to comment.