Warning: Can't use blame annotator:
svn blame failed on trunk/test/atmsdriver/model/LoadHighwaysTest.java: ("Can't find a temporary directory: Internal error", 20014)

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

Revision 103, 5.2 KB checked in by jtorres, 9 years ago (diff)

trunk/src/atmsdriver/ConsoleDriver.java: Created console driver for ATMSDriver, completed and very nice. Still need to apply correct vol/occ values to actually change the colors. Still need to write a JUnit test for it. trunk/src/atmsdriver/ATMSDriver.java: Refactored to run the console driver. ATMSDriver runs in thread, console driver runs, and they share the highways instance. Renamed NetworkLoader?.java to FEPLineLoader.java. trunk/src/atmsdriver/model/Highways.java: refactored loadHighways() method to conform to new undirected highway abstraction. trunk/src/atmsdriver/model/Station.java: added updateByDirection(DIRECTION dir) method and supporting utility methods. trunk/test/atmsdriver/model/LoadHighwaysTest.java: Conformed LoadHighways? test to new undirected highway abstraction. trunk/test/atmsdriver/model/StationTest.java: Conformed StationTest?.java to new changes - very minor stuff. Went through all model classes and changed any final privates with a getter method to final public, for good OOP practice and simplicity. Went through ALL FILES and commented everything very well. minor application custom configuration changes. Removed all .class or .o.d files from svn repository

RevLine 
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                "test/atmsdriver/model/lds_loadhighways_sample.txt",
64                "config/vds_data/loop.txt",
65                "config/vds_data/highwaysMeta.txt",
66                "localhost", 8080);
67       
68        // Test for correct number of highways
69        ArrayList<Highway> result = highways.highways;
70        assertEquals(2, result.size());
71       
72        // Test 55 N was loaded
73        Highway fiftyfiveN = result.get(0);
74        assertEquals(new Integer(55), fiftyfiveN.routeNumber);
75       
76        // Test 55 N stations are sorted by postmile
77        ArrayList<Station> stations = fiftyfiveN.stations;
78        ArrayList<Double> stationsPostmiles = new ArrayList<>();
79        for(Station station : stations)
80        {
81            stationsPostmiles.add(station.postmile);
82        }
83       
84        // Create expected station postmile list (sorted)
85        ArrayList<Double> expectedStationsPostmiles = new ArrayList<>();
86        expectedStationsPostmiles.add(new Double(4.58));
87        expectedStationsPostmiles.add(new Double(4.7));
88        expectedStationsPostmiles.add(new Double(5.06));
89        expectedStationsPostmiles.add(new Double(5.51));
90        expectedStationsPostmiles.add(new Double(9.41));
91        expectedStationsPostmiles.add(new Double(10));
92        expectedStationsPostmiles.add(new Double(10.4));
93        expectedStationsPostmiles.add(new Double(10.5));
94        for(int i = 0; i < 8; i++)
95        {
96            assertEquals(expectedStationsPostmiles.get(i), 
97                    stationsPostmiles.get(i));
98        }
99       
100        // Test 55 S was loaded
101        Highway fiftyfiveS = result.get(1);
102        assertEquals(new Integer(5), fiftyfiveS.routeNumber);
103       
104        // Test 55 S stations are sorted by postmile
105        stations = fiftyfiveS.stations;
106        stationsPostmiles.clear();
107        for(Station station : stations)
108        {
109            stationsPostmiles.add(station.postmile);
110        }
111        expectedStationsPostmiles.clear();
112        expectedStationsPostmiles.add(new Double(31.6));
113        expectedStationsPostmiles.add(new Double(32.25));
114        expectedStationsPostmiles.add(new Double(33));
115        for(int i = 0; i < 3; i++)
116        {
117            assertEquals(expectedStationsPostmiles.get(i), 
118                    stationsPostmiles.get(i));
119        }
120    }
121}
Note: See TracBrowser for help on using the repository browser.