/*
 * #%L
 * ImgLib2: a general-purpose, multidimensional image processing library.
 * %%
 * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia,
 * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves
 * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris,
 * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier,
 * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov.
 * %%
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * 
 * The views and conclusions contained in the software and documentation are
 * those of the authors and should not be interpreted as representing official
 * policies, either expressed or implied, of any organization.
 * #L%
 */

package net.imglib2.meta;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import net.imglib2.meta.axis.LinearAxis;

import org.junit.Test;

/**
 * @author Barry DeZonia
 */
public class DefaultCalibratedRealIntervalTest {

	private DefaultCalibratedRealInterval interval;

	@Test
	public void test1() {
		double[] extents = new double[]{5,10,20};
		double[] temp = new double[extents.length];
		CalibratedAxis[] axes = new CalibratedAxis[extents.length];
		interval = new DefaultCalibratedRealInterval(extents);
		assertEquals(extents.length, interval.numDimensions());
		interval.realMin(temp);
		assertArrayEquals(new double[3], temp, 0);
		interval.realMax(temp);
		assertArrayEquals(new double[] { 5, 10, 20 }, temp, 0);
		interval.axes(axes);
		// TODO - this is a little surprising
		for (CalibratedAxis axis : axes) {
			assertNull(axis);
		}
		for (int i = 0; i < extents.length; i++) {
			// TODO can't run this as default interval ctor has null axes
			// assertEquals(Double.NaN, interval.axis(i).averageScale(0, 1), 0);
			assertNull(interval.axis(i).unit());
		}
		LinearAxis axis = new LinearAxis(Axes.X, "plorps", 4);
		interval.setAxis(axis, 0);
		assertEquals(Axes.X, interval.axis(0).type());
		assertEquals("plorps", interval.axis(0).unit());
		assertEquals(4, interval.axis(0).averageScale(0, 1), 0);
	}

	@Test
	public void test2() {
		double[] extents = new double[] { 5, 10, 20 };
		double[] temp = new double[extents.length];
		CalibratedAxis axis0 = new LinearAxis(Axes.LIFETIME, "froop", 1);
		CalibratedAxis axis1 = new LinearAxis(Axes.PHASE, "orp", 3);
		CalibratedAxis axis2 = new LinearAxis(Axes.POLARIZATION, "smump", 5);
		interval = new DefaultCalibratedRealInterval(extents, axis0, axis1, axis2);
		assertEquals(extents.length, interval.numDimensions());
		interval.realMin(temp);
		assertArrayEquals(new double[3], temp, 0);
		interval.realMax(temp);
		assertArrayEquals(new double[] { 5, 10, 20 }, temp, 0);
		CalibratedAxis[] axes = new CalibratedAxis[extents.length];
		interval.axes(axes);
		for (CalibratedAxis axis : axes) {
			assertNotNull(axis);
		}
		assertEquals(Axes.LIFETIME, interval.axis(0).type());
		assertEquals(Axes.PHASE, interval.axis(1).type());
		assertEquals(Axes.POLARIZATION, interval.axis(2).type());
		assertEquals("froop", interval.axis(0).unit());
		assertEquals("orp", interval.axis(1).unit());
		assertEquals("smump", interval.axis(2).unit());
		assertEquals(1, interval.axis(0).averageScale(0, 1), 0);
		assertEquals(3, interval.axis(1).averageScale(0, 1), 0);
		assertEquals(5, interval.axis(2).averageScale(0, 1), 0);
	}

}

@@ -2217,16 +2217,58 @@
 rtNull;%0A
+import static org.junit.Assert.assertSame;
 %0Aimport 
@@ -2485,24 +2485,81 @@
 d test1() %7B%0A
+%09%09// verify that interval extents are assigned correctly%0A
 %09%09double%5B%5D e
@@ -2974,76 +2974,93 @@
 ;%0A%09%09
-interval.axes(axes);%0A%09%09// TODO - this is a little surprising
+// verify that axes are not yet populated (i.e., null)%0A%09%09interval.axes(axes);
 %0A%09%09for (
 Cali
@@ -3047,32 +3047,38 @@
 s(axes);%0A%09%09for (
+final 
 CalibratedAxis a
@@ -3168,428 +3168,208 @@
 %0A%09%09%09
-// TODO can't run this as default interval ctor has null axes%0A%09%09%09// assertEquals(Double.NaN, interval.axis(i).averageScale(0, 1), 0);%0A%09%09%09assertNull(interval.axis(i).unit());%0A%09%09%7D%0A%09%09LinearAxis axis = new LinearAxis(Axes.X, %22plorps%22, 4);%0A%09%09interval.setAxis(axis, 0);%0A%09%09assertEquals(Axes.X, interval.axis(0).type());%0A%09%09assertEquals(%22plorps%22, interval.axis(0).unit());%0A%09%09assertEquals(4, interval.axis(0).averageScale(0, 1), 0
+assertNull(interval.axis(i));%0A%09%09%7D%0A%09%09// verify that axes are assigned correctly%0A%09%09LinearAxis axis = new LinearAxis(Axes.X, %22plorps%22, 4);%0A%09%09interval.setAxis(axis, 0);%0A%09%09assertSame(axis, interval.axis(0)
 );%0A%09

fix up test1