/*
 *    GeoTools - OpenSource mapping toolkit
 *    http://geotools.org
 *    (C) 2005-2006, Geotools Project Managment Committee (PMC)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation; either
 *    version 2.1 of the License, or (at your option) any later version.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */
package org.geotools.referencing.operation.projection;

// JUnit dependencies
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

// OpenGIS dependencies
import org.opengis.referencing.operation.TransformException;


/**
 * Tests the {@link NewZealandMapGrid} implementation.
 *
 * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/test/java/org/geotools/referencing/operation/projection/NewZealandMapGridTest.java $
 * @version $Id: NewZealandMapGridTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
 * @author Justin Deoliveira
 */
public final class NewZealandMapGridTest extends TestCase {
    /**
     * Run the suite from the command line.
     */
    public static void main(String[] args) {
        org.geotools.util.logging.Logging.GEOTOOLS.forceMonolineConsoleOutput();
        junit.textui.TestRunner.run(suite());
    }

    /**
     * Returns the test suite.
     */
    public static Test suite() {
        return new TestSuite(NewZealandMapGridTest.class);
    }

    /**
     * Sets of geographic coordinates to project.
     */
    private static final double[] GEOGRAPHIC = {
        172.739194,  -34.444066,
        172.723106,  -40.512409,
        169.172062,  -46.651295
    };

    /**
     * Set of projected coordinates.
     */
    private static final double[] PROJECTED = {
        2487100.638,  6751049.719,
        2486533.395,  6077263.661,
        2216746.425,  5388508.765
    };

    /**
     * Computes the forward transform and compares against the expected result.
     */
	public void testTransform() throws TransformException {
		double[] dst = new double[6];
		new NewZealandMapGrid().transform(GEOGRAPHIC, 0, dst, 0, 3);
		for (int i=0; i<PROJECTED.length; i++) {
			assertEquals(PROJECTED[i], dst[i], 0.1);   // 10 cm precision
		}
	}

    /**
     * Computes the inverse transform and compares against the expected result.
     */
	public void testInverseTransform() throws TransformException {
		double[] dst = new double[6];
		new NewZealandMapGrid().inverse().transform(PROJECTED, 0, dst, 0, 3);
		for (int i=0; i<GEOGRAPHIC.length; i++) {
			assertEquals(GEOGRAPHIC[i], dst[i], 0.0001); // About 10 m precision
		}
	}

    /**
     * Tests WKT formatting.
     */
    public void testWKT() {
        final String wkt = new NewZealandMapGrid().toWKT();
        assertTrue(wkt.indexOf("central_meridian") >= 0);
    }
}
