source: tmcsimulator/trunk/test/tmcsim/cadsimulator/managers/TrafficModelManagerTest.java @ 204

Revision 204, 2.3 KB checked in by jdalbey, 9 years ago (diff)

TrafficModelManager?.java Refactor for code sharing with TrafficModelEventDriver?. Write unit test.

Line 
1
2package tmcsim.cadsimulator.managers;
3
4import atmsdriver.model.TrafficEvent;
5import java.text.ParseException;
6import java.util.LinkedList;
7import java.util.List;
8import java.util.Map;
9import java.util.Scanner;
10import junit.framework.TestCase;
11import tmcsim.common.SimulationException;
12
13/**
14 *
15 * @author jdalbey
16 */
17public class TrafficModelManagerTest extends TestCase
18{
19   
20    public TrafficModelManagerTest(String testName)
21    {
22        super(testName);
23    }
24   
25    @Override
26    protected void setUp() throws Exception
27    {
28        super.setUp();
29    }
30   
31    @Override
32    protected void tearDown() throws Exception
33    {
34        super.tearDown();
35    }
36
37    /**
38     * Test of readBatchFile method, of class TrafficModelManager.
39     */
40    public void testReadBatchFile() throws SimulationException, ParseException
41    {
42        System.out.println("readBatchFile");
43        String alpha = "181 00:00:01 405 N 2.2 20.1 Y";
44        String bravo = "187 00:00:37  55 S 6.88 0.2 R";
45        String dataIn = alpha + "\n" + bravo + "\n";
46        Scanner scan = new Scanner(dataIn);
47        TrafficEvent evtA = new TrafficEvent(alpha);
48        TrafficEvent evtB = new TrafficEvent(bravo);
49       
50        LinkedList<TrafficEvent> expResult = new LinkedList<TrafficEvent>();
51        expResult.add(evtA);
52        expResult.add(evtB);
53       
54        LinkedList<TrafficEvent> result = TrafficModelManager.readBatchFile(scan);
55        assertEquals(expResult, result);
56    }
57   
58    public void testCreateIncidentMap() throws ParseException
59    {
60        System.out.println("createIncidentMap");
61        String alpha = "181 00:00:01 405 N 2.2 20.1 Y";
62        String bravo = "187 00:00:37  55 S 6.88 0.2 R";
63        String dataIn = alpha + "\n" + bravo + "\n";
64        Scanner scan = new Scanner(dataIn);
65        TrafficEvent evtA = new TrafficEvent(alpha);
66        TrafficEvent evtB = new TrafficEvent(bravo);
67     
68        LinkedList<TrafficEvent> eventQueue = TrafficModelManager.readBatchFile(scan);
69        // Extract the incidents and create a map
70        Map<String, List<TrafficEvent>> incidents;
71        incidents = TrafficModelManager.createIncidentMap(eventQueue);
72        System.out.println(""+incidents.keySet());
73        assertTrue(incidents.keySet().contains("181"));
74        assertTrue(incidents.keySet().contains("187"));
75    }
76 
77}
Note: See TracBrowser for help on using the repository browser.