]> Witch of Git - jade-mouse/blob - toolchain/src/cpu/test.rs
Minor ISA changes
[jade-mouse] / toolchain / src / cpu / test.rs
1 use super::*;
2 use crate::inst::{Inst, Reg};
3 use proptest::prelude::*;
4
5 fn cpu() -> impl Strategy<Value = Cpu> {
6 (
7 0..1024u16,
8 [any::<u8>(); 4],
9 prop::collection::vec(any::<u8>(), 0..1024),
10 )
11 .prop_map(|(pc, reg, memory)| Cpu {
12 init: true,
13 pc,
14 reg: RegFile { values: reg },
15 memory,
16 })
17 }
18
19 fn reg() -> impl Strategy<Value = Reg> {
20 (0..4).prop_map(|r| match r {
21 0 => Reg::R0,
22 1 => Reg::R1,
23 2 => Reg::R2,
24 3 => Reg::R3,
25 _ => unreachable!(),
26 })
27 }
28
29 proptest! {
30 #[test]
31 fn run_move(mut cpu in cpu(), dst in reg(), src in reg()) {
32 let inst = Inst::Move(dst, src);
33 let val = cpu.reg(src);
34 cpu.run_inst(&inst);
35 prop_assert_eq!(val, cpu.reg(src));
36 prop_assert_eq!(val, cpu.reg(dst));
37 }
38 }