mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-02-14 17:00:03 +02:00
20221228 add one more point to the polygon
This commit is contained in:
parent
dcf29d4653
commit
42494f95ab
@ -84,8 +84,8 @@ impl Polygon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn length(&self) -> f64 {
|
pub fn length(&self) -> f64 {
|
||||||
if self.points.is_empty() {
|
if self.points.len() < 3 {
|
||||||
return 0.0;
|
return f64::NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut result = 0.0;
|
let mut result = 0.0;
|
||||||
@ -207,6 +207,7 @@ mod tests {
|
|||||||
fn test_shape_circumferences() {
|
fn test_shape_circumferences() {
|
||||||
let mut poly = Polygon::new();
|
let mut poly = Polygon::new();
|
||||||
poly.add_point(Point::new(12, 13));
|
poly.add_point(Point::new(12, 13));
|
||||||
|
poly.add_point(Point::new(17, 11));
|
||||||
poly.add_point(Point::new(16, 16));
|
poly.add_point(Point::new(16, 16));
|
||||||
let shapes = vec![
|
let shapes = vec![
|
||||||
Shape::from(poly),
|
Shape::from(poly),
|
||||||
@ -217,7 +218,7 @@ mod tests {
|
|||||||
.map(Shape::circumference)
|
.map(Shape::circumference)
|
||||||
.map(round_two_digits)
|
.map(round_two_digits)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
assert_eq!(circumferences, vec![10.0, 31.42]);
|
assert_eq!(circumferences, vec![15.48, 31.42]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ANCHOR_END: unit-tests
|
// ANCHOR_END: unit-tests
|
||||||
|
Loading…
x
Reference in New Issue
Block a user