| 1 | |
|---|
| 2 | package tmcsim.highwaymodel; |
|---|
| 3 | |
|---|
| 4 | import tmcsim.highwaymodel.PostmileCoords; |
|---|
| 5 | import java.io.FileInputStream; |
|---|
| 6 | import java.io.FileNotFoundException; |
|---|
| 7 | import java.util.Iterator; |
|---|
| 8 | import java.util.Scanner; |
|---|
| 9 | import junit.framework.TestCase; |
|---|
| 10 | |
|---|
| 11 | /** |
|---|
| 12 | * |
|---|
| 13 | * @author jdalbey |
|---|
| 14 | */ |
|---|
| 15 | public class PostmileCoordsTest extends TestCase |
|---|
| 16 | { |
|---|
| 17 | private PostmileCoords pmc; |
|---|
| 18 | |
|---|
| 19 | public PostmileCoordsTest(String testName) |
|---|
| 20 | { |
|---|
| 21 | super(testName); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | @Override |
|---|
| 25 | protected void setUp() throws Exception |
|---|
| 26 | { |
|---|
| 27 | super.setUp(); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | @Override |
|---|
| 31 | protected void tearDown() throws Exception |
|---|
| 32 | { |
|---|
| 33 | super.tearDown(); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | public void testLoad() throws FileNotFoundException |
|---|
| 37 | { |
|---|
| 38 | |
|---|
| 39 | System.out.println("load"); |
|---|
| 40 | String line1 = "5 N 4.02, 33.33, -117.117,Dyer Rd\n5 S 3.56, 33.33, -117.117,Dyer Rd"; |
|---|
| 41 | Scanner scan = new Scanner(line1).useDelimiter("\\A"); |
|---|
| 42 | pmc = new PostmileCoords(); |
|---|
| 43 | pmc.load(scan); |
|---|
| 44 | PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33", |
|---|
| 45 | "-117.117","Dyer Rd"); |
|---|
| 46 | assertEquals(pm,pmc.get(0)); |
|---|
| 47 | assert(pmc.size() == 2); |
|---|
| 48 | } |
|---|
| 49 | public void testLoadwithPrefix() throws FileNotFoundException |
|---|
| 50 | { |
|---|
| 51 | System.out.println("load"); |
|---|
| 52 | String line1 = "5 N R4.02, 33.33, -117.117,Dyer Rd\n5 S 3.56, 33.33, -117.117,Dyer Rd"; |
|---|
| 53 | Scanner scan = new Scanner(line1).useDelimiter("\\A"); |
|---|
| 54 | pmc = new PostmileCoords(); |
|---|
| 55 | pmc.load(scan); |
|---|
| 56 | PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33", |
|---|
| 57 | "-117.117","Dyer Rd","0","0"); |
|---|
| 58 | assertEquals(pm,pmc.get(0)); |
|---|
| 59 | assert(pmc.size() == 2); |
|---|
| 60 | } |
|---|
| 61 | public void testLoadNoPerps() throws FileNotFoundException |
|---|
| 62 | { |
|---|
| 63 | |
|---|
| 64 | System.out.println("load"); |
|---|
| 65 | String line1 = "5 N 4.02, 33.33, -117.117,Dyer Rd,\n5 S 3.56, 33.33, -117.117,Dyer Rd,"; |
|---|
| 66 | Scanner scan = new Scanner(line1).useDelimiter("\\A"); |
|---|
| 67 | pmc = new PostmileCoords(); |
|---|
| 68 | pmc.load(scan); |
|---|
| 69 | PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33", |
|---|
| 70 | "-117.117","Dyer Rd","0","0"); |
|---|
| 71 | assertEquals(pm,pmc.get(0)); |
|---|
| 72 | assert(pmc.size() == 2); |
|---|
| 73 | } |
|---|
| 74 | public void testLoadPerps() throws FileNotFoundException |
|---|
| 75 | { |
|---|
| 76 | |
|---|
| 77 | System.out.println("load"); |
|---|
| 78 | String line1 = "5 N 4.02, 33.33, -117.117,Dyer Rd,.1,.1\n5 S 3.56, 33.33, -117.117,Dyer Rd,.2,.2"; |
|---|
| 79 | Scanner scan = new Scanner(line1).useDelimiter("\\A"); |
|---|
| 80 | pmc = new PostmileCoords(); |
|---|
| 81 | pmc.load(scan); |
|---|
| 82 | PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33", |
|---|
| 83 | "-117.117","Dyer Rd",".1",".1"); |
|---|
| 84 | assertEquals(pm,pmc.get(0)); |
|---|
| 85 | assert(pmc.size() == 2); |
|---|
| 86 | } |
|---|
| 87 | public void testIterator() throws FileNotFoundException |
|---|
| 88 | { |
|---|
| 89 | System.out.println("iterator"); |
|---|
| 90 | testLoad(); |
|---|
| 91 | int count = 0; |
|---|
| 92 | for (Object pm: pmc) |
|---|
| 93 | { |
|---|
| 94 | count++; |
|---|
| 95 | } |
|---|
| 96 | assert(count == 2); |
|---|
| 97 | } |
|---|
| 98 | public void testFind() throws FileNotFoundException |
|---|
| 99 | { |
|---|
| 100 | System.out.println("find"); |
|---|
| 101 | testLoad(); |
|---|
| 102 | PostmileCoords.Postmile result = pmc.find("5 N 4.02"); |
|---|
| 103 | assertNotNull(result); |
|---|
| 104 | PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33", "-117.117","Dyer Rd", "0.547592", "0.836745"); |
|---|
| 105 | assertEquals(pm,result); |
|---|
| 106 | PostmileCoords.Postmile result2 = pmc.find("X"); |
|---|
| 107 | assertNull(result2); |
|---|
| 108 | System.out.println(pm.toJson()); |
|---|
| 109 | } |
|---|
| 110 | } |
|---|