add ratio tests
This commit is contained in:
parent
bc773f7d45
commit
94cd23fe4b
@ -1 +1,4 @@
|
||||
pub mod ratio;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
58
ratio_ops/src/tests.rs
Normal file
58
ratio_ops/src/tests.rs
Normal file
@ -0,0 +1,58 @@
|
||||
use crate::ratio::Ratio;
|
||||
|
||||
macro_rules! test_op{
|
||||
($ratio_op:ident,$op:ident,$a:expr,$b:expr,$c:expr,$d:expr)=>{
|
||||
assert_eq!(
|
||||
Ratio::new($a,$b).$ratio_op(Ratio::new($c,$d)),
|
||||
(($a as f32)/($b as f32)).$op(&(($c as f32)/($d as f32)))
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! test_many_ops{
|
||||
($ratio_op:ident,$op:ident)=>{
|
||||
test_op!($ratio_op,$op,1,2,3,4);
|
||||
test_op!($ratio_op,$op,1,2,-3,4);
|
||||
test_op!($ratio_op,$op,-1,2,-3,4);
|
||||
test_op!($ratio_op,$op,-1,-2,-3,4);
|
||||
test_op!($ratio_op,$op,2,1,6,3);
|
||||
test_op!($ratio_op,$op,-2,1,6,3);
|
||||
test_op!($ratio_op,$op,2,-1,-6,3);
|
||||
test_op!($ratio_op,$op,2,1,6,-3);
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lt(){
|
||||
test_many_ops!(lt_ratio,lt);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gt(){
|
||||
test_many_ops!(gt_ratio,gt);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_le(){
|
||||
test_many_ops!(le_ratio,le);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ge(){
|
||||
test_many_ops!(ge_ratio,ge);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eq(){
|
||||
test_many_ops!(eq_ratio,eq);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_partial_cmp(){
|
||||
test_many_ops!(partial_cmp_ratio,partial_cmp);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn test_cmp(){
|
||||
// test_many_ops!(cmp_ratio,cmp);
|
||||
// }
|
Loading…
Reference in New Issue
Block a user