Shift the gold testing infrastructure into its own module, and add the Haskell program I used to generate the tests.
This commit is contained in:
@@ -232,58 +232,8 @@ derive_arithmetic_operators!(SCN, Rem, rem, RemAssign, rem_assign);
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use quickcheck::{Arbitrary,Gen};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use super::*;
|
||||
|
||||
fn gold_test<F>(name: &str, f: F)
|
||||
where
|
||||
F: Fn(SCN,SCN) -> SCN
|
||||
{
|
||||
let mut file = File::open(name).unwrap();
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents).unwrap();
|
||||
let mut iter = contents.lines();
|
||||
|
||||
while let Some(xstr) = iter.next() {
|
||||
let ystr = iter.next().unwrap();
|
||||
let zstr = iter.next().unwrap();
|
||||
|
||||
assert!(xstr.starts_with("x: "));
|
||||
assert!(ystr.starts_with("y: "));
|
||||
assert!(zstr.starts_with("z: "));
|
||||
let x = SCN::from_str(&xstr[3..]);
|
||||
let y = SCN::from_str(&ystr[3..]);
|
||||
let z = SCN::from_str(&zstr[3..]);
|
||||
assert_eq!(f(x,y), z);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_tests() {
|
||||
gold_test("tests/add_tests_signed.txt", |x,y| x + y);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sub_tests() {
|
||||
gold_test("tests/sub_tests_signed.txt", |x,y| x - y);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mul_tests() {
|
||||
gold_test("tests/mul_tests_signed.txt", |x,y| x * y);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn div_tests() {
|
||||
gold_test("tests/div_tests_signed.txt", |x,y| x / y);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mod_tests() {
|
||||
gold_test("tests/mod_tests_signed.txt", |x,y| x % y);
|
||||
}
|
||||
|
||||
impl Arbitrary for SCN {
|
||||
fn arbitrary<G: Gen>(g: &mut G) -> SCN {
|
||||
let neg = (g.next_u32() & 1) == 1;
|
||||
|
||||
Reference in New Issue
Block a user