Reworked unit tests for machine and renamed test_programs directory
This commit is contained in:
parent
177abfe846
commit
c75e2995e7
@ -729,15 +729,12 @@ mod test {
|
||||
#[test]
|
||||
fn test_comp() {
|
||||
let mut m = Machine::init_machine();
|
||||
let path_before = "memoryComp.txt".to_string();
|
||||
let path_after = "memoryCompEnd.txt".to_string();
|
||||
let memory_before = mem_cmp::MemChecker::from(&path_before).unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from(&path_after).unwrap();
|
||||
let memory_before = mem_cmp::MemChecker::from("test/machine/memoryComp.txt").unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from("test/machine/memoryCompEnd.txt").unwrap();
|
||||
mem_cmp::MemChecker::fill_memory_from_mem_checker(&memory_before, &mut m);
|
||||
Machine::run(&mut m);
|
||||
|
||||
let path_trace = "memoryCompTrace.txt".to_string();
|
||||
let expected_trace = fs::read_to_string(path_trace).unwrap();
|
||||
let expected_trace = fs::read_to_string("test/machine/memoryCompTrace.txt").unwrap();
|
||||
|
||||
assert!(mem_cmp::MemChecker::compare_machine_memory(&memory_after, &m));
|
||||
assert!(expected_trace.contains(m.registers_trace.as_str()));
|
||||
@ -746,15 +743,12 @@ mod test {
|
||||
#[test]
|
||||
fn test_div() {
|
||||
let mut m = Machine::init_machine();
|
||||
let path_before = "memoryDiv.txt";
|
||||
let path_after = "memoryDivEnd.txt";
|
||||
let memory_before = mem_cmp::MemChecker::from(path_before).unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from(path_after).unwrap();
|
||||
let memory_before = mem_cmp::MemChecker::from("test/machine/memoryDiv.txt").unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from("test/machine/memoryDivEnd.txt").unwrap();
|
||||
mem_cmp::MemChecker::fill_memory_from_mem_checker(&memory_before, &mut m);
|
||||
Machine::run(&mut m);
|
||||
|
||||
let path_trace = "memoryDivTrace.txt".to_string();
|
||||
let expected_trace = fs::read_to_string(path_trace).unwrap();
|
||||
let expected_trace = fs::read_to_string("test/machine/memoryDivTrace.txt").unwrap();
|
||||
|
||||
assert!(mem_cmp::MemChecker::compare_machine_memory(&memory_after, &m));
|
||||
assert!(expected_trace.contains(m.registers_trace.as_str()));
|
||||
@ -763,15 +757,12 @@ mod test {
|
||||
#[test]
|
||||
fn test_if() {
|
||||
let mut m = Machine::init_machine();
|
||||
let path_before = "memoryIf.txt".to_string();
|
||||
let path_after = "memoryIfEnd.txt".to_string();
|
||||
let memory_before = mem_cmp::MemChecker::from(&path_before).unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from(&path_after).unwrap();
|
||||
let memory_before = mem_cmp::MemChecker::from("test/machine/memoryIf.txt").unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from("test/machine/memoryIfEnd.txt").unwrap();
|
||||
mem_cmp::MemChecker::fill_memory_from_mem_checker(&memory_before, &mut m);
|
||||
Machine::run(&mut m);
|
||||
|
||||
let path_trace = "memoryIfTrace.txt".to_string();
|
||||
let expected_trace = fs::read_to_string(path_trace).unwrap();
|
||||
let expected_trace = fs::read_to_string("test/machine/memoryIfTrace.txt").unwrap();
|
||||
|
||||
assert!(mem_cmp::MemChecker::compare_machine_memory(&memory_after, &m));
|
||||
assert!(expected_trace.contains(m.registers_trace.as_str()));
|
||||
@ -780,15 +771,12 @@ mod test {
|
||||
#[test]
|
||||
fn test_jump() {
|
||||
let mut m = Machine::init_machine();
|
||||
let path_before = "memoryJump.txt".to_string();
|
||||
let path_after = "memoryJumpEnd.txt".to_string();
|
||||
let memory_before = mem_cmp::MemChecker::from(&path_before).unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from(&path_after).unwrap();
|
||||
let memory_before = mem_cmp::MemChecker::from("test/machine/memoryJump.txt").unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from("test/machine/memoryJumpEnd.txt").unwrap();
|
||||
mem_cmp::MemChecker::fill_memory_from_mem_checker(&memory_before, &mut m);
|
||||
Machine::run(&mut m);
|
||||
|
||||
let path_trace = "memoryJumpTrace.txt".to_string();
|
||||
let expected_trace = fs::read_to_string(path_trace).unwrap();
|
||||
let expected_trace = fs::read_to_string("test/machine/memoryJumpTrace.txt").unwrap();
|
||||
|
||||
assert!(mem_cmp::MemChecker::compare_machine_memory(&memory_after, &m));
|
||||
assert!(expected_trace.contains(m.registers_trace.as_str()));
|
||||
@ -797,15 +785,12 @@ mod test {
|
||||
#[test]
|
||||
fn test_mul() {
|
||||
let mut m = Machine::init_machine();
|
||||
let path_before = "memoryMul.txt".to_string();
|
||||
let path_after = "memoryMulEnd.txt".to_string();
|
||||
let memory_before = mem_cmp::MemChecker::from(&path_before).unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from(&path_after).unwrap();
|
||||
let memory_before = mem_cmp::MemChecker::from("test/machine/memoryMul.txt").unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from("test/machine/memoryMulEnd.txt").unwrap();
|
||||
mem_cmp::MemChecker::fill_memory_from_mem_checker(&memory_before, &mut m);
|
||||
Machine::run(&mut m);
|
||||
|
||||
let path_trace = "memoryMulTrace.txt".to_string();
|
||||
let expected_trace = fs::read_to_string(path_trace).unwrap();
|
||||
let expected_trace = fs::read_to_string("test/machine/memoryMulTrace.txt").unwrap();
|
||||
|
||||
assert!(mem_cmp::MemChecker::compare_machine_memory(&memory_after, &m));
|
||||
assert!(expected_trace.contains(m.registers_trace.as_str()));
|
||||
@ -814,15 +799,12 @@ mod test {
|
||||
#[test]
|
||||
fn test_ret() {
|
||||
let mut m = Machine::init_machine();
|
||||
let path_before = "memoryRet.txt".to_string();
|
||||
let path_after = "memoryRetEnd.txt".to_string();
|
||||
let memory_before = mem_cmp::MemChecker::from(&path_before).unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from(&path_after).unwrap();
|
||||
let memory_before = mem_cmp::MemChecker::from("test/machine/memoryRet.txt").unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from("test/machine/memoryRetEnd.txt").unwrap();
|
||||
mem_cmp::MemChecker::fill_memory_from_mem_checker(&memory_before, &mut m);
|
||||
Machine::run(&mut m);
|
||||
|
||||
let path_trace = "memoryRetTrace.txt".to_string();
|
||||
let expected_trace = fs::read_to_string(path_trace).unwrap();
|
||||
let expected_trace = fs::read_to_string("test/machine/memoryRetTrace.txt").unwrap();
|
||||
|
||||
assert!(mem_cmp::MemChecker::compare_machine_memory(&memory_after, &m));
|
||||
assert!(expected_trace.contains(m.registers_trace.as_str()));
|
||||
@ -831,15 +813,12 @@ mod test {
|
||||
#[test]
|
||||
fn test_sub() {
|
||||
let mut m = Machine::init_machine();
|
||||
let path_before = "memorySub.txt".to_string();
|
||||
let path_after = "memorySubEnd.txt".to_string();
|
||||
let memory_before = mem_cmp::MemChecker::from(&path_before).unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from(&path_after).unwrap();
|
||||
let memory_before = mem_cmp::MemChecker::from("test/machine/memorySub.txt").unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from("test/machine/memorySubEnd.txt").unwrap();
|
||||
mem_cmp::MemChecker::fill_memory_from_mem_checker(&memory_before, &mut m);
|
||||
Machine::run(&mut m);
|
||||
|
||||
let path_trace = "memorySubTrace.txt".to_string();
|
||||
let expected_trace = fs::read_to_string(path_trace).unwrap();
|
||||
let expected_trace = fs::read_to_string("test/machine/memorySubTrace.txt").unwrap();
|
||||
|
||||
assert!(mem_cmp::MemChecker::compare_machine_memory(&memory_after, &m));
|
||||
assert!(expected_trace.contains(m.registers_trace.as_str()));
|
||||
@ -848,15 +827,12 @@ mod test {
|
||||
#[test]
|
||||
fn test_switch() {
|
||||
let mut m = Machine::init_machine();
|
||||
let path_before = "memorySwitch.txt".to_string();
|
||||
let path_after = "memorySwitchEnd.txt".to_string();
|
||||
let memory_before = mem_cmp::MemChecker::from(&path_before).unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from(&path_after).unwrap();
|
||||
let memory_before = mem_cmp::MemChecker::from("test/machine/memorySwitch.txt").unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from("test/machine/memorySwitchEnd.txt").unwrap();
|
||||
mem_cmp::MemChecker::fill_memory_from_mem_checker(&memory_before, &mut m);
|
||||
Machine::run(&mut m);
|
||||
|
||||
let path_trace = "memorySwitchTrace.txt".to_string();
|
||||
let expected_trace = fs::read_to_string(path_trace).unwrap();
|
||||
let expected_trace = fs::read_to_string("test/machine/memorySwitchTrace.txt").unwrap();
|
||||
|
||||
assert!(mem_cmp::MemChecker::compare_machine_memory(&memory_after, &m));
|
||||
assert!(expected_trace.contains(m.registers_trace.as_str()));
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user