Skip to content

Commit a918063

Browse files
committed
Wrap up command line testing
1 parent e5c15e1 commit a918063

33 files changed

+893
-90
lines changed

src/test/java/org/geometrycommands/OctagonalEnvelopeCommandTest.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* The OctagonalEnvelopeCommand UnitTest
1111
* @author Jared Erickson
1212
*/
13-
public class OctagonalEnvelopeCommandTest {
13+
public class OctagonalEnvelopeCommandTest extends BaseTest {
1414

1515
@Test
1616
public void execute() throws Exception {
@@ -37,4 +37,40 @@ public void execute() throws Exception {
3737
+ "8.653503037443446))",
3838
writer.getBuffer().toString());
3939
}
40+
41+
@Test
42+
public void run() throws Exception {
43+
// Geometry from options
44+
String result = runApp(new String[]{
45+
"octagonalenvelope",
46+
"-g", "MULTIPOINT ((12.27256417862947 12.73833434783841), "
47+
+ "(13.737894633461437 7.658802439672621), "
48+
+ "(6.857126638942733 8.821305316892328), "
49+
+ "(9.260874914207697 13.087320259444919), "
50+
+ "(8.017822881853032 7.492806794533148))",
51+
}, null);
52+
assertEquals("POLYGON ((6.857126638942733 8.653503037443446, "
53+
+ "6.857126638942733 10.683571984179956, 9.260874914207697 "
54+
+ "13.087320259444919, 11.923578267022961 13.087320259444919, "
55+
+ "13.737894633461437 11.273003893006443, 13.737894633461437 "
56+
+ "7.658802439672621, 13.571898988321964 7.492806794533148, "
57+
+ "8.017822881853032 7.492806794533148, 6.857126638942733 "
58+
+ "8.653503037443446))", result);
59+
60+
// Geometry from input stream
61+
result = runApp(new String[]{
62+
"octagonalenvelope"
63+
}, "MULTIPOINT ((12.27256417862947 12.73833434783841), "
64+
+ "(13.737894633461437 7.658802439672621), "
65+
+ "(6.857126638942733 8.821305316892328), "
66+
+ "(9.260874914207697 13.087320259444919), "
67+
+ "(8.017822881853032 7.492806794533148))");
68+
assertEquals("POLYGON ((6.857126638942733 8.653503037443446, "
69+
+ "6.857126638942733 10.683571984179956, 9.260874914207697 "
70+
+ "13.087320259444919, 11.923578267022961 13.087320259444919, "
71+
+ "13.737894633461437 11.273003893006443, 13.737894633461437 "
72+
+ "7.658802439672621, 13.571898988321964 7.492806794533148, "
73+
+ "8.017822881853032 7.492806794533148, 6.857126638942733 "
74+
+ "8.653503037443446))", result);
75+
}
4076
}

src/test/java/org/geometrycommands/OverlapsCommandTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import java.io.StringWriter;
66
import org.junit.Test;
77
import static org.junit.Assert.assertEquals;
8+
import static org.junit.Assert.assertFalse;
9+
import static org.junit.Assert.assertTrue;
810

911
/**
1012
* The OverlapsCommand UnitTest
1113
* @author Jared Erickson
1214
*/
13-
public class OverlapsCommandTest {
15+
public class OverlapsCommandTest extends BaseTest {
1416

1517
@Test
1618
public void execute() throws Exception {
@@ -42,4 +44,28 @@ public void execute() throws Exception {
4244
command.execute(options, reader, writer);
4345
assertEquals("false", writer.getBuffer().toString());
4446
}
47+
48+
@Test
49+
public void run() throws Exception {
50+
51+
String inputGeometry = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))";
52+
String otherGeometry1 = "POLYGON ((2 2, 2 14, 14 14, 14 2, 2 2))";
53+
String otherGeometry2 = "POINT (15 15)";
54+
55+
// Geometry from options
56+
String result = runApp(new String[]{
57+
"overlaps",
58+
"-g", inputGeometry,
59+
"-o", otherGeometry1
60+
}, null);
61+
assertTrue(Boolean.parseBoolean(result));
62+
63+
// Geometry from input stream
64+
result = runApp(new String[]{
65+
"overlaps",
66+
"-o", otherGeometry2
67+
}, inputGeometry);
68+
assertFalse(Boolean.parseBoolean(result));
69+
}
70+
4571
}

src/test/java/org/geometrycommands/PlacePointCommandTest.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import java.io.StringWriter;
66
import org.junit.Test;
77
import static org.junit.Assert.assertEquals;
8+
import static org.junit.Assert.assertFalse;
9+
import static org.junit.Assert.assertTrue;
810

911
/**
1012
* The PlacePointCommand UnitTest
1113
* @author Jared Erickson
1214
*/
13-
public class PlacePointCommandTest {
15+
public class PlacePointCommandTest extends BaseTest {
1416

1517
@Test
1618
public void execute() throws Exception {
@@ -28,4 +30,27 @@ public void execute() throws Exception {
2830
command.execute(options, reader, writer);
2931
assertEquals("POINT (3.75 3.75)", writer.getBuffer().toString());
3032
}
33+
34+
@Test
35+
public void run() throws Exception {
36+
37+
String inputGeometry = "LINESTRING (0 0, 5 5, 10 10)";
38+
String otherGeometry = "POINT (3 4.5)";
39+
String resultGeometry = "POINT (3.75 3.75)";
40+
41+
// Geometry from options
42+
String result = runApp(new String[]{
43+
"placepoint",
44+
"-g", inputGeometry,
45+
"-o", otherGeometry
46+
}, null);
47+
assertEquals(resultGeometry, result);
48+
49+
// Geometry from input stream
50+
result = runApp(new String[]{
51+
"placepoint",
52+
"-o", otherGeometry
53+
}, inputGeometry);
54+
assertEquals(resultGeometry, result);
55+
}
3156
}

src/test/java/org/geometrycommands/PointAtAngleCommandTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* The PointAtAngleCommand UnitTest
1212
* @author Jared Erickson
1313
*/
14-
public class PointAtAngleCommandTest {
14+
public class PointAtAngleCommandTest extends BaseTest {
1515

1616
@Test
1717
public void execute() throws Exception {
@@ -41,4 +41,25 @@ public void execute() throws Exception {
4141
command.execute(options, reader, writer);
4242
assertEquals("POINT (13.535533905932738 13.535533905932738)", writer.getBuffer().toString());
4343
}
44+
45+
@Test
46+
public void run() throws Exception {
47+
48+
// Geometry from options
49+
String result = runApp(new String[]{
50+
"pointatangle",
51+
"-g", "POINT (10 10)",
52+
"-a", "90",
53+
"-d", "10"
54+
}, null);
55+
assertEquals("POINT (10 20)", result);
56+
57+
// Geometry from input stream
58+
result = runApp(new String[]{
59+
"pointatangle",
60+
"-a", "45",
61+
"-d", "5"
62+
}, "POINT (10 10)");
63+
assertEquals("POINT (13.535533905932738 13.535533905932738)", result);
64+
}
4465
}

src/test/java/org/geometrycommands/PolygonizeCommandTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* The PolygonizeCommand UnitTest
2020
* @author Jared Erickson
2121
*/
22-
public class PolygonizeCommandTest {
22+
public class PolygonizeCommandTest extends BaseTest {
2323

2424
@Test
2525
public void execute() throws Exception {
@@ -62,4 +62,39 @@ public void execute() throws Exception {
6262
assertFalse(outputGeometry.getGeometryN(2).isEmpty());
6363
assertTrue(outputGeometry.getGeometryN(3).isEmpty());
6464
}
65+
66+
@Test
67+
public void run() throws Exception {
68+
69+
String inputGeometry = "MULTILINESTRING ((-5.70068359375 45.1416015625, "
70+
+ "-4.6 46.4), (-4.6 46.4, 1 52.2), (1 52.2, 2.47314453125 "
71+
+ "53.9306640625), (-1.21826171875 53.9306640625, 1 52.2), "
72+
+ "(1 52.2, 5.6 48.6), (5.6 48.6, 8.88916015625 46.1962890625), "
73+
+ "(0.71533203125 42.63671875, 1.8 44), (1.8 44, 5.6 48.6), "
74+
+ "(5.6 48.6, 7.13134765625 50.37109375), (-5.83251953125 "
75+
+ "46.943359375, -4.6 46.4), (-4.6 46.4, 1.8 44), (1.8 44, "
76+
+ "4.45068359375 42.98828125))";
77+
78+
// Geometry from options
79+
String result = runApp(new String[]{
80+
"polygonize",
81+
"-g", inputGeometry
82+
}, null);
83+
Geometry outputGeometry = new WKTReader().read(result);
84+
assertTrue(outputGeometry instanceof MultiPolygon);
85+
assertEquals(1, outputGeometry.getNumGeometries());
86+
87+
// Geometry from input stream
88+
result = runApp(new String[]{
89+
"polygonize",
90+
"-f"
91+
}, inputGeometry);
92+
outputGeometry = new WKTReader().read(result);
93+
assertTrue(outputGeometry instanceof GeometryCollection);
94+
assertEquals(4, outputGeometry.getNumGeometries());
95+
assertFalse(outputGeometry.getGeometryN(0).isEmpty());
96+
assertTrue(outputGeometry.getGeometryN(1).isEmpty());
97+
assertFalse(outputGeometry.getGeometryN(2).isEmpty());
98+
assertTrue(outputGeometry.getGeometryN(3).isEmpty());
99+
}
65100
}

src/test/java/org/geometrycommands/PrecisionReducerCommandTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* The PrecisionReducerCommand UnitTest
1212
* @author Jared Erickson
1313
*/
14-
public class PrecisionReducerCommandTest {
14+
public class PrecisionReducerCommandTest extends BaseTest {
1515

1616
@Test
1717
public void execute() throws Exception {
@@ -55,4 +55,26 @@ public void execute() throws Exception {
5555
command.execute(options, reader, writer);
5656
assertEquals("POINT (5.19775390625 51.07421875)", writer.getBuffer().toString());
5757
}
58+
59+
@Test
60+
public void run() throws Exception {
61+
62+
String inputGeometry = "POINT (5.19775390625 51.07421875)";
63+
64+
// Geometry from options
65+
String result = runApp(new String[]{
66+
"reduceprecision",
67+
"-g", inputGeometry,
68+
"-t", "floating"
69+
}, null);
70+
assertEquals("POINT (5.19775390625 51.07421875)", result);
71+
72+
// Geometry from input stream
73+
result = runApp(new String[]{
74+
"reduceprecision",
75+
"-t", "fixed",
76+
"-s", "10"
77+
}, inputGeometry);
78+
assertEquals("POINT (5.2 51.1)", result);
79+
}
5880
}

src/test/java/org/geometrycommands/ProjectCommandTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import java.io.StringWriter;
77
import org.junit.Test;
88
import static org.junit.Assert.assertEquals;
9+
import static org.junit.Assert.assertFalse;
10+
import static org.junit.Assert.assertTrue;
911

1012
/**
1113
* The ProjectCommand UnitTest
1214
* @author Jared Erickson
1315
*/
14-
public class ProjectCommandTest {
16+
public class ProjectCommandTest extends BaseTest {
1517

1618
@Test
1719
public void execute() throws Exception {
@@ -29,4 +31,24 @@ public void execute() throws Exception {
2931
command.execute(options, reader, writer);
3032
assertEquals("POINT (-122.32131937934592 47.07927009358412)", writer.getBuffer().toString());
3133
}
34+
35+
@Test
36+
public void run() throws Exception {
37+
// Geometry from options
38+
String result = runApp(new String[]{
39+
"project",
40+
"-g", "POINT (1186683.01 641934.58)",
41+
"-s", "EPSG:2927",
42+
"-t", "EPSG:4326"
43+
}, null);
44+
assertEquals("POINT (-122.32131937934592 47.07927009358412)", result);
45+
46+
// Geometry from input stream
47+
result = runApp(new String[]{
48+
"project",
49+
"-s", "EPSG:2927",
50+
"-t", "EPSG:4326"
51+
}, "POINT (1186683.01 641934.58)");
52+
assertEquals("POINT (-122.32131937934592 47.07927009358412)", result);
53+
}
3254
}

src/test/java/org/geometrycommands/RandomCommandTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
import java.io.StringWriter;
99
import org.junit.Test;
1010
import static org.junit.Assert.assertEquals;
11+
import static org.junit.Assert.assertFalse;
12+
import static org.junit.Assert.assertTrue;
1113

1214
/**
1315
* The RandomCommand UnitTest
1416
* @author Jared Erickson
1517
*/
16-
public class RandomCommandTest {
18+
public class RandomCommandTest extends BaseTest {
1719

1820
@Test
1921
public void execute() throws Exception {
@@ -33,4 +35,26 @@ public void execute() throws Exception {
3335
assertEquals("MultiPoint", geometry.getGeometryType());
3436
assertEquals(10, geometry.getNumGeometries());
3537
}
38+
39+
@Test
40+
public void run() throws Exception {
41+
// Geometry from options
42+
String result = runApp(new String[]{
43+
"random",
44+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))",
45+
"-n", "10"
46+
}, null);
47+
Geometry geometry = new WKTReader().read(result);
48+
assertEquals("MultiPoint", geometry.getGeometryType());
49+
assertEquals(10, geometry.getNumGeometries());
50+
51+
// Geometry from input stream
52+
result = runApp(new String[]{
53+
"random",
54+
"-n", "10"
55+
}, "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
56+
geometry = new WKTReader().read(result);
57+
assertEquals("MultiPoint", geometry.getGeometryType());
58+
assertEquals(10, geometry.getNumGeometries());
59+
}
3660
}

src/test/java/org/geometrycommands/RandomWalkCommandTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* The RandomWalkCommand UnitTest
1515
* @author Jared Erickson
1616
*/
17-
public class RandomWalkCommandTest {
17+
public class RandomWalkCommandTest extends BaseTest {
1818

1919
@Test
2020
public void execute() throws Exception {
@@ -36,4 +36,32 @@ public void execute() throws Exception {
3636
assertTrue(g instanceof LineString);
3737
assertEquals(11, g.getNumPoints());
3838
}
39+
40+
@Test
41+
public void run() throws Exception {
42+
// Geometry from options
43+
String result = runApp(new String[]{
44+
"randomwalk",
45+
"-g", "POINT (100 100)",
46+
"-n", "10",
47+
"-d", "10",
48+
"-a", "45",
49+
"-p", "0.75"
50+
}, null);
51+
Geometry g = new WKTReader().read(result);
52+
assertTrue(g instanceof LineString);
53+
assertEquals(11, g.getNumPoints());
54+
55+
// Geometry from input stream
56+
result = runApp(new String[]{
57+
"randomwalk",
58+
"-n", "10",
59+
"-d", "10",
60+
"-a", "45",
61+
"-p", "0.75"
62+
}, "POINT (100 100)");
63+
g = new WKTReader().read(result);
64+
assertTrue(g instanceof LineString);
65+
assertEquals(11, g.getNumPoints());
66+
}
3967
}

0 commit comments

Comments
 (0)