Advertisement
Guest User

Untitled

a guest
May 6th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. import org.junit.* ;
  2. import static org.junit.Assert.* ;
  3.  
  4. public class SphereTest {
  5.    
  6.     private double sphereRadius;
  7.     private int sphereX;
  8.     private int sphereY;
  9.     private int sphereZ;
  10.     private double delta = 1e-5;
  11.    
  12.    
  13.     @Before
  14.     public void setUp() {
  15.         sphereRadius = 3.0;
  16.         sphereX = 5;
  17.         sphereY = -2;
  18.         sphereZ = -10;
  19.     }
  20.    
  21.     @Test(timeout=1000)
  22.     public void testConstructorAndGettersX() {
  23.         Sphere dummySphere = new Sphere(sphereX, sphereY, sphereZ, sphereRadius);
  24.        
  25.         assertEquals("getX() does not return the value used during construction", sphereX, dummySphere.getX(), delta);
  26.     }
  27.    
  28.     @Test(timeout=1000)
  29.     public void testConstructorAndGettersY() {
  30.         Sphere dummySphere = new Sphere(new Point(sphereX, sphereY, sphereZ), sphereRadius);
  31.         assertEquals("getY() does not return the value used during construction", sphereY, dummySphere.getY(), delta);
  32.     }
  33.    
  34.     @Test(timeout=1000)
  35.     public void testConstructorAndGettersZ() {
  36.         Sphere dummySphere = new Sphere(new Point(sphereX, sphereY, sphereZ), sphereRadius);
  37.        
  38.         assertEquals("getZ() does not return the value used during construction", sphereZ, dummySphere.getZ(), delta);
  39.     }
  40.  
  41.     @Test(timeout=1000)
  42.     public void testCalculateDiameter() {
  43.         Sphere dummySphere = new Sphere(new Point(sphereX, sphereY, sphereZ), sphereRadius);
  44.         System.out.println("Expected diameter " + 2*sphereRadius + "Instead found: "+dummySphere.calculateDiameter());
  45.         assertEquals("calculateDiameter() does not return the twice the radius", 2*sphereRadius, dummySphere.calculateDiameter(), delta);
  46.     }
  47.    
  48.     /* Feel free to implement more tests. */
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement