2015-05-05 23:39:30 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Read;
|
|
|
|
use std::path::Path;
|
|
|
|
use std::process::Command;
|
2014-07-07 14:55:47 +00:00
|
|
|
|
|
|
|
static PROGNAME: &'static str = "./sort";
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn numeric1() {
|
|
|
|
numeric_helper(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn numeric2() {
|
|
|
|
numeric_helper(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn numeric3() {
|
|
|
|
numeric_helper(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn numeric4() {
|
|
|
|
numeric_helper(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn numeric5() {
|
|
|
|
numeric_helper(5);
|
|
|
|
}
|
|
|
|
|
2015-08-27 03:51:52 +00:00
|
|
|
#[test]
|
|
|
|
fn numeric6() {
|
|
|
|
numeric_helper(6);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn human1() {
|
|
|
|
test_helper(&String::from("human1"), &String::from("-H"));
|
|
|
|
}
|
|
|
|
|
2015-01-10 18:54:42 +00:00
|
|
|
fn numeric_helper(test_num: isize) {
|
2015-08-27 03:51:52 +00:00
|
|
|
test_helper(&format!("numeric{}", test_num), &String::from("-n"))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_helper(file_name: &String, args: &String) {
|
2014-07-07 14:55:47 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-08-27 03:51:52 +00:00
|
|
|
cmd.arg(args);
|
|
|
|
let po = match cmd.arg(format!("{}{}", file_name, ".txt")).output() {
|
2014-07-07 14:55:47 +00:00
|
|
|
Ok(p) => p,
|
2015-05-06 17:37:57 +00:00
|
|
|
Err(err) => panic!("{}", err)
|
2014-07-07 14:55:47 +00:00
|
|
|
};
|
|
|
|
|
2015-08-27 03:51:52 +00:00
|
|
|
let filename = format!("{}{}", file_name, ".ans");
|
2015-05-05 23:39:30 +00:00
|
|
|
let mut f = File::open(Path::new(&filename)).unwrap_or_else(|err| {
|
|
|
|
panic!("{}", err)
|
|
|
|
});
|
|
|
|
let mut answer = vec!();
|
2015-05-06 17:37:57 +00:00
|
|
|
match f.read_to_end(&mut answer) {
|
|
|
|
Ok(_) => {},
|
|
|
|
Err(err) => panic!("{}", err)
|
|
|
|
}
|
2015-05-05 23:39:30 +00:00
|
|
|
assert_eq!(String::from_utf8(po.stdout).unwrap(), String::from_utf8(answer).unwrap());
|
2014-10-30 09:06:47 +00:00
|
|
|
}
|