source: tmcsimulator/trunk/test/atmsdriver/model/PostmileCoordsTest.java @ 269

Revision 269, 3.4 KB checked in by jdalbey, 7 years ago (diff)

PostmileCoords?.java: Add new fields for perpendicular vector (x and y components). This enables adjusting the dot position along line perpendicular to the highway when the map is zoomed.

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