diff --git a/packages/cadmium/src/workbench.rs b/packages/cadmium/src/workbench.rs index 58649e20..382a1f27 100644 --- a/packages/cadmium/src/workbench.rs +++ b/packages/cadmium/src/workbench.rs @@ -493,3 +493,57 @@ impl Workbench { realized } } + +#[cfg(test)] +pub mod tests { + use crate::extrusion::Direction; + + use super::*; + + #[test] + fn make_empty_workbench() { + let wb = Workbench::new("Test Workbench"); + assert_eq!(wb.history.len(), 4); + assert_eq!(wb.get_first_plane_id().unwrap(), "Plane-0".to_owned()); + assert_eq!(wb.last_plane_id().unwrap(), "Plane-2".to_owned()); + assert_eq!(wb.plane_name_to_id("Front").unwrap(), "Plane-0".to_owned()); + assert_eq!(wb.plane_name_to_id("Right").unwrap(), "Plane-1".to_owned()); + assert_eq!(wb.plane_name_to_id("Top").unwrap(), "Plane-2".to_owned()); + + let realization = wb.realize(1000); + assert_eq!(realization.points.len(), 1); //origin + assert_eq!(realization.planes.len(), 3); // origin, front, right, top + assert_eq!(realization.sketches.len(), 0); + assert_eq!(realization.solids.len(), 0); + } + + #[test] + fn make_and_workbench_with_extrusion() { + let mut wb = Workbench::new("Test Workbench"); + wb.add_sketch_to_plane("Sketch 1", "Plane-0"); + let s = wb.get_sketch_mut("Sketch 1").unwrap(); + let ll = s.add_point(0.0, 0.0); + let lr = s.add_point(40.0, 0.0); + let ul = s.add_point(0.0, 40.0); + let ur = s.add_point(40.0, 40.0); + s.add_segment(ll, lr); + s.add_segment(lr, ur); + s.add_segment(ur, ul); + s.add_segment(ul, ll); + + let extrusion = Extrusion::new( + "Sketch-0".to_owned(), + vec![0], + 25.0, + 0.0, + Direction::Normal, + ExtrusionMode::New, + ); + wb.add_extrusion("Ext1", extrusion); + + let realization = wb.realize(1000); + assert_eq!(realization.planes.len(), 3); + assert_eq!(realization.sketches.len(), 1); + assert_eq!(realization.solids.len(), 1); + } +}