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