1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-25 00:50:26 +02:00

Propose to use the generic term perimeter instead of circumference for shapes (#281)

* Update unit tests to use generic perimeter

* Update solution to use perimeter

Update solution to use the generic term perimeter instead of circumference
This commit is contained in:
upsidedwn 2023-01-26 16:59:13 +08:00 committed by GitHub
parent 438c16607d
commit ec01563bd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -142,7 +142,7 @@ impl From<Circle> for Shape {
}
impl Shape {
pub fn circumference(&self) -> f64 {
pub fn perimeter(&self) -> f64 {
match self {
Shape::Polygon(poly) => poly.length(),
Shape::Circle(circle) => circle.circumference(),
@ -204,7 +204,7 @@ mod tests {
}
#[test]
fn test_shape_circumferences() {
fn test_shape_perimeters() {
let mut poly = Polygon::new();
poly.add_point(Point::new(12, 13));
poly.add_point(Point::new(17, 11));
@ -213,12 +213,12 @@ mod tests {
Shape::from(poly),
Shape::from(Circle::new(Point::new(10, 20), 5)),
];
let circumferences = shapes
let perimeters = shapes
.iter()
.map(Shape::circumference)
.map(Shape::perimeter)
.map(round_two_digits)
.collect::<Vec<_>>();
assert_eq!(circumferences, vec![15.48, 31.42]);
assert_eq!(perimeters, vec![15.48, 31.42]);
}
}
// ANCHOR_END: unit-tests