Now with tests for the basic algorithms.

This commit is contained in:
2018-09-28 17:48:35 -05:00
parent 3b68363b49
commit 304d009a67
95 changed files with 271012 additions and 270361 deletions

View File

@@ -219,4 +219,29 @@ macro_rules! div_impls
}
}
}
}
#[cfg(test)]
macro_rules! generate_div_tests {
($name: ident, $lname: ident) => {
#[test]
fn $lname() {
let fname = format!("testdata/div/{}.tests", stringify!($name));
run_test(fname.to_string(), 4, |case| {
let (neg0, abytes) = case.get("a").unwrap();
let (neg1, bbytes) = case.get("b").unwrap();
let (neg2, qbytes) = case.get("q").unwrap();
let (neg3, rbytes) = case.get("r").unwrap();
assert!(!neg0 && !neg1 && !neg2 && !neg3);
let a = $name::from_bytes(abytes);
let b = $name::from_bytes(bbytes);
let q = $name::from_bytes(qbytes);
let r = $name::from_bytes(rbytes);
let (myq, myr) = a.divmod(&b);
assert_eq!(q, myq);
assert_eq!(r, myr);
});
}
};
}