package tmcsim.cadsimulator.managers; import tmcsim.highwaymodel.TrafficEvent; import java.text.ParseException; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Scanner; import junit.framework.TestCase; import tmcsim.common.SimulationException; /** * * @author jdalbey */ public class TrafficModelManagerTest extends TestCase { public TrafficModelManagerTest(String testName) { super(testName); } @Override protected void setUp() throws Exception { super.setUp(); } @Override protected void tearDown() throws Exception { super.tearDown(); } public void testReadBatchFile() throws SimulationException, ParseException { System.out.println("readBatchFile"); String alpha = "181 00:00:01 405 N 2.2 20.1 Y"; String bravo = "187 00:00:37 55 S 6.88 0.2 R"; String dataIn = alpha + "\n" + bravo + "\n"; Scanner scan = new Scanner(dataIn); TrafficEvent evtA = new TrafficEvent(alpha); TrafficEvent evtB = new TrafficEvent(bravo); LinkedList expResult = new LinkedList(); expResult.add(evtA); expResult.add(evtB); LinkedList result = TrafficModelManager.readBatchFile(scan); assertEquals(expResult, result); } /** * Test of readBatchFile method, of class TrafficModelManager. */ public void testReadBatchFile2() throws SimulationException, ParseException { System.out.println("readBatchFile blank lines test"); String alpha = " "; String bravo = "187 00:00:37 55 S 6.88 0.2 R"; String dataIn = alpha + "\n" + bravo + "\n"; Scanner scan = new Scanner(dataIn); LinkedList result = TrafficModelManager.readBatchFile(scan); assertEquals(1,result.size()); } public void testCreateIncidentMap() throws ParseException { System.out.println("createIncidentMap"); String alpha = "181 00:00:01 405 N 2.2 20.1 Y"; String bravo = "187 00:00:37 55 S 6.88 0.2 R"; String dataIn = alpha + "\n" + bravo + "\n"; Scanner scan = new Scanner(dataIn); TrafficEvent evtA = new TrafficEvent(alpha); TrafficEvent evtB = new TrafficEvent(bravo); LinkedList eventQueue = TrafficModelManager.readBatchFile(scan); // Extract the incidents and create a map Map> incidents; incidents = TrafficModelManager.createIncidentMap(eventQueue); System.out.println(""+incidents.keySet()); assertTrue(incidents.keySet().contains("181")); assertTrue(incidents.keySet().contains("187")); } }