Skip to content

Commit

Permalink
[tests] fix nightly tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aslpavel committed Aug 11, 2024
1 parent f4196d7 commit fd67cb6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions examples/rasterize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ fn main() -> Result<(), Error> {
.bbox(Transform::identity())
.ok_or("nothing to render")?,
};
tracing::debug!(?bbox, "[bbox]");
let bbox = BBox::new((bbox.x().round(), bbox.y().round()), bbox.max());
let (scene, bg) = match args.bg {
None => {
Expand Down
27 changes: 9 additions & 18 deletions src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ fn cubic_offset_should_split(cubic: Cubic) -> bool {
#[cfg(test)]
mod tests {
use super::*;
use crate::assert_approx_eq;
use crate::{assert_approx_eq, assert_approx_eq_iter};

#[test]
fn test_polyline_offset() {
Expand Down Expand Up @@ -1501,21 +1501,18 @@ mod tests {
assert_eq!(l.roots().collect::<Vec<_>>(), vec![0.5]);

let q: Quad = "M0-2Q7,6 6-4".parse().unwrap();
assert_eq!(
q.roots().collect::<Vec<_>>(),
vec![0.73841681234051, 0.15047207654837882]
);
assert_approx_eq_iter!(q.roots(), [0.73841681234051, 0.15047207654837882]);

let c = Cubic::new((0.0, -2.0), (2.0, 4.0), (4.0, -3.0), (9.0, 1.0));
assert_eq!(
c.roots().collect::<Vec<_>>(),
vec![0.8812186869024836, 0.1627575589800928, 0.5810237541174236]
assert_approx_eq_iter!(
c.roots(),
[0.8812186869024836, 0.1627575589800928, 0.5810237541174236]
);

let c: Cubic = "M8,-1 C1,3 6,-3 9,1".parse().unwrap();
assert_eq!(
assert_approx_eq_iter!(
c.roots().collect::<Vec<_>>(),
vec![0.8872983346207419, 0.11270166537925835, 0.4999999999999995]
[0.8872983346207419, 0.11270166537925835, 0.4999999999999995]
);
}

Expand All @@ -1528,10 +1525,7 @@ mod tests {
0.0, 0.0, 1.0
];
let M3x3(q) = Q * QI;
assert_eq!(i3.len(), q.len());
for (v0, v1) in i3.iter().zip(q.iter()) {
assert_approx_eq!(v0, v1);
}
assert_approx_eq_iter!(i3, q);

#[rustfmt::skip]
let i4 = [
Expand All @@ -1541,10 +1535,7 @@ mod tests {
0.0, 0.0, 0.0, 1.0,
];
let M4x4(c) = C * CI;
assert_eq!(i4.len(), c.len());
for (v0, v1) in i4.iter().zip(c.iter()) {
assert_approx_eq!(v0, v1);
}
assert_approx_eq_iter!(i4, c);
}

#[test]
Expand Down
16 changes: 16 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,22 @@ pub mod tests {
}};
}

#[macro_export]
macro_rules! assert_approx_eq_iter {
( $v0:expr, $v1: expr ) => {{
assert_approx_eq_iter!($v0, $v1, $crate::EPSILON);
}};
( $v0:expr, $v1: expr, $e: expr ) => {{
let mut i0 = $v0.into_iter();
let mut i1 = $v1.into_iter();
for (v0, v1) in i0.by_ref().zip(i1.by_ref()) {
assert_approx_eq!(v0, v1, $e);
}
assert!(i0.next().is_none(), "left iterator is longer");
assert!(i1.next().is_none(), "right iterator is longer");
}};
}

#[test]
fn test_solve() {
fn solve_check(a: Scalar, b: Scalar, c: Scalar, d: Scalar, roots: &[Scalar]) {
Expand Down

0 comments on commit fd67cb6

Please sign in to comment.