source: tmcsimulator/trunk/test/atmsdriver/model/TrafficEventTest.java @ 183

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

ATMSBatchDriver.java Enhanced to automatically sort events chronologically (using new class TrafficEvent?).

Line 
1
2package atmsdriver.model;
3
4import java.text.ParseException;
5import java.util.PriorityQueue;
6import junit.framework.TestCase;
7
8/**
9 *
10 * @author jdalbey
11 */
12public class TrafficEventTest extends TestCase
13{
14   
15    public TrafficEventTest(String testName)
16    {
17        super(testName);
18    }
19   
20    @Override
21    protected void setUp() throws Exception
22    {
23        super.setUp();
24    }
25   
26    @Override
27    protected void tearDown() throws Exception
28    {
29        super.tearDown();
30    }
31
32    /**
33     * Test of compareTo method, of class TrafficEvent.
34     */
35    public void testCompareTo() throws ParseException
36    {
37        System.out.println("compareTo");
38        TrafficEvent alpha = new TrafficEvent("181 00:01:30 405 S 0.6 11.0 G");
39        TrafficEvent beta  = new TrafficEvent("181 00:12:30 405 S 0.6 11.0 G");
40        TrafficEvent charly  = new TrafficEvent("181 00:22:00 5 S 0.6 11.0 G");
41        assertEquals(-1, alpha.compareTo(beta));
42        assertEquals(1, charly.compareTo(beta));
43        assertEquals(0, beta.compareTo(beta));
44    }
45    public void testCompare2() throws ParseException
46    {
47        System.out.println("compareTo");
48        TrafficEvent alpha = new TrafficEvent(" 187   00:00:07  55      S         6.88     0.2      Y");
49        TrafficEvent beta  = new TrafficEvent(" 187   00:01:37  55      S         6.88     0.2      R");
50        TrafficEvent charly  = new TrafficEvent("191   02:49:02  73      S         27.20    0.8      G");
51        assertEquals(-1, alpha.compareTo(beta));
52        assertEquals(1, charly.compareTo(beta));
53        assertEquals(0, beta.compareTo(beta));
54    }
55    public void testQueue() throws ParseException
56    {
57        System.out.println("compareTo");
58        TrafficEvent alpha = new TrafficEvent(" 187   00:00:07  55      S         6.88     0.2      Y");
59        TrafficEvent beta  = new TrafficEvent(" 187   00:01:37  55      S         6.88     0.2      R");
60        TrafficEvent charly  = new TrafficEvent("191   02:49:02  73      S         27.20    0.8      G");
61        PriorityQueue<TrafficEvent> q = new PriorityQueue<TrafficEvent>();
62        q.add(charly);
63        q.add(beta);
64        q.add(alpha);
65        assertEquals(alpha, q.poll());
66        assertEquals(beta, q.poll());
67        assertEquals(charly, q.poll());
68    }
69   
70}
Note: See TracBrowser for help on using the repository browser.