Skip to content

Commit 596a33c

Browse files
committed
Add more command line tests
1 parent 588b12f commit 596a33c

11 files changed

+246
-11
lines changed

src/test/java/org/geometrycommands/InteriorPointCommandTest.java

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

1515
@Test
1616
public void execute() throws Exception {
@@ -30,4 +30,28 @@ public void execute() throws Exception {
3030
command.execute(options, reader, writer);
3131
assertEquals("POINT (17.205851236979164 46.6796875)", writer.getBuffer().toString());
3232
}
33+
34+
@Test
35+
public void run() throws Exception {
36+
// Geometry from options
37+
String result = runApp(new String[]{
38+
"interiorpoint",
39+
"-g", "POLYGON ((9.89990234375 52.7880859375, "
40+
+ "9.89990234375 49.931640625, 15.39306640625 49.580078125, "
41+
+ "15.48095703125 43.251953125, 8.97705078125 43.251953125, "
42+
+ "9.24072265625 40.615234375, 19.61181640625 40.5712890625, "
43+
+ "18.38134765625 52.4365234375, 9.89990234375 52.7880859375))"
44+
}, null);
45+
assertEquals("POINT (17.205851236979164 46.6796875)", result);
46+
47+
// Geometry from input stream
48+
result = runApp(new String[]{
49+
"interiorpoint"
50+
}, "POLYGON ((9.89990234375 52.7880859375, "
51+
+ "9.89990234375 49.931640625, 15.39306640625 49.580078125, "
52+
+ "15.48095703125 43.251953125, 8.97705078125 43.251953125, "
53+
+ "9.24072265625 40.615234375, 19.61181640625 40.5712890625, "
54+
+ "18.38134765625 52.4365234375, 9.89990234375 52.7880859375))");
55+
assertEquals("POINT (17.205851236979164 46.6796875)", result);
56+
}
3357
}

src/test/java/org/geometrycommands/InterpolatePointCommandTest.java

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

1616
@Test
1717
public void execute() throws Exception {
@@ -28,4 +28,22 @@ public void execute() throws Exception {
2828
command.execute(options, reader, writer);
2929
assertEquals("POINT (2.5 2.5)", writer.getBuffer().toString());
3030
}
31+
32+
@Test
33+
public void run() throws Exception {
34+
// Geometry from options
35+
String result = runApp(new String[]{
36+
"interpolatepoint",
37+
"-g", "LINESTRING (0 0, 5 5, 10 10)",
38+
"-p", "0.25"
39+
}, null);
40+
assertEquals("POINT (2.5 2.5)", result);
41+
42+
// Geometry from input stream
43+
result = runApp(new String[]{
44+
"interpolatepoint",
45+
"-p", "0.25"
46+
}, "LINESTRING (0 0, 5 5, 10 10)");
47+
assertEquals("POINT (2.5 2.5)", result);
48+
}
3149
}

src/test/java/org/geometrycommands/IntersectionCommandTest.java

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

1515
@Test
1616
public void execute() throws Exception {
@@ -29,4 +29,22 @@ public void execute() throws Exception {
2929
assertEquals("POLYGON ((5 10, 10 10, 10 5, 5 5, 5 10))",
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+
"intersection",
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 ((5 10, 10 10, 10 5, 5 5, 5 10))", result);
42+
43+
// Geometry from input stream
44+
result = runApp(new String[]{
45+
"intersection",
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 ((5 10, 10 10, 10 5, 5 5, 5 10))", result);
49+
}
3250
}

src/test/java/org/geometrycommands/IntersectsCommandTest.java

Lines changed: 21 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 IntersectsCommand UnitTest
1113
* @author Jared Erickson
1214
*/
13-
public class IntersectsCommandTest {
15+
public class IntersectsCommandTest extends BaseTest {
1416

1517
@Test
1618
public void execute() throws Exception {
@@ -43,4 +45,22 @@ public void execute() throws Exception {
4345
command.execute(options, reader, writer);
4446
assertEquals("false", writer.getBuffer().toString());
4547
}
48+
49+
@Test
50+
public void run() throws Exception {
51+
// Geometry from options
52+
String result = runApp(new String[]{
53+
"intersects",
54+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))",
55+
"-o", "POINT (5 5)"
56+
}, null);
57+
assertTrue(Boolean.parseBoolean(result));
58+
59+
// Geometry from input stream
60+
result = runApp(new String[]{
61+
"intersects",
62+
"-o", "POINT (15 15)"
63+
}, "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
64+
assertFalse(Boolean.parseBoolean(result));
65+
}
4666
}

src/test/java/org/geometrycommands/IsClosedCommandTest.java

Lines changed: 19 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 IsClosedCommand UnitTest
1113
* @author Jared Erickson
1214
*/
13-
public class IsClosedCommandTest {
15+
public class IsClosedCommandTest extends BaseTest {
1416

1517
@Test
1618
public void execute() throws Exception {
@@ -38,4 +40,20 @@ public void execute() throws Exception {
3840
command.execute(options, reader, writer);
3941
assertEquals("false", writer.getBuffer().toString());
4042
}
43+
44+
@Test
45+
public void run() throws Exception {
46+
// Geometry from options
47+
String result = runApp(new String[]{
48+
"isclosed",
49+
"-g", "LINESTRING (1 1, 1 5, 5 5, 5 1, 1 1)"
50+
}, null);
51+
assertTrue(Boolean.parseBoolean(result));
52+
53+
// Geometry from input stream
54+
result = runApp(new String[]{
55+
"isclosed"
56+
}, "LINESTRING (1 1, 5 5, 10 10)");
57+
assertFalse(Boolean.parseBoolean(result));
58+
}
4159
}

src/test/java/org/geometrycommands/IsEmptyCommandTest.java

Lines changed: 19 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 IsEmptyCommand UnitTest
1113
* @author Jared Erickson
1214
*/
13-
public class IsEmptyCommandTest {
15+
public class IsEmptyCommandTest extends BaseTest {
1416

1517
@Test
1618
public void execute() throws Exception {
@@ -39,4 +41,20 @@ public void execute() throws Exception {
3941
command.execute(options, reader, writer);
4042
assertEquals("false", writer.getBuffer().toString());
4143
}
44+
45+
@Test
46+
public void run() throws Exception {
47+
// Geometry from options
48+
String result = runApp(new String[]{
49+
"isempty",
50+
"-g", "POINT EMPTY"
51+
}, null);
52+
assertTrue(Boolean.parseBoolean(result));
53+
54+
// Geometry from input stream
55+
result = runApp(new String[]{
56+
"isempty"
57+
}, "LINESTRING (1 1, 5 5, 10 10)");
58+
assertFalse(Boolean.parseBoolean(result));
59+
}
4260
}

src/test/java/org/geometrycommands/IsRectangleCommandTest.java

Lines changed: 19 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 IsRectangleCommand UnitTest
1113
* @author Jared Erickson
1214
*/
13-
public class IsRectangleCommandTest {
15+
public class IsRectangleCommandTest extends BaseTest {
1416

1517
@Test
1618
public void execute() throws Exception {
@@ -38,4 +40,20 @@ public void execute() throws Exception {
3840
command.execute(options, reader, writer);
3941
assertEquals("false", writer.getBuffer().toString());
4042
}
43+
44+
@Test
45+
public void run() throws Exception {
46+
// Geometry from options
47+
String result = runApp(new String[]{
48+
"isrectangle",
49+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))"
50+
}, null);
51+
assertTrue(Boolean.parseBoolean(result));
52+
53+
// Geometry from input stream
54+
result = runApp(new String[]{
55+
"isrectangle"
56+
}, "POLYGON ((0 0, 0 10, 10 0, 0 0))");
57+
assertFalse(Boolean.parseBoolean(result));
58+
}
4159
}

src/test/java/org/geometrycommands/IsRingCommandTest.java

Lines changed: 19 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 IsRingCommand UnitTest
1113
* @author Jared Erickson
1214
*/
13-
public class IsRingCommandTest {
15+
public class IsRingCommandTest extends BaseTest {
1416

1517
@Test
1618
public void execute() throws Exception {
@@ -38,4 +40,20 @@ public void execute() throws Exception {
3840
command.execute(options, reader, writer);
3941
assertEquals("false", writer.getBuffer().toString());
4042
}
43+
44+
@Test
45+
public void run() throws Exception {
46+
// Geometry from options
47+
String result = runApp(new String[]{
48+
"isring",
49+
"-g", "LINESTRING (1 1, 1 5, 5 5, 5 1, 1 1)"
50+
}, null);
51+
assertTrue(Boolean.parseBoolean(result));
52+
53+
// Geometry from input stream
54+
result = runApp(new String[]{
55+
"isring"
56+
}, "LINESTRING (1 1, 5 5, 10 10)");
57+
assertFalse(Boolean.parseBoolean(result));
58+
}
4159
}

src/test/java/org/geometrycommands/IsSimpleCommandTest.java

Lines changed: 21 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 IsSimpleCommand UnitTest
1113
* @author Jared Erickson
1214
*/
13-
public class IsSimpleCommandTest {
15+
public class IsSimpleCommandTest extends BaseTest {
1416

1517
@Test
1618
public void execute() throws Exception {
@@ -40,4 +42,22 @@ public void execute() throws Exception {
4042
command.execute(options, reader, writer);
4143
assertEquals("false", writer.getBuffer().toString());
4244
}
45+
46+
@Test
47+
public void run() throws Exception {
48+
// Geometry from options
49+
String result = runApp(new String[]{
50+
"issimple",
51+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))"
52+
}, null);
53+
assertTrue(Boolean.parseBoolean(result));
54+
55+
// Geometry from input stream
56+
result = runApp(new String[]{
57+
"issimple"
58+
}, "LINESTRING (8.14208984375 48.0419921875, "
59+
+ "10.60302734375 51.6015625, 11.56982421875 47.91015625, "
60+
+ "8.36181640625 50.72265625)");
61+
assertFalse(Boolean.parseBoolean(result));
62+
}
4363
}

src/test/java/org/geometrycommands/IsValidCommandTest.java

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

1618
@Test
1719
public void execute() throws Exception {
@@ -62,4 +64,43 @@ public void execute() throws Exception {
6264
command.execute(options, reader, writer);
6365
assertEquals("POINT (15.42700884375309 46.45115927637351)", writer.getBuffer().toString());
6466
}
67+
68+
@Test
69+
public void run() throws Exception {
70+
// Geometry from options
71+
String result = runApp(new String[]{
72+
"isvalid",
73+
"-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))"
74+
}, null);
75+
assertTrue(Boolean.parseBoolean(result));
76+
77+
// Geometry from input stream
78+
result = runApp(new String[]{
79+
"isvalid"
80+
}, "POLYGON ((17.06298828125 49.7998046875, "
81+
+ "14.25048828125 44.04296875, 18.24951171875 44.04296875, "
82+
+ "13.45947265625 48.1298828125, 17.06298828125 "
83+
+ "49.7998046875))");
84+
assertFalse(Boolean.parseBoolean(result));
85+
86+
// message
87+
result = runApp(new String[]{
88+
"isvalid",
89+
"-t", "msg"
90+
}, "POLYGON ((17.06298828125 49.7998046875, "
91+
+ "14.25048828125 44.04296875, 18.24951171875 44.04296875, "
92+
+ "13.45947265625 48.1298828125, 17.06298828125 "
93+
+ "49.7998046875))");
94+
assertEquals("Self-intersection", result);
95+
96+
// location
97+
result = runApp(new String[]{
98+
"isvalid",
99+
"-t", "loc"
100+
}, "POLYGON ((17.06298828125 49.7998046875, "
101+
+ "14.25048828125 44.04296875, 18.24951171875 44.04296875, "
102+
+ "13.45947265625 48.1298828125, 17.06298828125 "
103+
+ "49.7998046875))");
104+
assertEquals("POINT (15.42700884375309 46.45115927637351)", result);
105+
}
65106
}

0 commit comments

Comments
 (0)