Created
September 13, 2012 08:17
-
-
Save killerswan/3712827 to your computer and use it in GitHub Desktop.
test for Sam
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std; | |
| use io::*; | |
| struct Point {x:float, y:float} | |
| enum Shape{ | |
| Circle(Point, float), | |
| Rectangle(Point, Point) | |
| } | |
| fn area(sh: Shape) -> float { | |
| match sh { | |
| Circle(_,size) => float::consts::pi*size*size, | |
| Rectangle(point1, point2) => (point2.x-point1.x)*(point2.y-point1.y) | |
| } | |
| } | |
| fn main() { | |
| let pt: Point = Point {x:4.5, y:5.5}; | |
| let circle: Shape = Circle(pt,1.7); | |
| area(circle); | |
| let pi = float::consts::pi; | |
| if area(circle) - 1.7 * 1.7 * pi < 0.1 { io::println("OK"); } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment