| 1 | |
|---|
| 2 | package tmcsim.highwaymodel; |
|---|
| 3 | |
|---|
| 4 | import tmcsim.highwaymodel.LoopDetector; |
|---|
| 5 | import tmcsim.highwaymodel.Station; |
|---|
| 6 | import tmcsim.highwaymodel.Station.DIRECTION; |
|---|
| 7 | import java.util.ArrayList; |
|---|
| 8 | import junit.framework.TestCase; |
|---|
| 9 | import org.w3c.dom.Element; |
|---|
| 10 | |
|---|
| 11 | /** |
|---|
| 12 | * |
|---|
| 13 | * @author jdalbey |
|---|
| 14 | */ |
|---|
| 15 | public class StationTest extends TestCase { |
|---|
| 16 | Station alpha; |
|---|
| 17 | public StationTest(String testName) { |
|---|
| 18 | super(testName); |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | @Override |
|---|
| 22 | protected void setUp() throws Exception { |
|---|
| 23 | super.setUp(); |
|---|
| 24 | alpha = new Station(1,2,3,"A",new ArrayList<LoopDetector>(), 4, DIRECTION.NORTH, 1.0); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | @Override |
|---|
| 28 | protected void tearDown() throws Exception { |
|---|
| 29 | super.tearDown(); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | /** |
|---|
| 33 | * Test of getHighwayNumber method, of class Station. |
|---|
| 34 | */ |
|---|
| 35 | public void testGetHighwayNumber() { |
|---|
| 36 | System.out.println("getHighwayNumber"); |
|---|
| 37 | assertEquals(4, alpha.routeNumber); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | * Test of getDirection method, of class Station. |
|---|
| 42 | */ |
|---|
| 43 | public void testGetDirection() { |
|---|
| 44 | System.out.println("getDirection"); |
|---|
| 45 | assertEquals(DIRECTION.NORTH, alpha.direction); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | /** |
|---|
| 49 | * Test of getPostmile method, of class Station. |
|---|
| 50 | */ |
|---|
| 51 | public void testGetPostmile() { |
|---|
| 52 | System.out.println("getPostmile"); |
|---|
| 53 | assertEquals(1.0, alpha.postmile,0.1); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | /** |
|---|
| 57 | * Test of compareTo method, of class Station. |
|---|
| 58 | */ |
|---|
| 59 | public void testCompareTo() { |
|---|
| 60 | System.out.println("compareTo"); |
|---|
| 61 | Station beta = new Station(1,2,3,"B",new ArrayList<LoopDetector>(), 4, DIRECTION.NORTH, 2.0); |
|---|
| 62 | int expResult = 0; |
|---|
| 63 | assertEquals(-1, alpha.compareTo(beta)); |
|---|
| 64 | assertEquals(1, beta.compareTo(alpha)); |
|---|
| 65 | assertEquals(0, beta.compareTo(beta)); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | public void testMatches() |
|---|
| 69 | { |
|---|
| 70 | Station alpha = new Station(1,2,3,"A",new ArrayList<LoopDetector>(), 4, DIRECTION.NORTH, 2.0); |
|---|
| 71 | assertTrue(alpha.matches(DIRECTION.NORTH, 2.0)); |
|---|
| 72 | assertFalse(alpha.matches(DIRECTION.NORTH,2.1)); |
|---|
| 73 | } |
|---|
| 74 | /** |
|---|
| 75 | * Test get Color and LoopDetector accessors |
|---|
| 76 | */ |
|---|
| 77 | public void testGetColor() |
|---|
| 78 | { |
|---|
| 79 | LoopDetector lane = new LoopDetector(999,"locid","loc"); |
|---|
| 80 | ArrayList<LoopDetector> lanes = new ArrayList<LoopDetector>(); |
|---|
| 81 | lanes.add(lane); |
|---|
| 82 | Station alpha = new Station(1,2,3,"A",lanes, 4, DIRECTION.NORTH, 2.0); |
|---|
| 83 | assertEquals('-',alpha.getColor().symbol()); |
|---|
| 84 | assertEquals("lime",alpha.getColor().htmlColor()); |
|---|
| 85 | lane.setAttributes(LoopDetector.DOTCOLOR.YELLOW); |
|---|
| 86 | assertEquals('+',alpha.getColor().symbol()); |
|---|
| 87 | assertEquals("yellow",alpha.getColor().htmlColor()); |
|---|
| 88 | lane.setAttributes(LoopDetector.DOTCOLOR.RED); |
|---|
| 89 | assertEquals('@',alpha.getColor().symbol()); |
|---|
| 90 | assertEquals("red",alpha.getColor().htmlColor()); |
|---|
| 91 | } |
|---|
| 92 | } |
|---|