# Polygon Struct

We will create a `Polygon` struct which contain some points. Copy the code below to https://play.rust-lang.org/ and fill in the missing methods to make the tests pass:

``````// TODO: remove this when you're done with your implementation.

pub struct Point {
}

impl Point {
}

pub struct Polygon {
}

impl Polygon {
}

pub struct Circle {
}

impl Circle {
}

pub enum Shape {
Polygon(Polygon),
Circle(Circle),
}

#[cfg(test)]
mod tests {
use super::*;

fn round_two_digits(x: f64) -> f64 {
(x * 100.0).round() / 100.0
}

#[test]
fn test_point_magnitude() {
let p1 = Point::new(12, 13);
assert_eq!(round_two_digits(p1.magnitude()), 17.69);
}

#[test]
fn test_point_dist() {
let p1 = Point::new(10, 10);
let p2 = Point::new(14, 13);
assert_eq!(round_two_digits(p1.dist(p2)), 5.00);
}

#[test]
let p1 = Point::new(16, 16);
let p2 = p1 + Point::new(-4, 3);
assert_eq!(p2, Point::new(12, 19));
}

#[test]
fn test_polygon_left_most_point() {
let p1 = Point::new(12, 13);
let p2 = Point::new(16, 16);

let mut poly = Polygon::new();
assert_eq!(poly.left_most_point(), Some(p1));
}

#[test]
fn test_polygon_iter() {
let p1 = Point::new(12, 13);
let p2 = Point::new(16, 16);

let mut poly = Polygon::new();

let points = poly.iter().cloned().collect::<Vec<_>>();
assert_eq!(points, vec![Point::new(12, 13), Point::new(16, 16)]);
}

#[test]
fn test_shape_perimeters() {
let mut poly = Polygon::new();
let shapes = vec![
Shape::from(poly),
Shape::from(Circle::new(Point::new(10, 20), 5)),
];
let perimeters = shapes
.iter()
.map(Shape::perimeter)
.map(round_two_digits)
.collect::<Vec<_>>();
assert_eq!(perimeters, vec![15.48, 31.42]);
}
}

• Derive a `Copy` trait for some structs, as in tests the methods sometimes don’t borrow their arguments.
• Discover that `Add` trait must be implemented for two objects to be addable via “+”. Note that we do not discuss generics until Day 3.