mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-02 20:18:38 -05:00
Tests: assert counts and saved names in tool, path, 3D, brush and CAD tests
Tests whose all() passed on an empty list now check the list's length or that it is not empty: - huge_circles_bridge_with_finite_anchors_or_are_refused (pathops bridge) - smooth_rounds_corners (pathops ops): the four corners stay, smoothed - a_held_rotation_turns_the_art_around_its_pin (tools ARAP): one point per mesh vertex - the_eraser_drag_area_matches_the_release_when_pressure_or_a_mode_starts_during_the_drag (tools gesture): one released point per press - every_effect_casts_a_shadow, inflate_cells_across_a_hole_edge_are_cut_to_the_shape, a_plane_has_only_a_front_and_a_hollow_solid_none and perspective_runs_0_to_160_degrees_with_the_eye_outside_the_object (three-d) - a_file_two_branches_include_is_followed_from_the_shallower_one (scriptcheck): one row per include line - pens_pick_colors_and_widths (cad HP-GL): four widths - junk_pressure_brushes_draw_finite_art (brush): all 12 cases draw Round trips that hold by construction (parse finds the id in ALL) are replaced with one saved name that must parse and one that must not: follow_names_parse (pathops shared edge), the shape kinds (pathops shapes), surfaces_parse_from_their_ids (three-d), the Quick Pen actions (tools), names_parse_and_serialize_as_names (plugins) and the brush variation modes, which also compare the serde names with the ids. crop_keeps_an_instance_whose_art_reaches_the_region (cad) names the entities written instead of checking that some were. the_saved_engine_preference_is_found (app) pins the GPU choices the preferences offer to the three the app reads. timing_unite_1000_circles (pathops) gets an ignore reason and checks that Unite gives one shape. Each changed assertion fails when the code under test is broken (an id renamed, a list emptied, a flush or instance dropped) and passes when it is restored.
This commit is contained in:
1 parent
5970647dec
commit
ccf5765419
18 files changed
+41
-33
No files matched your search
@@ -553,10 +553,9 @@ fn the_saved_engine_preference_is_found() {
|
||||
let saved = prefs.to_json();
|
||||
assert_eq!(power_preference(saved.get("gpuPreference").and_then(serde_json::Value::as_str), None), power);
|
||||
}
|
||||
// Every choice Preferences offer means something here.
|
||||
for (value, _) in vectorcraft_engine::cmd::prefscmds::GPU_PREFERENCES {
|
||||
assert!(["automatic", "lowPower", "highPerformance"].contains(value), "{value}");
|
||||
}
|
||||
// Preferences offer the three choices read above, and no other.
|
||||
let offered: Vec<&str> = vectorcraft_engine::cmd::prefscmds::GPU_PREFERENCES.iter().map(|(value, _)| *value).collect();
|
||||
assert_eq!(offered, ["automatic", "lowPower", "highPerformance"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -2220,7 +2220,10 @@ fn brushes_without_modes_vary_randomly_as_before() {
|
||||
serde_json::to_value(Variation::ALL).unwrap(),
|
||||
serde_json::json!(["fixed", "random", "pressure", "tilt", "bearing", "rotation", "stylusWheel"])
|
||||
);
|
||||
assert!(Variation::ALL.iter().all(|v| Variation::parse(v.id()) == Some(*v) && serde_json::to_value(v).unwrap() == v.id()));
|
||||
let ids: Vec<&str> = Variation::ALL.iter().map(|v| v.id()).collect();
|
||||
assert_eq!(serde_json::to_value(Variation::ALL).unwrap(), serde_json::json!(ids), "saved names are the ids");
|
||||
assert_eq!(Variation::parse("stylusWheel"), Some(Variation::StylusWheel));
|
||||
assert_eq!(Variation::parse("wheel"), None);
|
||||
assert!(!Variation::offered(false).contains(&Variation::StylusWheel) && Variation::offered(true).contains(&Variation::StylusWheel));
|
||||
}
|
||||
|
||||
@@ -2228,6 +2231,7 @@ fn brushes_without_modes_vary_randomly_as_before() {
|
||||
#[test]
|
||||
fn junk_pressure_brushes_draw_finite_art() {
|
||||
let bp = preview_path(120.0, 24.0);
|
||||
let mut drawn = 0;
|
||||
for (size, var) in [(1e308, 1e308), (-1e308, 1e308), (0.0, -1e308), (f64::MAX, f64::MAX)] {
|
||||
for profile in [vec![], vec![(0.0, 2.0), (0.0, -1.0), (5.0, 0.5)], vec![(1.0, 1.0), (0.0, 0.0)]] {
|
||||
let out = stroke_pieces(&Document::new(1.0, 1.0), &pressure_calli(size, var), &bp, &pressed(profile));
|
||||
@@ -2236,8 +2240,10 @@ fn junk_pressure_brushes_draw_finite_art() {
|
||||
all_points(n, &mut pts);
|
||||
}
|
||||
assert!(pts.iter().all(|p| p.x.is_finite() && p.y.is_finite()), "{size} {var}");
|
||||
drawn += usize::from(!pts.is_empty());
|
||||
}
|
||||
}
|
||||
assert_eq!(drawn, 12, "brushes that draw");
|
||||
}
|
||||
|
||||
/// A scatter brush of 10 × 4 pt rectangles whose size goes from `lo` % to `hi` % as `mode` says.
|
||||
|
||||
@@ -131,7 +131,7 @@ fn pens_pick_colors_and_widths() {
|
||||
let i = plot("IN;SP1;PW1;PD0,0,10,0;PU;PW2,2;SP2;PD0,10,10,10;PU;SP1;PD0,20,10,20;PU;IN;SP1;PD0,30,10,30;");
|
||||
let widths: Vec<f64> = leaves(&i.document).iter().map(|n| stroke(n).width).collect();
|
||||
let want = [MM, 2.0 * MM, MM, 0.35 * MM];
|
||||
assert!(widths.iter().zip(want).all(|(a, b)| (a - b).abs() < 1e-9), "{widths:?}");
|
||||
assert!(widths.len() == want.len() && widths.iter().zip(want).all(|(a, b)| (a - b).abs() < 1e-9), "{widths:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1448,7 +1448,8 @@ fn crop_keeps_an_instance_whose_art_reaches_the_region() {
|
||||
let art = path(&mut d, shapes::rectangle(Rect::new(100.0, 50.0, 140.0, 90.0)), Paint::solid(Color::rgb(1.0, 0.0, 0.0)), Paint::None, 0.0);
|
||||
d.symbols.push(vectorcraft_doc::Symbol { dynamic: false, name: "Far".into(), art: Arc::new(art) });
|
||||
let o = DxfOptions { crop: true, ..opts(&d) };
|
||||
assert!(!kinds(&export(&d, &o).unwrap()).is_empty());
|
||||
// The red fill: its outline and its hatch.
|
||||
assert_eq!(kinds(&export(&d, &o).unwrap()), ["LWPOLYLINE", "HATCH"]);
|
||||
}
|
||||
|
||||
/// An instance stained blue by its fill writes its symbol's red art in blue, as the canvas draws it.
|
||||
|
||||
@@ -816,11 +816,14 @@ mod tests {
|
||||
// Squaring these lengths overflows f64.
|
||||
let (a, b) = (circle(0.0, 0.0, 5e153), circle(1.5e154, 0.0, 5e153));
|
||||
let sp = smooth_bridge(a, b, 5e153).unwrap();
|
||||
// At least one anchor for each of the two circles and the two arcs.
|
||||
assert!(sp.closed && sp.anchors.len() >= 4, "{}", sp.anchors.len());
|
||||
assert!(sp.anchors.iter().all(|q| [q.p, q.h_in, q.h_out].iter().all(|p| p.x.is_finite() && p.y.is_finite())));
|
||||
assert_smooth(&sp);
|
||||
// The two radius sums fit in f64, but not their total.
|
||||
let (a, b) = (circle(-5e307, 0.0, 1e307), circle(5e307, 0.0, 1e307));
|
||||
let sp = smooth_bridge(a, b, 1.5e308).unwrap();
|
||||
assert!(sp.closed && sp.anchors.len() >= 4, "{}", sp.anchors.len());
|
||||
assert!(sp.anchors.iter().all(|q| [q.p, q.h_in, q.h_out].iter().all(|p| p.x.is_finite() && p.y.is_finite())));
|
||||
// The arcs' centers would lie beyond the largest f64.
|
||||
let (a, b) = (circle(0.0, 0.0, 1e308), circle(1.5e308, 0.0, 1e308));
|
||||
|
||||
@@ -609,12 +609,12 @@ mod tests {
|
||||
fn each_kind_draws_a_closed_outline_in_its_box() {
|
||||
for kind in ShapeKind::ALL {
|
||||
let s = shape(kind);
|
||||
assert_eq!(ShapeKind::parse(kind.id()), Some(kind));
|
||||
assert_eq!(s.check(), Ok(()), "{kind:?}");
|
||||
let p = s.path().unwrap();
|
||||
assert!(closed(&p) && within_box(&p, &s), "{kind:?}: {:?}", p.bounds());
|
||||
assert!(p.anchors().all(|(_, _, a)| a.p.x.is_finite() && a.p.y.is_finite()));
|
||||
}
|
||||
assert_eq!(ShapeKind::parse("gear"), Some(ShapeKind::Gear));
|
||||
assert_eq!(ShapeKind::parse("cloud"), None);
|
||||
}
|
||||
|
||||
|
||||
@@ -262,9 +262,7 @@ fn a_smooth_end_whose_handles_part_turns_into_a_corner() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn follow_names_round_trip() {
|
||||
for f in Follow::ALL {
|
||||
assert_eq!(Follow::parse(f.id()), Some(f));
|
||||
}
|
||||
fn follow_names_parse() {
|
||||
assert_eq!(Follow::parse("b"), Some(Follow::Second));
|
||||
assert_eq!(Follow::parse("up"), None);
|
||||
}
|
||||
@@ -738,6 +738,8 @@ fn simplify_levels_and_auto_simplify() {
|
||||
#[test]
|
||||
fn smooth_rounds_corners() {
|
||||
let s = smooth(&rect(0.0, 0.0, 10.0, 10.0), 1.0);
|
||||
// The four corners stay, each made smooth.
|
||||
assert_eq!(s.anchor_count(), 4, "{s:?}");
|
||||
assert!(s.anchors().all(|(_, _, a)| a.has_in() && a.has_out()));
|
||||
let same = smooth(&rect(0.0, 0.0, 10.0, 10.0), 0.0);
|
||||
assert_eq!(same, rect(0.0, 0.0, 10.0, 10.0));
|
||||
@@ -959,7 +961,7 @@ fn grid_split() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
#[ignore = "benchmark: prints how long Unite takes on 1000 circles; run by hand with --ignored"]
|
||||
fn timing_unite_1000_circles() {
|
||||
let mut seed = 0x1234_5678_u64;
|
||||
let mut rnd = || {
|
||||
@@ -971,8 +973,8 @@ fn timing_unite_1000_circles() {
|
||||
let circles: Vec<Shape> = (0..1000).map(|i| shape(circle(rnd() * 1000.0, rnd() * 1000.0, 5.0 + rnd() * 30.0), i)).collect();
|
||||
let t = std::time::Instant::now();
|
||||
let r = pathfinder(PathfinderOp::Unite, &circles);
|
||||
assert_eq!(r.len(), 1, "Unite gives one compound shape");
|
||||
println!("unite 1000 circles: {} ms, {} anchors", t.elapsed().as_millis(), r[0].path.anchor_count());
|
||||
assert!(!r.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -330,13 +330,11 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn names_round_trip_and_serialize_as_names() {
|
||||
for p in ALL {
|
||||
assert_eq!(Permission::parse(p.name()), Some(p));
|
||||
assert_eq!(serde_json::to_value(p).unwrap(), serde_json::json!(p.name()));
|
||||
}
|
||||
fn names_parse_and_serialize_as_names() {
|
||||
assert_eq!(serde_json::to_value(ALL).unwrap(), serde_json::json!(names(&ALL)), "saved names are the names");
|
||||
assert_eq!(Permission::parse("doc.write"), Some(Permission::DocWrite));
|
||||
assert_eq!(Permission::parse("document.read"), None);
|
||||
assert!(RESERVED.iter().all(|r| Permission::parse(r).is_none()), "reserved names are not granted");
|
||||
assert!(!RESERVED.is_empty() && RESERVED.iter().all(|r| Permission::parse(r).is_none()), "reserved names are not granted");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -2697,6 +2697,8 @@ fn a_file_two_branches_include_is_followed_from_the_shallower_one() {
|
||||
]);
|
||||
let limits = Limits { include_depth: 3, ..Limits::default() };
|
||||
let r = check("main.jsx", b"#include 'a.jsxinc'\n#include 'b.jsxinc'\n", Some(&mut m), &limits);
|
||||
// One row per #include line: main's two, a's, b's, c's and shared's.
|
||||
assert_eq!(r.includes.len(), 6, "{:?}", includes(&r));
|
||||
assert!(r.includes.iter().all(|i| i.status == IncludeStatus::Checked), "{:?}", includes(&r));
|
||||
assert_eq!(r.outside.iter().map(|o| o.id).collect::<Vec<_>>(), ["network"]);
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ fn every_effect_casts_a_shadow() {
|
||||
assert!(plane.path(Shadow::default()).is_some());
|
||||
let mut inflate = ShadowCaster::new();
|
||||
let results = inflate.inflate(&[(&path, FillRule::NonZero)], &[true], bounds, Inflate::default(), View::default());
|
||||
assert!(results.iter().all(Result::is_ok));
|
||||
assert!(results.len() == 1 && results[0].is_ok(), "one result for the one path");
|
||||
assert!(inflate.path(Shadow::default()).is_some());
|
||||
let mut revolve = ShadowCaster::new();
|
||||
revolve.revolve(&path, FillRule::NonZero, bounds, Revolve::default()).unwrap();
|
||||
|
||||
@@ -880,7 +880,7 @@ fn inflate_cells_across_a_hole_edge_are_cut_to_the_shape() {
|
||||
let (p, r) = shape(&b);
|
||||
let v = View { rotation_x: -21.88, rotation_y: -23.4, rotation_z: 9.06, ..front() };
|
||||
let f = inflate(&p, FillRule::EvenOdd, r, Inflate::default(), v).unwrap();
|
||||
assert!(f.iter().all(|f| f.contours.len() == 1), "every facet is one piece of the surface");
|
||||
assert!(!f.is_empty() && f.iter().all(|f| f.contours.len() == 1), "every facet is one piece of the surface");
|
||||
// Straight on, the facets still cover exactly the shape.
|
||||
let flat = inflate(&p, FillRule::EvenOdd, r, Inflate::default(), front()).unwrap();
|
||||
assert!(close(area(&flat), 220.0 * 220.0 - 100.0 * 90.0, 1e-3), "{}", area(&flat));
|
||||
|
||||
@@ -77,7 +77,8 @@ fn a_plane_has_only_a_front_and_a_hollow_solid_none() {
|
||||
let hollow = Extrude { cap: false, ..Extrude::default() };
|
||||
assert_eq!(extrude_face_map(bounds, hollow, view, PlanarFace::Front), None);
|
||||
let facets = extrude(&path, FillRule::NonZero, bounds, hollow, view).unwrap();
|
||||
assert!(facets.iter().all(|f| f.end.is_none()));
|
||||
// A hollow extrusion still draws its sides, and none of them is an end.
|
||||
assert!(!facets.is_empty() && facets.iter().all(|f| f.end.is_none()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -181,7 +181,7 @@ fn perspective_runs_0_to_160_degrees_with_the_eye_outside_the_object() {
|
||||
assert!(eyes.windows(2).all(|w| w[0] > w[1]), "{eyes:?}");
|
||||
let (p, b) = cylinder();
|
||||
let wide = revolve(&p, b, Revolve { rotation_x: -30.0, perspective: 160.0, ..Default::default() }).unwrap();
|
||||
assert!(wide.iter().flat_map(|f| &f.points).all(|q| q.x.is_finite() && q.y.is_finite()));
|
||||
assert!(!wide.is_empty() && wide.iter().flat_map(|f| &f.points).all(|q| q.x.is_finite() && q.y.is_finite()));
|
||||
assert_eq!(wide, revolve(&p, b, Revolve { rotation_x: -30.0, perspective: 400.0, ..Default::default() }).unwrap());
|
||||
}
|
||||
#[test]
|
||||
|
||||
@@ -87,10 +87,8 @@ fn blend_steps_round_the_shading_to_that_many_levels() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn surfaces_round_trip_through_their_ids() {
|
||||
for surface in ClassicSurface::ALL {
|
||||
assert_eq!(ClassicSurface::parse(surface.id()), Some(surface));
|
||||
}
|
||||
fn surfaces_parse_from_their_ids() {
|
||||
assert_eq!(ClassicSurface::parse("none"), Some(ClassicSurface::NoShading));
|
||||
assert_eq!(ClassicSurface::parse("glossy"), None);
|
||||
assert_eq!(ClassicSurface::default(), ClassicSurface::Plastic);
|
||||
}
|
||||
|
||||
@@ -758,11 +758,12 @@ mod tests {
|
||||
};
|
||||
// One pin, held at 0.4 rad: the whole shape turns rigidly around it.
|
||||
let d = deform(&m, &[Pin { angle: Some(0.4), ..Pin::new(c, c) }]);
|
||||
assert!(!m.verts.is_empty() && d.len() == m.verts.len(), "{} of {}", d.len(), m.verts.len());
|
||||
let err = m.verts.iter().zip(&d).map(|(a, b)| rot(*a).distance(*b)).fold(0.0, f64::max);
|
||||
assert!(err < 0.05, "{err}");
|
||||
// A free pin alone leaves the shape where it is.
|
||||
let d = deform(&m, &[Pin::new(c, c)]);
|
||||
assert!(m.verts.iter().zip(&d).all(|(a, b)| a.distance(*b) < 1e-3));
|
||||
assert!(d.len() == m.verts.len() && m.verts.iter().zip(&d).all(|(a, b)| a.distance(*b) < 1e-3));
|
||||
// Held ends: the turned end turns, the other end stays.
|
||||
let left = Point::new(10.0, 50.0);
|
||||
let pins = [Pin { angle: Some(0.5), ..Pin::new(left, left) }, Pin::new(Point::new(190.0, 50.0), Point::new(190.0, 50.0))];
|
||||
|
||||
@@ -3752,7 +3752,8 @@ fn the_eraser_drag_area_matches_the_release_when_pressure_or_a_mode_starts_durin
|
||||
press(&mut t, upright, 0.5, PointerKind::Drag, 150.0);
|
||||
near(bounds(&t), (40.0, 147.5, 160.0, 152.5));
|
||||
let released = t.stroke_json();
|
||||
assert!(released.as_array().is_some_and(|a| a.iter().all(|p| p.as_array().is_some_and(|p| p.len() == 3))), "{released}");
|
||||
// One entry per press so far (the press and two drags), each of three numbers.
|
||||
assert!(released.as_array().is_some_and(|a| a.len() == 3 && a.iter().all(|p| p.as_array().is_some_and(|p| p.len() == 3))), "{released}");
|
||||
press(&mut t, upright, 0.5, PointerKind::Up, 150.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -139,9 +139,7 @@ fn actions_cycle_and_name_themselves() {
|
||||
assert_eq!(Stroke::Line.next(), Stroke::ContinuousArc);
|
||||
assert_eq!(Stroke::ContinuousArc.next(), Stroke::SharpArc);
|
||||
assert_eq!(Stroke::SharpArc.next(), Stroke::Line);
|
||||
for s in Stroke::ALL {
|
||||
assert_eq!(Stroke::parse(s.name()), Some(s));
|
||||
}
|
||||
assert_eq!(Stroke::parse("sharpArc"), Some(Stroke::SharpArc));
|
||||
assert_eq!(Stroke::parse("arc"), None);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user