Warning: Can't use blame annotator:
svn blame failed on branches/FEPSimulator/tests/HighwaysParserTest.cpp: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/branches/FEPSimulator/tests/HighwaysParserTest.cpp @ 212

Revision 212, 7.3 KB checked in by jtorres, 9 years ago (diff)

branches/FEPSimulator/tests/HighwaysParserTest.cpp: Unit test for HighwaysParser?.cpp. HighwaysTest?.java: now passing toXML(), added test for toCondensedFormat() method. LoadHighwaysTest?.java: passing. LoadSadDotsTest?.java: conformed to changes, not passing. Highway.java/Highways.java: converted class attributes to List instead of ArrayList?. Highways.java: corrected toCondensedFormat() method comments and added comments throughout file.

RevLine 
1/*
2 * File:   HighwaysParserTest.cpp
3 * Author: jtorres
4 *
5 * Created on Nov 1, 2017, 11:59:27 PM
6 */
7
8#include <stdlib.h>
9#include <iostream>
10#include "HighwaysParser.h"
11#include "network.h"
12
13using namespace std;
14
15/*
16 * Simple C++ Test Suite
17 */
18char * createBuffer()
19{
20    char * buffer = "2\n"
21    "32 0 2\n"
22    "1210831 1 5 S 0.9 8\n" 
23    "1210832  0.0 0 ML_1\n"
24    "1210833  0.0 0 ML_2\n"
25    "1210834  0.0 0 ML_3\n"
26    "1210835  0.0 0 ML_4\n"
27    "1210836  0.0 0 PASSAGE\n"
28    "1210837  0.0 0 DEMAND\n"
29    "1210838  0.0 0 QUEUE\n"
30    "1210839  0.0 0 RAMP_OFF\n"
31    "1210845 2 5 S 1.49 9 \n"
32    "1210846  0.0 0 ML_1\n"
33    "1210847  0.0 0 ML_2\n"
34    "1210848  0.0 0 ML_3\n"
35    "1210849  0.0 0 ML_4\n"
36    "1210850  0.0 0 RAMP_ON\n"
37    "1210851  0.0 0 PASSAGE\n"
38    "1210853  0.0 0 DEMAND\n"
39    "1210854  0.0 0 QUEUE\n"
40    "1210855  0.0 0 RAMP_OFF\n"
41    "74 0 1\n"
42    "1204203 2 5 N 1.26 13\n" 
43    "1204205  0.0 0 RAMP_ON\n"
44    "1204206  0.0 0 QUEUE\n"
45    "1204207  0.0 0 DEMAND\n"
46    "1204208  0.0 0 PASSAGE\n"
47    "1204210  0.0 0 RAMP_OFF\n"
48    "1204212  0.0 0 ML_1\n"
49    "1204213  0.0 0 ML_2\n"
50    "1204214  0.0 0 ML_3\n"
51    "1204215  0.0 0 ML_4\n"
52    "1204217  0.0 0 OS_1\n"
53    "1204218  0.0 0 OS_2\n"
54    "1204219  0.0 0 OS_3\n"
55    "1204220  0.0 0 OS_4\n";
56    return buffer;
57}
58
59void testParseLines() {
60    char* highwaysData;
61    HighwaysParser highwaysParser(createBuffer());
62    vector<FEP_LINE *> lines = highwaysParser.lines;
63    vector<STATION *> stations = highwaysParser.stations;
64   
65    // test number of lines
66    int expectedNumLines = 2;
67    int actualNumLines = lines.size();
68    if (expectedNumLines != actualNumLines) {
69        cout << "%TEST_FAILED% time=0 testname=testParseLines (HighwaysParserTest) message=incorrect number of lines" << endl;
70    }
71   
72    // test line nums
73    int expectedLineNums[2] = { 32, 74 };
74    int actualLineNums[2] = { lines.at(0)->lineNum, lines.at(1)->lineNum };
75    for(int i = 0; i < 2; i++)
76    {
77        if(expectedLineNums[i] != actualLineNums[i])
78        {
79            cout << "%TEST_FAILED% time=0 testname=testParseLines (HighwaysParserTest) message=incorrect line_id (LineNum)" << endl;
80        }
81    }
82   
83    // test lds id vector
84    long expectedLDS[2] = { 1210831, 1210845 };
85    long actualLDS[2] = { lines.at(0)->lds.at(0), lines.at(0)->lds.at(1) };
86    for(int i = 0; i < 2; i++)
87    {
88        if(expectedLDS[i] != actualLDS[i])
89        {
90            cout << "%TEST_FAILED% time=0 testname=testParseLines (HighwaysParserTest) message=incorrect lds" << endl;
91        }
92    }
93   
94    // test lds index vector
95    long expectedLDSIndex[2] = { 0, 1 };
96    long actualLDSIndex[2] = { lines.at(0)->ldsIndex.at(0), lines.at(0)->ldsIndex.at(1) };
97    for(int i = 0; i < 2; i++)
98    {
99        if(expectedLDSIndex[i] != actualLDSIndex[i])
100        {
101            cout << "%TEST_FAILED% time=0 testname=testParseLines (HighwaysParserTest) message=incorrect lds index" << endl;
102        }
103    }
104   
105    // test number of stations
106    int expectedNumStations = 3;
107    int actualNumStations = stations.size();
108   
109    if(expectedNumStations != actualNumStations)
110    {
111        cout << "%TEST_FAILED% time=0 testname=testParseLines (HighwaysParserTest) message=incorrect number of stations" << endl;
112    }
113   
114    // test drop number
115    int expectedDropNums[3] = { 1, 2, 2 };
116    int actualDropNums[3] = { stations.at(0)->drop, stations.at(1)->drop, stations.at(2)->drop };
117    for(int i = 0; i < 3; i++)
118    {
119        if(expectedDropNums[i] != actualDropNums[i])
120        {
121            cout << "%TEST_FAILED% time=0 testname=testParseLines (HighwaysParserTest) message=incorrect drop number" << endl;
122        }
123    }
124   
125    // test station lds numbers
126    long expectedLDSNums[3] = { 1210831, 1210845, 1204203 };
127    long actualLDSNums[3] = { stations.at(0)->lds, stations.at(1)->lds, stations.at(2)->lds };
128    for(int i = 0; i < 3; i++)
129    {
130        if(expectedLDSNums[i] != actualLDSNums[i])
131        {
132            cout << "%TEST_FAILED% time=0 testname=testParseLines (HighwaysParserTest) message=incorrect station drop number" << endl;
133        }
134    }
135   
136    // test station line nums
137    short expectedStnLineNums[3] = {32, 32, 74};
138    short actualStnLineNums[3] = {stations.at(0)->line_num, stations.at(1)->line_num, stations.at(2)->line_num};
139    for(int i = 0; i < 3; i++)
140    {
141        if(expectedStnLineNums[i] != actualStnLineNums[i])
142        {
143            cout << "%TEST_FAILED% time=0 testname=testParseLines (HighwaysParserTest) message=incorrect station line number" << endl;
144        }
145    }
146   
147    // test number of loops
148    int expectedNumberOfLoops = 30;
149    int actualNumberOfLoops = stations.at(0)->loops.size() + stations.at(1)->loops.size() + stations.at(2)->loops.size();
150   
151    if(expectedNumberOfLoops != actualNumberOfLoops)
152    {
153        cout << "%TEST_FAILED% time=0 testname=testParseLines (HighwaysParserTest) message=incorrect number of loops" << endl;
154    }
155   
156    // test loops
157    vector<LOOP *> loopsOne = stations.at(0)->loops;
158   
159    // test loopIDS
160    long expectedLoopIDS[8] = { 1210832, 1210833, 1210834, 1210835, 
161            1210836, 1210837, 1210838, 1210839 };
162    long actualLoopIDS[8] = { loopsOne.at(0)->loopID, loopsOne.at(1)->loopID, 
163            loopsOne.at(2)->loopID, loopsOne.at(3)->loopID, 
164            loopsOne.at(4)->loopID, loopsOne.at(5)->loopID,
165            loopsOne.at(6)->loopID, loopsOne.at(7)->loopID };
166    for(int i = 0; i < 8; i++)
167    {
168        if(expectedLoopIDS[i] != actualLoopIDS[i])
169        {
170            cout << "%TEST_FAILED% time=0 testname=testParseLines (HighwaysParserTest) message=incorrect loop IDS" << endl;
171        }
172    }
173   
174    // test loop occ
175    float expectedOCC[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
176    float actualOCC[8] = { loopsOne.at(0)->occ, loopsOne.at(1)->occ, 
177            loopsOne.at(2)->occ, loopsOne.at(3)->occ, loopsOne.at(4)->occ, 
178            loopsOne.at(5)->occ, loopsOne.at(6)->occ, loopsOne.at(7)->occ };
179    for(int i = 0; i < 8; i++)
180    {
181        if(expectedOCC[i] != actualOCC[i])
182        {
183            cout << "%TEST_FAILED% time=0 testname=testParseLines (HighwaysParserTest) message=incorrect loop IDS" << endl;
184        }
185    }
186   
187    // test loop locations
188    char * expectedLocs[8] = {"ML_1", "ML_2", "ML_3", "ML_4", "PASSAGE", "DEMAND",
189            "QUEUE", "RAMP_OFF"};
190    char * actualLocs[8] = { loopsOne.at(0)->loop_loc, loopsOne.at(1)->loop_loc,
191            loopsOne.at(2)->loop_loc, loopsOne.at(3)->loop_loc, loopsOne.at(4)->loop_loc,
192            loopsOne.at(5)->loop_loc, loopsOne.at(6)->loop_loc, loopsOne.at(7)->loop_loc };
193
194    for(int i = 0; i < 8; i++)
195    {
196        if(strcmp(expectedLocs[i], actualLocs[i]) != 0)
197        {
198            cout << "EXPECTED: " << expectedLocs[i] << endl;
199            cout << "ACTUAL: " << actualLocs[i] << endl;
200            cout << "%TEST_FAILED% time=0 testname=testParseLines (HighwaysParserTest) message=incorrect loop locs" << endl;
201        }
202    }
203}
204
205int main(int argc, char** argv) {
206    cout << "%SUITE_STARTING% HighwaysParserTest" << endl;
207    cout << "%SUITE_STARTED%" << endl;
208
209    cout << "%TEST_STARTED% testParseLines (HighwaysParserTest)" << endl;
210    testParseLines();
211    cout << "%TEST_FINISHED% time=0 testParseLines (HighwaysParserTest)" << endl;
212
213    cout << "%SUITE_FINISHED% time=0" << endl;
214
215    return (EXIT_SUCCESS);
216}
217
Note: See TracBrowser for help on using the repository browser.