import org.junit.Test; import static org.junit.Assert.*; public class CampusMapTest { public static final double MAX_DIFFERENCE = 0.00001; // Delta used for floating-point comparisons private CampusMap map; @org.junit.Before public void setUp() throws Exception { map = new CampusMap("Map.txt"); } @Test public void testParsePointSimple() { PointOfInterest p = CampusMap.parsePoint("0 0.5 0.4 candy machine"); assertEquals(p.getName(), "candy machine"); assertEquals(p.getScreenX(), 0.5, MAX_DIFFERENCE); assertEquals(p.getScreenY(), 0.4, MAX_DIFFERENCE); assertFalse(p.isIntersection()); } @Test public void testParsePointSimple2() { PointOfInterest p = CampusMap.parsePoint("1 0.1 0.2 Pepsi soda machine"); assertEquals(p.getName(), "Pepsi soda machine"); assertEquals(p.getScreenX(), 0.1, MAX_DIFFERENCE); assertEquals(p.getScreenY(), 0.2, MAX_DIFFERENCE); assertTrue(p.isIntersection()); } @Test public void testMapFileRead() { System.out.println("Number of POIs: " + map.pointsOfInterest.size()); PointOfInterest p1 = map.pointsOfInterest.get("campus cafeteria"); PointOfInterest p2 = map.pointsOfInterest.get("Aquafina machine"); PointOfInterest p3 = map.pointsOfInterest.get("candy machine"); assertEquals(p1.getScreenX(), 150, MAX_DIFFERENCE); assertEquals(p1.getScreenY(), 400, MAX_DIFFERENCE); assertFalse(p1.isIntersection()); assertEquals(p2.getScreenX(), 100, MAX_DIFFERENCE); assertEquals(p2.getScreenY(), 200, MAX_DIFFERENCE); assertTrue(p2.isIntersection()); assertEquals(p3.getScreenX(), 500, MAX_DIFFERENCE); assertEquals(p3.getScreenY(), 590, MAX_DIFFERENCE); assertFalse(p3.isIntersection()); } }