Update tests

This commit is contained in:
2018-05-26 15:53:20 +02:00
parent 2fe47fe30c
commit 0b8e28fb22
4 changed files with 115 additions and 15 deletions

40
tests/advanced5.rs Normal file
View File

@@ -0,0 +1,40 @@
extern crate rustijvm;
use std::sync::{Arc, Mutex};
use std::io::{Cursor, Seek, SeekFrom, Read};
fn run_calc(input: &'static str, expected: &str) {
let rc = Arc::new(Mutex::new(Cursor::new(Vec::new())));
let mut machine = rustijvm::Machine::new_from_file("files/advanced/SimpleCalc.ijvm").unwrap();
machine.set_input(Box::new(input.as_bytes()));
machine.set_output(rc.clone());
machine.run().unwrap();
let mut out = rc.lock().unwrap();
let mut output = String::new();
out.seek(SeekFrom::Start(0)).unwrap();
out.read_to_string(&mut output).unwrap();
assert_eq!(output, expected);
}
#[test]
fn advanced5_level1() {
run_calc("0 0 + ? .", "0\n");
run_calc("0 9 + ? .", "9\n");
run_calc("9 0 + ? .", "9\n");
run_calc("9 9 - ? .", "0\n");
}
#[test]
fn advanced5_level2() {
run_calc(" 5 4 -?.", "1\n");
run_calc(" 8 8 8 - + ?.", "8\n");
}
#[test]
fn advanced5_level3() {
run_calc("1 1 + 1 1 + 1 1 + 1 1 + 1 1 + +-++?.", "2\n");
run_calc("9 8 -9 7-9 6-9 5-9 4-9 3-9 2-9 1-9 0- -+-+-+-+?.", "1\n");
}