Created
April 6, 2012 05:55
-
-
Save bltavares/2317443 to your computer and use it in GitHub Desktop.
Rectangle Code
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
public class Rectangle { | |
private final int width; | |
private final int height; | |
public Rectangle(int width, int height) { | |
this.width = width; | |
this.height = height; | |
} | |
public int perimeter() { | |
return width * 2 + height * 2; | |
} | |
public int area() { | |
return width * height; | |
} | |
} |
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
import org.junit.Test; | |
import static junit.framework.Assert.assertEquals; | |
public class RectangleTest { | |
@Test | |
public void should_have_a_perimeter() { | |
assertEquals(20, new Rectangle(5, 5).perimeter()); | |
assertEquals(18, new Rectangle(4, 5).perimeter()); | |
} | |
@Test | |
public void should_have_an_area() { | |
assertEquals(1, new Rectangle(1, 1).area()); | |
assertEquals(20, new Rectangle(4, 5).area()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment