36 lines
831 B
Rust
36 lines
831 B
Rust
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 advanced6_recurse1() {
|
|
run_calc("2!?.", "2\n");
|
|
}
|
|
|
|
#[test]
|
|
fn advanced6_recurse2() {
|
|
run_calc("7!?.", "5040\n");
|
|
}
|
|
|
|
#[test]
|
|
fn advanced6_recurse3() {
|
|
run_calc("8!?.", "40320\n");
|
|
}
|