source: tmcsimulator/trunk/test/atmsdriver/model/LoadHighwaysTest.java @ 89

Revision 89, 6.0 KB checked in by jtorres, 9 years ago (diff)

trunk/test/atmsdriver/model/LoadHighwaysTest.java added test to ensure highways are loaded and sorted by postmile. Renamed NetworkTest?.java to HighwaysTest?.java

Line 
1package atmsdriver.model;
2
3import atmsdriver.ATMSDriver;
4import atmsdriver.model.Station.DIRECTION;
5import java.io.File;
6import java.io.FileWriter;
7import java.io.PrintWriter;
8import java.nio.file.FileSystems;
9import java.nio.file.Files;
10import java.nio.file.Path;
11import java.util.ArrayList;
12import junit.framework.TestCase;
13
14/**
15 *
16 * @author jdalbey
17 */
18public class LoadHighwaysTest extends TestCase {
19
20    public LoadHighwaysTest(String testName) {
21        super(testName);
22    }
23
24    @Override
25    protected void setUp() throws Exception {
26        super.setUp();
27        PrintWriter writer = null;
28        try {
29            writer = new PrintWriter(new FileWriter("test/atmsdriver/model/lds_loadhighways_sample.txt"));
30           
31            writer.println("lds_id      line    drop sch lineinfo       system_key      sch_seq glo_seq         count   freeway Dir     ca_pm   lds_name");
32            writer.println("1203081     6       17      2       2       1123005691      26491   1357639         19      55      N       4.58    BRISTOL");
33            writer.println("1210163     6       20      2       2       1123005691      26491   1357639         19      55      N       5.51    PAULARINO 1");
34            writer.println("1203244     50      4       13      13      1123005873      24148   1357650         19      55      N       10      MCFADDEN");
35            writer.println("1203211     50      5       13      13      1123005873      24148   1357650         19      55      N       9.41    EDINGER 2");
36           
37            writer.println("1203261     23      14      23      21      1123005995      26479   1357626         18      55      S       10.4    S OF 5");
38            writer.println("1203083     6       18      2       2       1123005691      26491   1357639         19      55      S       4.7     BAKER 1");
39            writer.println("1210174     6       19      2       2       1123005691      26491   1357639         19      55      S       5.06    BAKER 2");
40            writer.println("1203270     23      15      23      21      1123005995      26479   1357626         18      55      S       10.5    N OF 5");
41           
42            writer.println("1205238     22      16      4       4       1123005726      26490   1357624         19      5       S       32.25   17TH 1");
43            writer.println("1205208     22      17      4       4       1123005726      26490   1357624         19      5       S       31.6    GRAND 1");
44            writer.println("1205270     5       19      1       1       1123005673      26492   1357648         20      5       S       33      MAIN 1   ");
45           
46
47            writer.close();
48        } catch (Exception e) {
49            e.printStackTrace();
50        }
51    }
52
53    @Override
54    protected void tearDown() throws Exception {
55        super.tearDown();
56        Path path = FileSystems.getDefault().getPath("test/atmsdriver/model", "lds_loadhighways_sample.txt");
57        Files.delete(path);
58    }
59
60    /**
61     * Test of toXML method, of class Network.
62     */
63    public void testLoadHighways() {
64        System.out.println("toXML");
65        Highways highways = new Highways(
66                "test/atmsdriver/model/lds_loadhighways_sample.txt",
67                "config/vds_data/loop.txt",
68                "config/vds_data/highwaysMeta.txt",
69                "localhost", 8080);
70       
71        // Test for correct number of highways
72        ArrayList<Highway> result = highways.getHighways();
73        assertEquals(3, result.size());
74       
75        // Test 55 N was loaded
76        Highway fiftyfiveN = result.get(2);
77        assertEquals(new Integer(55), fiftyfiveN.getRouteNumber());
78        assertEquals(DIRECTION.NORTH, fiftyfiveN.getDirection());
79       
80        // Test 55 N stations are sorted by postmile
81        ArrayList<Station> stations = fiftyfiveN.getStations();
82        ArrayList<Double> stationsPostmiles = new ArrayList<>();
83        for(Station station : stations)
84        {
85            stationsPostmiles.add(station.getPostmile());
86        }
87        ArrayList<Double> expectedStationsPostmiles = new ArrayList<>();
88        expectedStationsPostmiles.add(new Double(4.58));
89        expectedStationsPostmiles.add(new Double(5.51));
90        expectedStationsPostmiles.add(new Double(9.41));
91        expectedStationsPostmiles.add(new Double(10));
92        for(int i = 0; i < 4; i++)
93        {
94            assertEquals(expectedStationsPostmiles.get(i), 
95                    stationsPostmiles.get(i));
96        }
97       
98        // Test 55 S was loaded
99        Highway fiftyfiveS = result.get(0);
100        assertEquals(new Integer(55), fiftyfiveS.getRouteNumber());
101        assertEquals(DIRECTION.SOUTH, fiftyfiveS.getDirection());
102       
103        // Test 55 S stations are sorted by postmile
104        stations = fiftyfiveS.getStations();
105        stationsPostmiles.clear();
106        for(Station station : stations)
107        {
108            stationsPostmiles.add(station.getPostmile());
109        }
110        expectedStationsPostmiles.clear();
111        expectedStationsPostmiles.add(new Double(4.7));
112        expectedStationsPostmiles.add(new Double(5.06));
113        expectedStationsPostmiles.add(new Double(10.4));
114        expectedStationsPostmiles.add(new Double(10.5));
115        for(int i = 0; i < 4; i++)
116        {
117            assertEquals(expectedStationsPostmiles.get(i), 
118                    stationsPostmiles.get(i));
119        }
120       
121        Highway fiveS = result.get(1);
122        assertEquals(new Integer(5), fiveS.getRouteNumber());
123        assertEquals(DIRECTION.SOUTH, fiveS.getDirection());
124       
125        // Test 5 S stations are sorted by postmile
126        stations = fiveS.getStations();
127        stationsPostmiles.clear();
128        for(Station station : stations)
129        {
130            stationsPostmiles.add(station.getPostmile());
131        }
132        expectedStationsPostmiles.clear();
133        expectedStationsPostmiles.add(new Double(31.6));
134        expectedStationsPostmiles.add(new Double(32.25));
135        expectedStationsPostmiles.add(new Double(33));
136        for(int i = 0; i < 2; i++)
137        {
138            assertEquals(expectedStationsPostmiles.get(i), 
139                    stationsPostmiles.get(i));
140        }
141    }
142}
Note: See TracBrowser for help on using the repository browser.