Skip to content

Commit

Permalink
Redefine test in terms of public API
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Jun 21, 2022
1 parent c43ffcf commit b82b663
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions crates/fj-kernel/src/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,28 +183,51 @@ mod tests {
use crate::{
objects::Edge,
shape::{LocalForm, Shape},
validation::Config,
};

#[test]
fn validate_edge() -> anyhow::Result<()> {
let mut shape = Shape::new();
Edge::builder(&mut shape)
.build_line_segment_from_points([[0., 0., 0.], [1., 0., 0.]])?
.get();

let deviation = Scalar::from_f64(0.25);

let edge = Edge::builder(&mut shape)
.build_line_segment_from_points([[0., 0., 0.], [1., 0., 0.]])?
.get();
let edge = Edge {
vertices: edge.vertices.map(|vertex| {
LocalForm::new(
*vertex.local() + [deviation],
vertex.canonical(),
)
}),
..edge
};
assert!(super::coherence::validate_edge(&edge, deviation * 2.).is_ok());
assert!(super::coherence::validate_edge(&edge, deviation / 2.).is_err());
shape
.update()
.update_all(|edge: &mut Edge<3>| {
let original = edge.clone();
*edge = Edge {
vertices: original.vertices.map(|vertex| {
LocalForm::new(
*vertex.local() + [deviation],
vertex.canonical(),
)
}),
..original
}
})
.validate()?;

let result = super::validate(
shape.clone(),
&Config {
identical_max_distance: deviation * 2.,
..Config::default()
},
);
assert!(result.is_ok());

let result = super::validate(
shape,
&Config {
identical_max_distance: deviation / 2.,
..Config::default()
},
);
assert!(result.is_err());

Ok(())
}
Expand Down

0 comments on commit b82b663

Please sign in to comment.