Skip to content

Commit e5c15e1

Browse files
committed
More command line unit tests
1 parent 596a33c commit e5c15e1

11 files changed

+310
-41
lines changed

src/test/java/org/geometrycommands/KochSnowflakeCommandTest.java

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

1618
@Test
1719
public void execute() throws Exception {
@@ -36,4 +38,36 @@ public void execute() throws Exception {
3638
, writer.getBuffer().toString());
3739

3840
}
41+
42+
@Test
43+
public void run() throws Exception {
44+
// Geometry from options
45+
String result = runApp(new String[]{
46+
"kochsnowflake",
47+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))",
48+
"-n", "30"
49+
}, null);
50+
assertEquals("POLYGON ((1.6666666666666665 5.773502691896256, "
51+
+ "0.0000000000000004 8.660254037844386, 3.333333333333333 "
52+
+ "8.660254037844386, 5 11.547005383792515, 6.666666666666666 "
53+
+ "8.660254037844386, 10 8.660254037844386, 8.333333333333332 "
54+
+ "5.773502691896258, 10 2.8867513459481287, 6.666666666666667 "
55+
+ "2.8867513459481287, 5 0, 3.333333333333334 2.8867513459481287, "
56+
+ "0 2.8867513459481287, 1.6666666666666665 5.773502691896256))"
57+
, result);
58+
59+
// Geometry from input stream
60+
result = runApp(new String[]{
61+
"kochsnowflake",
62+
"-n", "30"
63+
}, "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
64+
assertEquals("POLYGON ((1.6666666666666665 5.773502691896256, "
65+
+ "0.0000000000000004 8.660254037844386, 3.333333333333333 "
66+
+ "8.660254037844386, 5 11.547005383792515, 6.666666666666666 "
67+
+ "8.660254037844386, 10 8.660254037844386, 8.333333333333332 "
68+
+ "5.773502691896258, 10 2.8867513459481287, 6.666666666666667 "
69+
+ "2.8867513459481287, 5 0, 3.333333333333334 2.8867513459481287, "
70+
+ "0 2.8867513459481287, 1.6666666666666665 5.773502691896256))"
71+
, result);
72+
}
3973
}

src/test/java/org/geometrycommands/LineMergeCommandTest.java

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

1515
@Test
1616
public void execute() throws Exception {
@@ -27,4 +27,20 @@ public void execute() throws Exception {
2727
assertEquals("MULTILINESTRING ((-29 -27, -30 -29.7, -36 -31, -45 -33, -46 -32))",
2828
writer.getBuffer().toString());
2929
}
30+
31+
@Test
32+
public void run() throws Exception {
33+
// Geometry from options
34+
String result = runApp(new String[]{
35+
"linemerge",
36+
"-g", "MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45 -33,-46 -32))"
37+
}, null);
38+
assertEquals("MULTILINESTRING ((-29 -27, -30 -29.7, -36 -31, -45 -33, -46 -32))", result);
39+
40+
// Geometry from input stream
41+
result = runApp(new String[]{
42+
"linemerge",
43+
}, "MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45 -33,-46 -32))");
44+
assertEquals("MULTILINESTRING ((-29 -27, -30 -29.7, -36 -31, -45 -33, -46 -32))", result);
45+
}
3046
}

src/test/java/org/geometrycommands/ListCommandTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
import java.io.StringReader;
55
import java.io.StringWriter;
66
import org.junit.Test;
7+
8+
import static org.junit.Assert.assertEquals;
79
import static org.junit.Assert.assertFalse;
810
import static org.junit.Assert.assertTrue;
911

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

1618
@Test
1719
public void execute() throws Exception {
@@ -28,4 +30,17 @@ public void execute() throws Exception {
2830
String[] lines = output.split(System.getProperty("line.separator"));
2931
assertTrue(lines.length > 0);
3032
}
33+
34+
@Test
35+
public void run() throws Exception {
36+
// Geometry from options
37+
String result = runApp(new String[]{
38+
"list"
39+
}, null);
40+
assertFalse(result.isEmpty());
41+
String[] lines = result.split(System.getProperty("line.separator"));
42+
assertTrue(lines.length > 0);
43+
assertTrue(result.contains("buffer"));
44+
assertTrue(result.contains("centroid"));
45+
}
3146
}

src/test/java/org/geometrycommands/LocatePointCommandTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* The LocatePointCommand UnitTest
1111
* @author Jared Erickson
1212
*/
13-
public class LocatePointCommandTest {
13+
public class LocatePointCommandTest 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("0.25", writer.getBuffer().toString());
3030
}
31+
32+
@Test
33+
public void run() throws Exception {
34+
// Geometry from options
35+
String result = runApp(new String[]{
36+
"locatepoint",
37+
"-g", "LINESTRING (0 0, 5 5, 10 10)",
38+
"-o", "POINT (2.5 2.5)"
39+
}, null);
40+
assertEquals(0.25, Double.parseDouble(result), 0.01);
41+
42+
// Geometry from input stream
43+
result = runApp(new String[]{
44+
"locatepoint",
45+
"-o", "POINT (2.5 2.5)"
46+
}, "LINESTRING (0 0, 5 5, 10 10)");
47+
assertEquals(0.25, Double.parseDouble(result), 0.01);
48+
}
3149
}

src/test/java/org/geometrycommands/MinimumBoundingCircleCommandTest.java

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,40 @@
1010
* The MinimumBoundingCircleCommand UnitTest
1111
* @author Jared Erickson
1212
*/
13-
public class MinimumBoundingCircleCommandTest {
13+
public class MinimumBoundingCircleCommandTest extends BaseTest {
14+
15+
private final String inputGeometry = "MULTIPOINT ((12.27256417862947 12.73833434783841), "
16+
+ "(13.737894633461437 7.658802439672621), "
17+
+ "(6.857126638942733 8.821305316892328), "
18+
+ "(9.260874914207697 13.087320259444919), "
19+
+ "(8.017822881853032 7.492806794533148))";
20+
21+
private final String resultGeometry = "POLYGON ((14.261208198913506 9.566699017816614, "
22+
+ "14.189353574798158 8.83714677603589, 13.976551035360327 "
23+
+ "8.13563081776919, 13.630978462849573 7.489110007878018, "
24+
+ "13.165916017428149 6.9224297785134485, 12.599235788063577 "
25+
+ "6.457367333092024, 11.952714978172406 6.111794760581269, "
26+
+ "11.251199019905705 5.898992221143438, 10.521646778124982 "
27+
+ "5.82713759702809, 9.792094536344258 5.898992221143438, "
28+
+ "9.090578578077558 6.111794760581269, 8.444057768186386 "
29+
+ "6.457367333092024, 7.877377538821817 6.922429778513448, "
30+
+ "7.412315093400392 7.489110007878018, 7.066742520889636 "
31+
+ "8.13563081776919, 6.853939981451806 8.837146776035892, "
32+
+ "6.782085357336458 9.566699017816617, 6.853939981451807 "
33+
+ "10.29625125959734, 7.066742520889639 10.997767217864043, "
34+
+ "7.4123150934003945 11.644288027755213, 7.87737753882182 "
35+
+ "12.210968257119784, 8.444057768186392 12.676030702541208, "
36+
+ "9.090578578077565 13.021603275051962, 9.792094536344267 "
37+
+ "13.234405814489792, 10.52164677812499 13.306260438605138, "
38+
+ "11.251199019905716 13.234405814489788, 11.952714978172416 "
39+
+ "13.021603275051955, 12.599235788063588 12.676030702541198, "
40+
+ "13.165916017428156 12.21096825711977, 13.63097846284958 "
41+
+ "11.644288027755199, 13.976551035360332 10.997767217864025, "
42+
+ "14.189353574798162 10.296251259597323, 14.261208198913506 "
43+
+ "9.566699017816614))";
1444

1545
@Test
1646
public void execute() throws Exception {
17-
18-
String inputGeometry = "MULTIPOINT ((12.27256417862947 12.73833434783841), "
19-
+ "(13.737894633461437 7.658802439672621), "
20-
+ "(6.857126638942733 8.821305316892328), "
21-
+ "(9.260874914207697 13.087320259444919), "
22-
+ "(8.017822881853032 7.492806794533148))";
2347
GeometryOptions options = new GeometryOptions();
2448
options.setGeometry(inputGeometry);
2549

@@ -28,28 +52,22 @@ public void execute() throws Exception {
2852

2953
MinimumBoundingCircleCommand command = new MinimumBoundingCircleCommand();
3054
command.execute(options, reader, writer);
31-
assertEquals("POLYGON ((14.261208198913506 9.566699017816614, "
32-
+ "14.189353574798158 8.83714677603589, 13.976551035360327 "
33-
+ "8.13563081776919, 13.630978462849573 7.489110007878018, "
34-
+ "13.165916017428149 6.9224297785134485, 12.599235788063577 "
35-
+ "6.457367333092024, 11.952714978172406 6.111794760581269, "
36-
+ "11.251199019905705 5.898992221143438, 10.521646778124982 "
37-
+ "5.82713759702809, 9.792094536344258 5.898992221143438, "
38-
+ "9.090578578077558 6.111794760581269, 8.444057768186386 "
39-
+ "6.457367333092024, 7.877377538821817 6.922429778513448, "
40-
+ "7.412315093400392 7.489110007878018, 7.066742520889636 "
41-
+ "8.13563081776919, 6.853939981451806 8.837146776035892, "
42-
+ "6.782085357336458 9.566699017816617, 6.853939981451807 "
43-
+ "10.29625125959734, 7.066742520889639 10.997767217864043, "
44-
+ "7.4123150934003945 11.644288027755213, 7.87737753882182 "
45-
+ "12.210968257119784, 8.444057768186392 12.676030702541208, "
46-
+ "9.090578578077565 13.021603275051962, 9.792094536344267 "
47-
+ "13.234405814489792, 10.52164677812499 13.306260438605138, "
48-
+ "11.251199019905716 13.234405814489788, 11.952714978172416 "
49-
+ "13.021603275051955, 12.599235788063588 12.676030702541198, "
50-
+ "13.165916017428156 12.21096825711977, 13.63097846284958 "
51-
+ "11.644288027755199, 13.976551035360332 10.997767217864025, "
52-
+ "14.189353574798162 10.296251259597323, 14.261208198913506 "
53-
+ "9.566699017816614))", writer.getBuffer().toString());
55+
assertEquals(resultGeometry, writer.getBuffer().toString());
56+
}
57+
58+
@Test
59+
public void run() throws Exception {
60+
// Geometry from options
61+
String result = runApp(new String[]{
62+
"mincircle",
63+
"-g", inputGeometry,
64+
}, null);
65+
assertEquals(resultGeometry, result);
66+
67+
// Geometry from input stream
68+
result = runApp(new String[]{
69+
"mincircle"
70+
}, inputGeometry);
71+
assertEquals(resultGeometry, result);
5472
}
5573
}

src/test/java/org/geometrycommands/MinimumClearanceCommandTest.java

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

1616
@Test
1717
public void execute() throws Exception {
@@ -31,4 +31,28 @@ public void execute() throws Exception {
3131
assertEquals("LINESTRING (12.36083984375 45.9765625, "
3232
+ "13.439104121814852 45.510413314286374)", writer.getBuffer().toString());
3333
}
34+
35+
@Test
36+
public void run() throws Exception {
37+
// Geometry from options
38+
String result = runApp(new String[]{
39+
"minclearance",
40+
"-g", "POLYGON ((15.92041015625 51.25, 6.91162109375 "
41+
+ "52.5244140625, 12.36083984375 45.9765625, 5.46142578125 "
42+
+ "40.7470703125, 11.56982421875 41.1865234375, "
43+
+ "15.92041015625 51.25))"
44+
}, null);
45+
assertEquals("LINESTRING (12.36083984375 45.9765625, "
46+
+ "13.439104121814852 45.510413314286374)", result);
47+
48+
// Geometry from input stream
49+
result = runApp(new String[]{
50+
"minclearance"
51+
}, "POLYGON ((15.92041015625 51.25, 6.91162109375 "
52+
+ "52.5244140625, 12.36083984375 45.9765625, 5.46142578125 "
53+
+ "40.7470703125, 11.56982421875 41.1865234375, "
54+
+ "15.92041015625 51.25))");
55+
assertEquals("LINESTRING (12.36083984375 45.9765625, "
56+
+ "13.439104121814852 45.510413314286374)", result);
57+
}
3458
}

src/test/java/org/geometrycommands/MinimumDiameterCommandTest.java

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

1515
@Test
1616
public void execute() throws Exception {
@@ -30,4 +30,28 @@ public void execute() throws Exception {
3030
assertEquals("LINESTRING (14.966024044129165 49.042379599235645, "
3131
+ "6.91162109375 52.5244140625)", writer.getBuffer().toString());
3232
}
33+
34+
@Test
35+
public void run() throws Exception {
36+
// Geometry from options
37+
String result = runApp(new String[]{
38+
"mindiameter",
39+
"-g", "POLYGON ((15.92041015625 51.25, 6.91162109375 "
40+
+ "52.5244140625, 12.36083984375 45.9765625, 5.46142578125 "
41+
+ "40.7470703125, 11.56982421875 41.1865234375, "
42+
+ "15.92041015625 51.25))",
43+
}, null);
44+
assertEquals("LINESTRING (14.966024044129165 49.042379599235645, "
45+
+ "6.91162109375 52.5244140625)", result);
46+
47+
// Geometry from input stream
48+
result = runApp(new String[]{
49+
"mindiameter"
50+
}, "POLYGON ((15.92041015625 51.25, 6.91162109375 "
51+
+ "52.5244140625, 12.36083984375 45.9765625, 5.46142578125 "
52+
+ "40.7470703125, 11.56982421875 41.1865234375, "
53+
+ "15.92041015625 51.25))");
54+
assertEquals("LINESTRING (14.966024044129165 49.042379599235645, "
55+
+ "6.91162109375 52.5244140625)", result);
56+
}
3357
}

src/test/java/org/geometrycommands/MinimumRectangleCommandTest.java

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

1515
@Test
1616
public void execute() throws Exception {
@@ -34,4 +34,34 @@ public void execute() throws Exception {
3434
+ "13.737894633461437 7.658802439672627))",
3535
writer.getBuffer().toString());
3636
}
37+
38+
@Test
39+
public void run() throws Exception {
40+
// Geometry from options
41+
String result = runApp(new String[]{
42+
"minrect",
43+
"-g", "MULTIPOINT ((12.27256417862947 12.73833434783841), "
44+
+ "(13.737894633461437 7.658802439672621), "
45+
+ "(6.857126638942733 8.821305316892328), "
46+
+ "(9.260874914207697 13.087320259444919), "
47+
+ "(8.017822881853032 7.492806794533148))",
48+
}, null);
49+
assertEquals("POLYGON ((13.737894633461437 7.658802439672627, "
50+
+ "13.576725239178604 13.212565604281293, 6.7354542973976805 "
51+
+ "13.014032922722615, 6.896623691680514 7.460269758113947, "
52+
+ "13.737894633461437 7.658802439672627))", result);
53+
54+
// Geometry from input stream
55+
result = runApp(new String[]{
56+
"minrect"
57+
}, "MULTIPOINT ((12.27256417862947 12.73833434783841), "
58+
+ "(13.737894633461437 7.658802439672621), "
59+
+ "(6.857126638942733 8.821305316892328), "
60+
+ "(9.260874914207697 13.087320259444919), "
61+
+ "(8.017822881853032 7.492806794533148))");
62+
assertEquals("POLYGON ((13.737894633461437 7.658802439672627, "
63+
+ "13.576725239178604 13.212565604281293, 6.7354542973976805 "
64+
+ "13.014032922722615, 6.896623691680514 7.460269758113947, "
65+
+ "13.737894633461437 7.658802439672627))", result);
66+
}
3767
}

0 commit comments

Comments
 (0)