From 42494f95aba5c7e5a84a772831e71b2c17815551 Mon Sep 17 00:00:00 2001 From: Der Chien Date: Wed, 28 Dec 2022 21:49:01 +0800 Subject: [PATCH 1/2] 20221228 add one more point to the polygon --- src/exercises/day-2/points-polygons.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/exercises/day-2/points-polygons.rs b/src/exercises/day-2/points-polygons.rs index 78fd13fb..2f1148c8 100644 --- a/src/exercises/day-2/points-polygons.rs +++ b/src/exercises/day-2/points-polygons.rs @@ -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; @@ -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), @@ -217,7 +218,7 @@ mod tests { .map(Shape::circumference) .map(round_two_digits) .collect::>(); - assert_eq!(circumferences, vec![10.0, 31.42]); + assert_eq!(circumferences, vec![15.48, 31.42]); } } // ANCHOR_END: unit-tests From 0b77fc6bf3bf4c1d0fdb32e324c5db064c639902 Mon Sep 17 00:00:00 2001 From: Der Chien Date: Wed, 28 Dec 2022 22:39:52 +0800 Subject: [PATCH 2/2] 20221228 revert the points length check --- src/exercises/day-2/points-polygons.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/exercises/day-2/points-polygons.rs b/src/exercises/day-2/points-polygons.rs index 2f1148c8..0d7c1d23 100644 --- a/src/exercises/day-2/points-polygons.rs +++ b/src/exercises/day-2/points-polygons.rs @@ -84,8 +84,8 @@ impl Polygon { } pub fn length(&self) -> f64 { - if self.points.len() < 3 { - return f64::NAN; + if self.points.is_empty() { + return 0.0; } let mut result = 0.0;