use std::cell::RefCell;
use std::rc::Rc;
use osiris_data::data::atomic::Word;
use osiris_data::data::composite::Array;
use osiris_data::data::identification::Address;
use osiris_data::memory::Memory;
use osiris_process::operation::Instruction;
use osiris_process::processor::Cpu;
use crate::get_standard_set;
fn get_test_cpu(instructions: &[Instruction]) -> Cpu {
let raw:Vec<Word> = instructions.iter().map(|i| Word::new(i.to_u64())).collect();
let mut mem = Memory::with_size(instructions.len() + 1);
mem.copy(Address::new(0), Array::from(&raw)).unwrap();
mem.store(Address::new(instructions.len() as u64), Word::new(0x01FF_0000_0000_0000)).unwrap();
let mut cpu = Cpu::new(RefCell::new(mem), Rc::new(get_standard_set()));
cpu.state.flag_debug = true;
cpu
}
#[test]
fn test_compare() {
let mut cpu = get_test_cpu(&[
Instruction::new(0x0202_0000_0000_0000),
Instruction::new(0x0202_0001_0000_0015),
Instruction::new(0x100F_0000_0000_0001),
]);
cpu.until_halt();
assert_eq!(cpu.state.operation.compare, -1);
}
#[test]
fn test_compare2() {
let mut cpu = get_test_cpu(&[
Instruction::new(0x0105_0000_0000_0002),
Instruction::new(0x01FF_0000_0000_0000),
Instruction::new(0x0202_0000_0000_0000),
Instruction::new(0x0202_0001_0000_0015),
Instruction::new(0x100F_0000_0000_0001),
Instruction::new(0x010A_0003_0000_0002), Instruction::new(0x0103_0000_0000_0000),
]);
cpu.until_halt();
}