|
| 1 | +package org.geometrycommands; |
| 2 | + |
| 3 | +import org.geometrycommands.HilbertCurveCommand.HilbertCurveOptions; |
| 4 | +import org.junit.Test; |
| 5 | + |
| 6 | +import java.io.Reader; |
| 7 | +import java.io.StringReader; |
| 8 | +import java.io.StringWriter; |
| 9 | + |
| 10 | +import static org.junit.Assert.assertEquals; |
| 11 | + |
| 12 | +/** |
| 13 | + * The HilbertCurveCommand UnitTest |
| 14 | + * @author Jared Erickson |
| 15 | + */ |
| 16 | +public class HilbertCurveCommandTest extends BaseTest { |
| 17 | + |
| 18 | + private final String inputGeometry = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))"; |
| 19 | + |
| 20 | + private final String resultGeometry = "LINESTRING (0 0, 0 1.4285714285714286, 1.4285714285714286 1.4285714285714286, " + |
| 21 | + "1.4285714285714286 0, 2.857142857142857 0, 4.285714285714286 0, 4.285714285714286 1.4285714285714286, " + |
| 22 | + "2.857142857142857 1.4285714285714286, 2.857142857142857 2.857142857142857, 4.285714285714286 2.857142857142857, " + |
| 23 | + "4.285714285714286 4.285714285714286, 2.857142857142857 4.285714285714286, 1.4285714285714286 4.285714285714286, " + |
| 24 | + "1.4285714285714286 2.857142857142857, 0 2.857142857142857, 0 4.285714285714286, 0 5.714285714285714, " + |
| 25 | + "1.4285714285714286 5.714285714285714, 1.4285714285714286 7.142857142857143, 0 7.142857142857143, " + |
| 26 | + "0 8.571428571428571, 0 10, 1.4285714285714286 10, 1.4285714285714286 8.571428571428571, " + |
| 27 | + "2.857142857142857 8.571428571428571, 2.857142857142857 10, 4.285714285714286 10, 4.285714285714286 8.571428571428571, " + |
| 28 | + "4.285714285714286 7.142857142857143, 2.857142857142857 7.142857142857143, 2.857142857142857 5.714285714285714, " + |
| 29 | + "4.285714285714286 5.714285714285714, 5.714285714285714 5.714285714285714, 7.142857142857143 5.714285714285714, " + |
| 30 | + "7.142857142857143 7.142857142857143, 5.714285714285714 7.142857142857143, 5.714285714285714 8.571428571428571, " + |
| 31 | + "5.714285714285714 10, 7.142857142857143 10, 7.142857142857143 8.571428571428571, 8.571428571428571 8.571428571428571, " + |
| 32 | + "8.571428571428571 10, 10 10, 10 8.571428571428571, 10 7.142857142857143, 8.571428571428571 7.142857142857143, " + |
| 33 | + "8.571428571428571 5.714285714285714, 10 5.714285714285714, 10 4.285714285714286, 10 2.857142857142857, " + |
| 34 | + "8.571428571428571 2.857142857142857, 8.571428571428571 4.285714285714286, 7.142857142857143 4.285714285714286, " + |
| 35 | + "5.714285714285714 4.285714285714286, 5.714285714285714 2.857142857142857, 7.142857142857143 2.857142857142857, " + |
| 36 | + "7.142857142857143 1.4285714285714286, 5.714285714285714 1.4285714285714286, 5.714285714285714 0, 7.142857142857143 0, " + |
| 37 | + "8.571428571428571 0, 8.571428571428571 1.4285714285714286, 10 1.4285714285714286, 10 0)"; |
| 38 | + |
| 39 | + @Test |
| 40 | + public void execute() throws Exception { |
| 41 | + |
| 42 | + HilbertCurveOptions options = new HilbertCurveOptions(); |
| 43 | + options.setGeometry(inputGeometry); |
| 44 | + options.setNumberOfPoints(30); |
| 45 | + |
| 46 | + Reader reader = new StringReader(inputGeometry); |
| 47 | + StringWriter writer = new StringWriter(); |
| 48 | + |
| 49 | + HilbertCurveCommand command = new HilbertCurveCommand(); |
| 50 | + command.execute(options, reader, writer); |
| 51 | + assertEquals(resultGeometry, writer.getBuffer().toString()); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void run() throws Exception { |
| 56 | + // Geometry from options |
| 57 | + String result = runApp(new String[]{ |
| 58 | + "hilbertcurve", |
| 59 | + "-g", inputGeometry, |
| 60 | + "-n", "30" |
| 61 | + }, null); |
| 62 | + assertEquals(resultGeometry, result); |
| 63 | + |
| 64 | + // Geometry from input stream |
| 65 | + result = runApp(new String[]{ |
| 66 | + "hilbertcurve", |
| 67 | + "-n", "30" |
| 68 | + }, inputGeometry); |
| 69 | + assertEquals(resultGeometry, result); |
| 70 | + } |
| 71 | +} |
0 commit comments