~maddie/custom-processor-simulator

59de9ed0478e28b6716188bc60a067d34e411fca — Madeline Cronin 3 months ago e1ab8b6
Write tests for subtraction and related behaviours.
1 files changed, 47 insertions(+), 0 deletions(-)

M src/processor.rs
M src/processor.rs => src/processor.rs +47 -0
@@ 385,4 385,51 @@ mod tests {
        assert_eq!(processor.reg[2], i16::MIN as u16 + 4);
        assert_eq!(processor.reg[3], 5);
    }
    #[test]
    fn arithmetic_invert () {
        let memory: &mut [u16] = &mut [0x0600, 3, 0x0608, 4, 0x0110, 0x0044, 0, 0];
        let disk: &mut [u16] = &mut [0];
        let vram: &mut [u16] = &mut [0];
        let mut processor = new(memory, disk, vram);
        loop {
            if processor.run() {break};
        }
        assert_eq!(processor.reg[2], !7);
    }
    #[test]
    fn sub () {
        let memory: &mut [u16] = &mut [0x0600, 5, 0x0608, 3, 0x0101, 0x0044, 0, 0];
        let disk: &mut [u16] = &mut [0];
        let vram: &mut [u16] = &mut [0];
        let mut processor = new(memory, disk, vram);
        loop {
            if processor.run() {break};
        }
        assert_eq!(processor.reg[2], 2);
    }
    #[test]
    fn underflow () {
        let memory: &mut [u16] = &mut [0x0600, 3, 0x0608, 5, 0x0141, 0x0044, 0xA618, 7, 0, 0];
        let disk: &mut [u16] = &mut [0];
        let vram: &mut [u16] = &mut [0];
        let mut processor = new(memory, disk, vram);
        loop {
            if processor.run() {break};
        }
        assert_eq!(processor.reg[2], u16::MAX - 1);
        assert_eq!(processor.reg[3], 7);
    }
    #[test]
    fn signed_underflow () {
        let memory: &mut [u16] = &mut [0x0600, 3, 0x0608, 5, 0x01C1, 0x0044, 0x0600, i16::MIN as u16, 0x01E1, 0x0046, 0xD620, 7, 0, 0];
        let disk: &mut [u16] = &mut [0];
        let vram: &mut [u16] = &mut [0];
        let mut processor = new(memory, disk, vram);
        loop {
            if processor.run() {break};
        }
        assert_eq!(processor.reg[2], -2i16 as u16);
        assert_eq!(processor.reg[3], i16::MAX as u16 - 4);
        assert_eq!(processor.reg[4], 7);
    }
}