Skip to content

Commit

Permalink
20221228 add one more point to the polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
der3318 authored Dec 28, 2022
1 parent dcf29d4 commit 42494f9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/exercises/day-2/points-polygons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl Polygon {
}

pub fn length(&self) -> f64 {
if self.points.is_empty() {
return 0.0;
if self.points.len() < 3 {
return f64::NAN;
}

let mut result = 0.0;
Expand Down Expand Up @@ -207,6 +207,7 @@ mod tests {
fn test_shape_circumferences() {
let mut poly = Polygon::new();
poly.add_point(Point::new(12, 13));
poly.add_point(Point::new(17, 11));
poly.add_point(Point::new(16, 16));
let shapes = vec![
Shape::from(poly),
Expand All @@ -217,7 +218,7 @@ mod tests {
.map(Shape::circumference)
.map(round_two_digits)
.collect::<Vec<_>>();
assert_eq!(circumferences, vec![10.0, 31.42]);
assert_eq!(circumferences, vec![15.48, 31.42]);
}
}
// ANCHOR_END: unit-tests

0 comments on commit 42494f9

Please sign in to comment.