Skip to content

Commit 4c32306

Browse files
committed
More testing of command line usage
1 parent 51afeb3 commit 4c32306

9 files changed

+226
-14
lines changed

src/test/java/org/geometrycommands/DelaunayTriangulationCommandTest.java

Lines changed: 39 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 DelaunayTriangulationCommand UnitTest
1214
* @author Jared Erickson
1315
*/
14-
public class DelaunayTriangulationCommandTest {
16+
public class DelaunayTriangulationCommandTest extends BaseTest {
1517

1618
@Test
1719
public void execute() throws Exception {
@@ -37,4 +39,40 @@ public void execute() throws Exception {
3739
+ "12.73833434783841, 8.017822881853032 7.492806794533148, 13.737894633461437 "
3840
+ "7.658802439672621, 12.27256417862947 12.73833434783841)))", writer.getBuffer().toString());
3941
}
42+
43+
@Test
44+
public void run() throws Exception {
45+
// Geometry from options
46+
String result = runApp(new String[]{
47+
"delaunay",
48+
"-g", "MULTIPOINT ((12.27256417862947 12.73833434783841), "
49+
+ "(13.737894633461437 7.658802439672621), "
50+
+ "(6.857126638942733 8.821305316892328), "
51+
+ "(9.260874914207697 13.087320259444919), "
52+
+ "(8.017822881853032 7.492806794533148))"
53+
}, null);
54+
assertEquals("GEOMETRYCOLLECTION (POLYGON ((6.857126638942733 8.821305316892328, "
55+
+ "8.017822881853032 7.492806794533148, 9.260874914207697 13.087320259444919, "
56+
+ "6.857126638942733 8.821305316892328)), POLYGON ((9.260874914207697 "
57+
+ "13.087320259444919, 8.017822881853032 7.492806794533148, 12.27256417862947 "
58+
+ "12.73833434783841, 9.260874914207697 13.087320259444919)), POLYGON ((12.27256417862947 "
59+
+ "12.73833434783841, 8.017822881853032 7.492806794533148, 13.737894633461437 "
60+
+ "7.658802439672621, 12.27256417862947 12.73833434783841)))", result);
61+
62+
// Geometry from input stream
63+
result = runApp(new String[]{
64+
"delaunay",
65+
}, "MULTIPOINT ((12.27256417862947 12.73833434783841), "
66+
+ "(13.737894633461437 7.658802439672621), "
67+
+ "(6.857126638942733 8.821305316892328), "
68+
+ "(9.260874914207697 13.087320259444919), "
69+
+ "(8.017822881853032 7.492806794533148))");
70+
assertEquals("GEOMETRYCOLLECTION (POLYGON ((6.857126638942733 8.821305316892328, "
71+
+ "8.017822881853032 7.492806794533148, 9.260874914207697 13.087320259444919, "
72+
+ "6.857126638942733 8.821305316892328)), POLYGON ((9.260874914207697 "
73+
+ "13.087320259444919, 8.017822881853032 7.492806794533148, 12.27256417862947 "
74+
+ "12.73833434783841, 9.260874914207697 13.087320259444919)), POLYGON ((12.27256417862947 "
75+
+ "12.73833434783841, 8.017822881853032 7.492806794533148, 13.737894633461437 "
76+
+ "7.658802439672621, 12.27256417862947 12.73833434783841)))", result);
77+
}
4078
}

src/test/java/org/geometrycommands/DensifyCommandTest.java

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

1616
@Test
1717
public void execute() throws Exception {
@@ -32,4 +32,30 @@ public void execute() throws Exception {
3232
+ "9.200000000000001, 10.600000000000001 10.600000000000001, "
3333
+ "12 12)", writer.getBuffer().toString());
3434
}
35+
36+
@Test
37+
public void run() throws Exception {
38+
// Geometry from options
39+
String result = runApp(new String[]{
40+
"densify",
41+
"-g", "LINESTRING (1 1, 5 5, 12 12)",
42+
"-d", "2"
43+
}, null);
44+
assertEquals("LINESTRING (1 1, 2.3333333333333335 2.3333333333333335, "
45+
+ "3.666666666666667 3.666666666666667, 5 5, 6.4 6.4, "
46+
+ "7.800000000000001 7.800000000000001, 9.200000000000001 "
47+
+ "9.200000000000001, 10.600000000000001 10.600000000000001, "
48+
+ "12 12)", result);
49+
50+
// Geometry from input stream
51+
result = runApp(new String[]{
52+
"densify",
53+
"-d", "2"
54+
}, "LINESTRING (1 1, 5 5, 12 12)");
55+
assertEquals("LINESTRING (1 1, 2.3333333333333335 2.3333333333333335, "
56+
+ "3.666666666666667 3.666666666666667, 5 5, 6.4 6.4, "
57+
+ "7.800000000000001 7.800000000000001, 9.200000000000001 "
58+
+ "9.200000000000001, 10.600000000000001 10.600000000000001, "
59+
+ "12 12)", result);
60+
}
3561
}

src/test/java/org/geometrycommands/DifferenceCommandTest.java

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

1515
@Test
1616
public void execute() throws Exception {
@@ -29,4 +29,22 @@ public void execute() throws Exception {
2929
assertEquals("POLYGON ((0 0, 0 10, 5 10, 5 5, 10 5, 10 0, 0 0))",
3030
writer.getBuffer().toString());
3131
}
32+
33+
@Test
34+
public void run() throws Exception {
35+
// Geometry from options
36+
String result = runApp(new String[]{
37+
"difference",
38+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))",
39+
"-o", "POLYGON ((5 5, 5 20, 20 20, 20 5, 5 5))"
40+
}, null);
41+
assertEquals("POLYGON ((0 0, 0 10, 5 10, 5 5, 10 5, 10 0, 0 0))", result);
42+
43+
// Geometry from input stream
44+
result = runApp(new String[]{
45+
"difference",
46+
"-o", "POLYGON ((5 5, 5 20, 20 20, 20 5, 5 5))"
47+
}, "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
48+
assertEquals("POLYGON ((0 0, 0 10, 5 10, 5 5, 10 5, 10 0, 0 0))", result);
49+
}
3250
}

src/test/java/org/geometrycommands/DiscreteHausdorffDistanceCommandTest.java

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

1515
@Test
1616
public void execute() throws Exception {
@@ -28,4 +28,22 @@ public void execute() throws Exception {
2828
command.execute(options, reader, writer);
2929
assertEquals("29.068883707497267", writer.getBuffer().toString());
3030
}
31+
32+
@Test
33+
public void run() throws Exception {
34+
// Geometry from options
35+
String result = runApp(new String[]{
36+
"hausdorffdistance",
37+
"-g", "POINT (1 1)",
38+
"-o", "POINT (20 23)"
39+
}, null);
40+
assertEquals(29.068883707497267, Double.parseDouble(result), 0.00001);
41+
42+
// Geometry from input stream
43+
result = runApp(new String[]{
44+
"hausdorffdistance",
45+
"-o", "POINT (20 23)"
46+
}, "POINT (1 1)");
47+
assertEquals(29.068883707497267, Double.parseDouble(result), 0.00001);
48+
}
3149
}

src/test/java/org/geometrycommands/DisjointCommandTest.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package org.geometrycommands;
22

3+
import org.junit.Test;
4+
35
import java.io.Reader;
46
import java.io.StringReader;
57
import java.io.StringWriter;
6-
import org.junit.Test;
7-
import static org.junit.Assert.assertEquals;
8+
9+
import static org.junit.Assert.*;
810

911
/**
1012
* The DisjointCommand UnitTest
13+
*
1114
* @author Jared Erickson
1215
*/
13-
public class DisjointCommandTest {
16+
public class DisjointCommandTest extends BaseTest {
1417

1518
@Test
1619
public void execute() throws Exception {
@@ -43,4 +46,22 @@ public void execute() throws Exception {
4346
command.execute(options, reader, writer);
4447
assertEquals("true", writer.getBuffer().toString());
4548
}
49+
50+
@Test
51+
public void run() throws Exception {
52+
// Geometry from options
53+
String result = runApp(new String[]{
54+
"disjoint",
55+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))",
56+
"-o", "LINESTRING (5 5, 5 15)"
57+
}, null);
58+
assertFalse(Boolean.parseBoolean(result));
59+
60+
// Geometry from input stream
61+
result = runApp(new String[]{
62+
"disjoint",
63+
"-o", "LINESTRING (15 15, 20 20)"
64+
}, "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
65+
assertTrue(Boolean.parseBoolean(result));
66+
}
4667
}

src/test/java/org/geometrycommands/DistanceCommandTest.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package org.geometrycommands;
22

3+
import org.junit.Test;
4+
35
import java.io.Reader;
46
import java.io.StringReader;
57
import java.io.StringWriter;
6-
import org.junit.Test;
8+
79
import static org.junit.Assert.assertEquals;
810

911
/**
1012
* The DistanceCommand UnitTest
13+
*
1114
* @author Jared Erickson
1215
*/
13-
public class DistanceCommandTest {
16+
public class DistanceCommandTest extends BaseTest {
1417

1518
@Test
1619
public void execute() throws Exception {
@@ -28,4 +31,22 @@ public void execute() throws Exception {
2831
command.execute(options, reader, writer);
2932
assertEquals("29.068883707497267", writer.getBuffer().toString());
3033
}
34+
35+
@Test
36+
public void run() throws Exception {
37+
// Geometry from options
38+
String result = runApp(new String[]{
39+
"distance",
40+
"-g", "POINT (1 1)",
41+
"-o", "POINT (20 23)"
42+
}, null);
43+
assertEquals(29.068883707497267, Double.parseDouble(result), 0.0001);
44+
45+
// Geometry from input stream
46+
result = runApp(new String[]{
47+
"distance",
48+
"-o", "POINT (20 23)"
49+
}, "POINT (1 1)");
50+
assertEquals(29.068883707497267, Double.parseDouble(result), 0.0001);
51+
}
3152
}

src/test/java/org/geometrycommands/DistanceLineStringCommandTest.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package org.geometrycommands;
22

3+
import org.junit.Test;
4+
35
import java.io.Reader;
46
import java.io.StringReader;
57
import java.io.StringWriter;
6-
import org.junit.Test;
8+
79
import static org.junit.Assert.assertEquals;
810

911
/**
1012
* The DistanceLineStringCommand UnitTest
13+
*
1114
* @author Jared Erickson
1215
*/
13-
public class DistanceLineStringCommandTest {
16+
public class DistanceLineStringCommandTest extends BaseTest {
1417

1518
@Test
1619
public void execute() throws Exception {
@@ -28,4 +31,22 @@ public void execute() throws Exception {
2831
command.execute(options, reader, writer);
2932
assertEquals("LINESTRING (1 1, 20 23)", writer.getBuffer().toString());
3033
}
34+
35+
@Test
36+
public void run() throws Exception {
37+
// Geometry from options
38+
String result = runApp(new String[]{
39+
"distanceline",
40+
"-g", "POINT (1 1)",
41+
"-o", "POINT (20 23)"
42+
}, null);
43+
assertEquals("LINESTRING (1 1, 20 23)", result);
44+
45+
// Geometry from input stream
46+
result = runApp(new String[]{
47+
"distanceline",
48+
"-o", "POINT (20 23)"
49+
}, "POINT (1 1)");
50+
assertEquals("LINESTRING (1 1, 20 23)", result);
51+
}
3152
}

src/test/java/org/geometrycommands/DrawCommandTest.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
import java.io.StringWriter;
77
import org.geometrycommands.DrawCommand.DrawOptions;
88
import org.junit.Test;
9+
10+
import static org.junit.Assert.assertEquals;
911
import static org.junit.Assert.assertTrue;
1012

1113
/**
1214
* The DrawCommand UnitTest
1315
* @author Jared Erickson
1416
*/
15-
public class DrawCommandTest {
17+
public class DrawCommandTest extends BaseTest {
1618

1719
@Test
1820
public void execute() throws Exception {
1921

2022
String inputGeometry = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))";
2123
File file = File.createTempFile("image", ".png");
22-
System.out.println(file);
2324
DrawOptions options = new DrawOptions();
2425
options.setGeometry(inputGeometry);
2526
options.setFile(file);
@@ -31,4 +32,36 @@ public void execute() throws Exception {
3132
command.execute(options, reader, writer);
3233
assertTrue(file.exists());
3334
}
35+
36+
@Test
37+
public void run() throws Exception {
38+
// Geometry from options
39+
File file = File.createTempFile("image", ".png");
40+
String result = runApp(new String[]{
41+
"draw",
42+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))",
43+
"-f", file.getAbsolutePath()
44+
}, null);
45+
assertTrue(file.exists());
46+
assertTrue(file.length() > 0);
47+
48+
// Geometry from input stream
49+
file = File.createTempFile("image", ".png");
50+
result = runApp(new String[]{
51+
"draw",
52+
"-w", "300",
53+
"-h", "250",
54+
"-f", file.getAbsolutePath(),
55+
"-b", "0,0,0",
56+
"-s", "255,255,255",
57+
"-t", "0.75",
58+
"-l", "255,255,0",
59+
"-o", "0.55",
60+
"-m", "square",
61+
"-z", "12",
62+
"-e", "0,0,10,10"
63+
}, "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
64+
assertTrue(file.exists());
65+
assertTrue(file.length() > 0);
66+
}
3467
}

src/test/java/org/geometrycommands/DumpCommandTest.java

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

1515
private final static String NEW_LINE = System.getProperty("line.separator");
1616

@@ -39,4 +39,20 @@ public void execute() throws Exception {
3939
command.execute(options, reader, writer);
4040
assertEquals("POINT (5 5)" + NEW_LINE + "POINT (1 1)" + NEW_LINE + "POINT (2 2)" + NEW_LINE, writer.getBuffer().toString());
4141
}
42+
43+
@Test
44+
public void run() throws Exception {
45+
// Geometry from options
46+
String result = runApp(new String[]{
47+
"dump",
48+
"-g", "MULTIPOINT ((1 1), (2 2))"
49+
}, null);
50+
assertEquals("POINT (1 1)" + NEW_LINE + "POINT (2 2)", result);
51+
52+
// Geometry from input stream
53+
result = runApp(new String[]{
54+
"dump"
55+
}, "MULTIPOINT ((1 1), (2 2))");
56+
assertEquals("POINT (1 1)" + NEW_LINE + "POINT (2 2)", result);
57+
}
4258
}

0 commit comments

Comments
 (0)