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:
parent
438c16607d
commit
ec01563bd6
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user