Skip to content

Commit 0942839

Browse files
committed
minor fix
1 parent 8aa514b commit 0942839

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/domain/point.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,15 @@ impl<const N: usize> TryFrom<[Point; N]> for Points {
106106
type Error = InputError;
107107

108108
fn try_from(points: [Point; N]) -> Result<Self, Self::Error> {
109-
Self::try_from(Vec::from(points))
109+
if N < MIN_POINTS {
110+
return Err(InputError::TooFewPoints {
111+
len: N,
112+
min_required: MIN_POINTS,
113+
});
114+
}
115+
Ok(Self {
116+
points: Arc::from(points),
117+
})
110118
}
111119
}
112120

src/domain/tests/basics.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ fn points_require_at_least_two_values() {
4343
);
4444
}
4545

46+
#[test]
47+
fn points_array_construction_rejects_short_arrays() {
48+
let points = [Point::try_new(0.0, 0.0).unwrap()];
49+
let error = Points::try_from(points).expect_err("must reject short arrays");
50+
51+
assert_eq!(
52+
error,
53+
InputError::TooFewPoints {
54+
len: 1,
55+
min_required: 2,
56+
}
57+
);
58+
}
59+
4660
#[test]
4761
fn family_validation_checks_min_points_and_domain() {
4862
let points = Points::try_from([

0 commit comments

Comments
 (0)