package tmcsim.highwaymodel; import tmcsim.highwaymodel.TrafficEvent; import java.text.ParseException; import java.util.PriorityQueue; import junit.framework.TestCase; /** * * @author jdalbey */ public class TrafficEventTest extends TestCase { public TrafficEventTest(String testName) { super(testName); } @Override protected void setUp() throws Exception { super.setUp(); } @Override protected void tearDown() throws Exception { super.tearDown(); } /** * Test of compareTo method, of class TrafficEvent. */ public void testCompareTo() throws ParseException { System.out.println("compareTo"); TrafficEvent alpha = new TrafficEvent("181 00:01:30 405 S 0.6 11.0 G"); TrafficEvent beta = new TrafficEvent("181 00:12:30 405 S 0.6 11.0 G"); TrafficEvent charly = new TrafficEvent("181 00:22:00 5 S 0.6 11.0 G"); assertEquals(-1, alpha.compareTo(beta)); assertEquals(1, charly.compareTo(beta)); assertEquals(0, beta.compareTo(beta)); } public void testCompare2() throws ParseException { System.out.println("compareTo"); TrafficEvent alpha = new TrafficEvent(" 187 00:00:07 55 S 6.88 0.2 Y"); TrafficEvent beta = new TrafficEvent(" 187 00:01:37 55 S 6.88 0.2 R"); TrafficEvent charly = new TrafficEvent("191 02:49:02 73 S 27.20 0.8 G"); assertEquals(-1, alpha.compareTo(beta)); assertEquals(1, charly.compareTo(beta)); assertEquals(0, beta.compareTo(beta)); } public void testQueue() throws ParseException { System.out.println("compareTo"); TrafficEvent alpha = new TrafficEvent(" 187 00:00:07 55 S 6.88 0.2 Y"); TrafficEvent beta = new TrafficEvent(" 187 00:01:37 55 S 6.88 0.2 R"); TrafficEvent charly = new TrafficEvent("191 02:49:02 73 S 27.20 0.8 G"); PriorityQueue q = new PriorityQueue(); q.add(charly); q.add(beta); q.add(alpha); assertEquals(alpha, q.poll()); assertEquals(beta, q.poll()); assertEquals(charly, q.poll()); } }