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

Revision 185, 5.1 KB checked in by jtorres, 9 years ago (diff)

HighwaysTest?.java, LoadHighwaysTest?.java, LoadSadDotsTest?.java: configured Highways initialization to reflect new configuration, but the tests obviously still fail. branches/FEPSimulator: removed tinxml/ and unlinked the tinyxml library in project configuration

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