write some ratio tests

This commit is contained in:
Quaternions 2024-08-28 15:46:49 -07:00
parent e604ce83e9
commit d47eaa423e
5 changed files with 59 additions and 0 deletions

View File

@ -2,13 +2,35 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "bnum"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e31ea183f6ee62ac8b8a8cf7feddd766317adfb13ff469de57ce033efd6a790"
[[package]]
name = "deferred_division"
version = "0.1.0"
dependencies = [
"fixed_wide",
"fixed_wide_traits",
]
[[package]]
name = "fixed_wide"
version = "0.1.0"
dependencies = [
"bnum",
"fixed_wide_traits",
"typenum",
]
[[package]]
name = "fixed_wide_traits"
version = "0.1.0"
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"

View File

@ -9,3 +9,6 @@ fixed_wide_traits=["dep:fixed_wide_traits"]
[dependencies]
fixed_wide_traits = { version = "0.1.0", path = "../fixed_wide_traits", optional = true }
[dev-dependencies]
fixed_wide = { version = "0.1.0", path = "../fixed_wide" }

View File

@ -0,0 +1,4 @@
mod tests;
#[cfg(feature="fixed_wide_traits")]
mod wide;

View File

@ -0,0 +1,15 @@
use crate::ratio::Ratio;
#[test]
fn ratio(){
let r=Ratio::new(5,3);
let a=r%1;
assert_eq!(a.num,2);
assert_eq!(a.den,3);
let b=r*2;
assert_eq!(b.num,10);
assert_eq!(b.den,3);
let c=r/2;
assert_eq!(c.num,5);
assert_eq!(c.den,6);
}

View File

@ -0,0 +1,15 @@
use crate::ratio::Ratio;
use fixed_wide_traits::wide::{WideMul,WideDiv};
use fixed_wide::types::I32F32;
use fixed_wide::types::I64F64;
#[test]
fn ratio(){
let r=Ratio::new(I32F32::from(5),I32F32::from(3));
let a=r.wide_mul(I32F32::from(7)>>2);
assert_eq!(a.num,I64F64::from(7*5)>>2);
assert_eq!(a.den,I32F32::from(3));
let a=r.wide_div(I32F32::from(7)>>2);
assert_eq!(a.num,I32F32::from(5));
assert_eq!(a.den,I64F64::from(3*7)>>2);
}