Skip to content

Commit

Permalink
rust/workspaces: adds some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindnetland authored and MattFerraro committed May 30, 2024
1 parent 453f9e8 commit ed67c2d
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/cadmium/src/workbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit ed67c2d

Please sign in to comment.