Skip to content

Instantly share code, notes, and snippets.

@vikhyat
Created March 26, 2014 09:05
Show Gist options
  • Save vikhyat/9779280 to your computer and use it in GitHub Desktop.
Save vikhyat/9779280 to your computer and use it in GitHub Desktop.
package net.vikhyat.circle;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
public class CircleTest extends TestCase {
private Circle circle;
@Before
public void initializeCircle() {
circle = new Circle(0, 0);
}
@Test
public void testComputeRadius() throws Exception {
assertEquals("computes radius correctly", 10.0, circle.computeRadius(314.1592653589), 0.01);
assertEquals("updates computed radius", 100.0, circle.computeRadius(31415.92653589), 0.01);
}
@Test
public void testComputeArea() throws Exception {
assertEquals("computes area correctly", 314.1592653589, circle.computeArea(10.0), 0.01);
assertEquals("updates computed area", 31415.92653589, circle.computeArea(100.0), 0.01);
}
@Test
public void testGetFormattedRadius() throws Exception {
circle = new Circle(10, 0);
assertEquals("radius is formatted correctly", "10.0", circle.getFormattedRadius());
circle = new Circle(234.234324, 0);
assertEquals("radius is formatted correctly", "234.234", circle.getFormattedRadius());
}
@Test
public void testGetFormattedArea() throws Exception {
circle = new Circle(0, 10);
assertEquals("area is formatted correctly", "10.0", circle.getFormattedArea());
circle = new Circle(0, 123456789289.0);
assertEquals("area switches to scientific notation when it is too long", "1.235E11", circle.getFormattedArea());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment