Skip to content

Commit

Permalink
Add test for euclid casting
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Burns <nico@nicoburns.com>
  • Loading branch information
nicoburns committed Dec 12, 2024
1 parent 8f86c25 commit bb2bfdf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ num-traits = { version = "0.2", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }

[dev-dependencies]
euclid = "0.22.11"
ron = "0.8.0"

[features]
Expand Down
24 changes: 24 additions & 0 deletions src/app_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,27 @@ fn serialize() {
let serialized = ron::to_string(&Au(42)).unwrap();
assert_eq!(ron::from_str(&serialized), Ok(Au(42)));
}

#[cfg(feature = "num_traits")]
#[test]
fn euclid_cast_au_to_f32() {
use euclid::default::Size2D;
let size_au: Size2D<Au> = Size2D::new(Au::new(20), Au::new(30));
let size_f32_manual: Size2D<f32> =
Size2D::new(Au::new(20).to_f32_px(), Au::new(30).to_f32_px());
let size_f32_cast: Size2D<f32> = size_au.cast();

assert_eq!(size_f32_manual, size_f32_cast);
}

#[cfg(feature = "num_traits")]
#[test]
fn euclid_cast_f32_to_au() {
use euclid::default::Size2D;
let size_f32: Size2D<f32> = Size2D::new(3.1456, 245.043656);
let size_au_manual: Size2D<Au> =
Size2D::new(Au::from_f32_px(3.1456), Au::from_f32_px(245.043656));
let size_au_cast: Size2D<Au> = size_f32.cast();

assert_eq!(size_au_manual, size_au_cast);
}

0 comments on commit bb2bfdf

Please sign in to comment.