package org.geometrycommands;

import org.geometrycommands.EqualsCommand.EqualsOptions;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * The EqualsCommand UnitTest
 * @author Jared Erickson
 */
public class EqualsCommandTest extends BaseTest {

    @Test
    public void execute() throws Exception {

        // true
        String inputGeometry = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))";
        String otherGeometry = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))";
        EqualsOptions options = new EqualsOptions();
        options.setGeometry(inputGeometry);
        options.setOtherGeometry(otherGeometry);

        Reader reader = new StringReader(inputGeometry);
        StringWriter writer = new StringWriter();

        EqualsCommand command = new EqualsCommand();
        command.execute(options, reader, writer);
        assertEquals("true", writer.getBuffer().toString());

        // false
        inputGeometry = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))";
        otherGeometry = "POLYGON ((1 1, 1 10, 10 10, 10 1, 1 1))";
        options = new EqualsOptions();
        options.setGeometry(inputGeometry);
        options.setOtherGeometry(otherGeometry);

        reader = new StringReader(inputGeometry);
        writer = new StringWriter();

        command = new EqualsCommand();
        command.execute(options, reader, writer);
        assertEquals("false", writer.getBuffer().toString());
    }

    @Test
    public void run() throws Exception {
        // Geometry from options
        String result = runApp(new String[]{
                "equals",
                "-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))",
                "-o", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))"
        }, null);
        assertTrue(Boolean.parseBoolean(result));

        // Geometry from input stream
        result = runApp(new String[]{
                "equals",
                "-o", "POLYGON ((1 1, 1 10, 10 10, 10 1, 1 1))"
        }, "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
        assertFalse(Boolean.parseBoolean(result));
    }
}

@@ -1595,16 +1595,1683 @@
 ring());
+%0A%0A        // exact%0A        inputGeometry = %22POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))%22;%0A        otherGeometry = %22POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))%22;%0A        options = new EqualsOptions();%0A        options.setGeometry(inputGeometry);%0A        options.setOtherGeometry(otherGeometry);%0A        options.setType(%22exact%22);%0A%0A        reader = new StringReader(inputGeometry);%0A        writer = new StringWriter();%0A%0A        command = new EqualsCommand();%0A        command.execute(options, reader, writer);%0A        assertEquals(%22true%22, writer.getBuffer().toString());%0A%0A        // norm%0A        inputGeometry = %22POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))%22;%0A        otherGeometry = %22POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))%22;%0A        options = new EqualsOptions();%0A        options.setGeometry(inputGeometry);%0A        options.setOtherGeometry(otherGeometry);%0A        options.setType(%22norm%22);%0A%0A        reader = new StringReader(inputGeometry);%0A        writer = new StringWriter();%0A%0A        command = new EqualsCommand();%0A        command.execute(options, reader, writer);%0A        assertEquals(%22true%22, writer.getBuffer().toString());%0A%0A        // topo%0A        inputGeometry = %22POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))%22;%0A        otherGeometry = %22POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))%22;%0A        options = new EqualsOptions();%0A        options.setGeometry(inputGeometry);%0A        options.setOtherGeometry(otherGeometry);%0A        options.setType(%22topo%22);%0A%0A        reader = new StringReader(inputGeometry);%0A        writer = new StringWriter();%0A%0A        command = new EqualsCommand();%0A        command.execute(options, reader, writer);%0A        assertEquals(%22true%22, writer.getBuffer().toString());
 %0A    %7D%0A%0A

Increase test coverage of equals command