PointTest.java
01 package fr.isae.geometry;
02 
03 import org.junit.*;
04 import static org.junit.Assert.*;
05 
06 /**
07  *  Unit Test for class Point.
08  *
09  *
10  * Created: Mon Oct 30 16:30:12 2006
11  *
12  @author <a href="mailto:garion@isae.fr">Christophe Garion</a>
13  @version 1.0
14  */
15 public class PointTest {
16 
17     private Point p1;
18     private Point p2;
19 
20     private static final double EPS = 1E-9;
21 
22     /**
23      * Setup for the tests.
24      */
25     @Before public void setUp() {
26         p1 = new Point(0.00.0);
27         p2 = new Point(5.06.0);
28     }
29 
30     /**
31      * Cleanup for the tests.
32      */
33     @After public void tearDown() {
34 
35     }
36 
37     /**
38      * Basic test for translater.
39      */
40     @Test public void testTranslaterBasic() {
41         p2.translater(3.06.0);
42         assertEquals(8.0, p2.getX(), EPS);
43         assertEquals(12.0, p2.getY(), EPS);
44     }
45 
46     /**
47      * Test for translater with null vector.
48      */
49     @Test public void testTranslaterNullVector() {
50         p2.translater(0.00.0);
51         assertEquals(5.0, p2.getX(), EPS);
52         assertEquals(6.0, p2.getY(), EPS);
53     }
54 
55     /**
56      * Test for translater: going back!
57      */
58     @Test public void testTranslaterBack() {
59         Point pold = p2.clone();
60         p2.translater(2.03.0);
61         p2.translater(-2.0, -3.0);
62         assertEquals(pold.getX(), p2.getX(), EPS);
63         assertEquals(pold.getY(), p2.getY(), EPS);
64     }
65 
66     /**
67      * Test method for distance.
68      */
69     @Test public void testDistance() {
70         assertEquals(7.810249676, p1.distance(p2), EPS);
71     }
72 
73     /**
74      * Test method for equals.
75      */
76     @Test public void testEquals() {
77         assertTrue(p1.equals(p1));
78         assertFalse(p1.equals(p2));
79         assertFalse(p2.equals(p1));
80 
81         p2.setX(p1.getX());
82         p2.setY(p1.getY());
83 
84         assertTrue(p1.equals(p2));
85         assertTrue(p2.equals(p1));
86     }
87 }