Skip to content

Instantly share code, notes, and snippets.

@bltavares
Created April 6, 2012 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bltavares/2317443 to your computer and use it in GitHub Desktop.
Save bltavares/2317443 to your computer and use it in GitHub Desktop.
Rectangle Code
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;
}
}
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