~ubuntu-branches/ubuntu/oneiric/mkgmap/oneiric

« back to all changes in this revision

Viewing changes to test/uk/me/parabola/mkgmap/general/LineClipperTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine, Andreas Putzo, Francesco Paolo Lovergine
  • Date: 2009-07-16 11:10:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090716111016-yycxqya1f26xmti7
Tags: 0.0.0+svn1067-1
[ Andreas Putzo ]
* New upstream snapshot.
* Added ${misc:Depends} among dependencies to fix a lintian warning.
* Bumped debhelper compatibility level to 7.
* Updated long description.
* Updated Homepage in debian/control, debian/copyright, debian/watch.
* Added numerous files from /doc to debian/docs.
* Mentioned Bernhard Heibler in debian/copyright and updated copyright
  year of software and packaging.
* Bumped policy to 3.8.2, without changes.
* Added DM-Upload-Allowed to debian/control.

[ Francesco Paolo Lovergine ]
* Added me as Uploader to avoid possible inappropriate NMU notices.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Steve Ratcliffe
 
3
 * 
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License version 2 as
 
6
 *  published by the Free Software Foundation.
 
7
 * 
 
8
 *  This program is distributed in the hope that it will be useful,
 
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 *  GNU General Public License for more details.
 
12
 * 
 
13
 * 
 
14
 * Author: Steve Ratcliffe
 
15
 * Create date: 29-Nov-2008
 
16
 */
 
17
package uk.me.parabola.mkgmap.general;
 
18
 
 
19
import java.util.Arrays;
 
20
import java.util.List;
 
21
 
 
22
import uk.me.parabola.imgfmt.app.Area;
 
23
import uk.me.parabola.imgfmt.app.Coord;
 
24
 
 
25
import static org.junit.Assert.assertArrayEquals;
 
26
import static org.junit.Assert.assertEquals;
 
27
import static org.junit.Assert.assertNull;
 
28
import static org.junit.Assert.assertTrue;
 
29
import org.junit.Test;
 
30
 
 
31
public class LineClipperTest {
 
32
 
 
33
        /**
 
34
         * This is the example as given on the referenced web page.
 
35
         * We now use integers instead of floats so the 101.425 from the
 
36
         * example is just 101 here.
 
37
         */
 
38
        @Test
 
39
        public void testExampleClip() {
 
40
                Area a = new Area(60, 70, 150, 230);
 
41
                Coord[] co = {
 
42
                                new Coord(20, 30),
 
43
                                new Coord(160, 280),
 
44
                };
 
45
 
 
46
                List<List<Coord>> listList = LineClipper.clip(a, Arrays.asList(co));
 
47
                assertTrue("list should be empty", !listList.isEmpty());
 
48
 
 
49
                Coord[] result = {
 
50
                                new Coord(60, 101),
 
51
                                new Coord(132, 230)
 
52
                };
 
53
                assertArrayEquals("example result", result, listList.get(0).toArray());
 
54
        }
 
55
 
 
56
        /**
 
57
         * Test an original line that enters the area, leaves it and then goes back
 
58
         * into the area.  This should give two lines in the result set.
 
59
         */
 
60
        @Test
 
61
        public void testListClip() {
 
62
                // Add your code here
 
63
                Area a = new Area(100, 100, 200, 200);
 
64
                List<Coord> l = Arrays.asList(new Coord(20, 30),
 
65
                                new Coord(40, 60),
 
66
                                new Coord(102, 110),
 
67
                                new Coord(150, 150),
 
68
                                new Coord(210, 220),
 
69
                                new Coord(190, 135)
 
70
                                );
 
71
                List<List<Coord>> list = LineClipper.clip(a, l);
 
72
 
 
73
                // There should be exactly two lines
 
74
                assertEquals("should be two lines", 2, list.size());
 
75
 
 
76
                // No empty lists
 
77
                for (List<Coord> lco : list)
 
78
                        assertTrue("empty list", !lco.isEmpty());
 
79
 
 
80
                // Check values
 
81
                Coord[] firstExpectedLine = {
 
82
                                new Coord(100, 108),
 
83
                                new Coord(102, 110),
 
84
                                new Coord(150, 150),
 
85
                                new Coord(193, 200)
 
86
                };
 
87
                assertArrayEquals(firstExpectedLine, list.get(0).toArray());
 
88
                Coord[] secondExpectedLine = {
 
89
                                new Coord(200, 178),
 
90
                                new Coord(190, 135)
 
91
                };
 
92
                assertArrayEquals(secondExpectedLine, list.get(1).toArray());
 
93
        }
 
94
 
 
95
        /**
 
96
         * If all the lines are inside, then it should just return null to indicate that.
 
97
         */
 
98
        @Test
 
99
        public void testAllInside() {
 
100
                Area a = new Area(100, 100, 200, 200);
 
101
                List<Coord> l = Arrays.asList(
 
102
                                new Coord(102, 110),
 
103
                                new Coord(150, 150),
 
104
                                new Coord(190, 195)
 
105
                                );
 
106
                List<List<Coord>> list = LineClipper.clip(a, l);
 
107
                assertNull("all lines inside", list);
 
108
        }
 
109
}