| 1 | |
|---|
| 2 | package tmcsim.cadsimulator.managers; |
|---|
| 3 | |
|---|
| 4 | import tmcsim.highwaymodel.TrafficEvent; |
|---|
| 5 | import java.text.ParseException; |
|---|
| 6 | import java.util.LinkedList; |
|---|
| 7 | import java.util.List; |
|---|
| 8 | import java.util.Map; |
|---|
| 9 | import java.util.Scanner; |
|---|
| 10 | import junit.framework.TestCase; |
|---|
| 11 | import tmcsim.common.SimulationException; |
|---|
| 12 | |
|---|
| 13 | /** |
|---|
| 14 | * |
|---|
| 15 | * @author jdalbey |
|---|
| 16 | */ |
|---|
| 17 | public 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 | public void testReadBatchFile() throws SimulationException, ParseException |
|---|
| 38 | { |
|---|
| 39 | System.out.println("readBatchFile"); |
|---|
| 40 | String alpha = "181 00:00:01 405 N 2.2 20.1 Y"; |
|---|
| 41 | String bravo = "187 00:00:37 55 S 6.88 0.2 R"; |
|---|
| 42 | String dataIn = alpha + "\n" + bravo + "\n"; |
|---|
| 43 | Scanner scan = new Scanner(dataIn); |
|---|
| 44 | TrafficEvent evtA = new TrafficEvent(alpha); |
|---|
| 45 | TrafficEvent evtB = new TrafficEvent(bravo); |
|---|
| 46 | |
|---|
| 47 | LinkedList<TrafficEvent> expResult = new LinkedList<TrafficEvent>(); |
|---|
| 48 | expResult.add(evtA); |
|---|
| 49 | expResult.add(evtB); |
|---|
| 50 | |
|---|
| 51 | LinkedList<TrafficEvent> result = TrafficModelManager.readBatchFile(scan); |
|---|
| 52 | assertEquals(expResult, result); |
|---|
| 53 | } |
|---|
| 54 | /** |
|---|
| 55 | * Test of readBatchFile method, of class TrafficModelManager. |
|---|
| 56 | */ |
|---|
| 57 | public void testReadBatchFile2() throws SimulationException, ParseException |
|---|
| 58 | { |
|---|
| 59 | System.out.println("readBatchFile blank lines test"); |
|---|
| 60 | String alpha = " "; |
|---|
| 61 | String bravo = "187 00:00:37 55 S 6.88 0.2 R"; |
|---|
| 62 | String dataIn = alpha + "\n" + bravo + "\n"; |
|---|
| 63 | Scanner scan = new Scanner(dataIn); |
|---|
| 64 | |
|---|
| 65 | LinkedList<TrafficEvent> result = TrafficModelManager.readBatchFile(scan); |
|---|
| 66 | assertEquals(1,result.size()); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | public void testCreateIncidentMap() throws ParseException |
|---|
| 70 | { |
|---|
| 71 | System.out.println("createIncidentMap"); |
|---|
| 72 | String alpha = "181 00:00:01 405 N 2.2 20.1 Y"; |
|---|
| 73 | String bravo = "187 00:00:37 55 S 6.88 0.2 R"; |
|---|
| 74 | String dataIn = alpha + "\n" + bravo + "\n"; |
|---|
| 75 | Scanner scan = new Scanner(dataIn); |
|---|
| 76 | TrafficEvent evtA = new TrafficEvent(alpha); |
|---|
| 77 | TrafficEvent evtB = new TrafficEvent(bravo); |
|---|
| 78 | |
|---|
| 79 | LinkedList<TrafficEvent> eventQueue = TrafficModelManager.readBatchFile(scan); |
|---|
| 80 | // Extract the incidents and create a map |
|---|
| 81 | Map<String, List<TrafficEvent>> incidents; |
|---|
| 82 | incidents = TrafficModelManager.createIncidentMap(eventQueue); |
|---|
| 83 | System.out.println(""+incidents.keySet()); |
|---|
| 84 | assertTrue(incidents.keySet().contains("181")); |
|---|
| 85 | assertTrue(incidents.keySet().contains("187")); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | } |
|---|