You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-16 06:10: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:
@ -142,7 +142,7 @@ impl From<Circle> for Shape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Shape {
|
impl Shape {
|
||||||
pub fn circumference(&self) -> f64 {
|
pub fn perimeter(&self) -> f64 {
|
||||||
match self {
|
match self {
|
||||||
Shape::Polygon(poly) => poly.length(),
|
Shape::Polygon(poly) => poly.length(),
|
||||||
Shape::Circle(circle) => circle.circumference(),
|
Shape::Circle(circle) => circle.circumference(),
|
||||||
@ -204,7 +204,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_shape_circumferences() {
|
fn test_shape_perimeters() {
|
||||||
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(17, 11));
|
||||||
@ -213,12 +213,12 @@ mod tests {
|
|||||||
Shape::from(poly),
|
Shape::from(poly),
|
||||||
Shape::from(Circle::new(Point::new(10, 20), 5)),
|
Shape::from(Circle::new(Point::new(10, 20), 5)),
|
||||||
];
|
];
|
||||||
let circumferences = shapes
|
let perimeters = shapes
|
||||||
.iter()
|
.iter()
|
||||||
.map(Shape::circumference)
|
.map(Shape::perimeter)
|
||||||
.map(round_two_digits)
|
.map(round_two_digits)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
assert_eq!(circumferences, vec![15.48, 31.42]);
|
assert_eq!(perimeters, vec![15.48, 31.42]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ANCHOR_END: unit-tests
|
// ANCHOR_END: unit-tests
|
||||||
|
Reference in New Issue
Block a user