/**
 * 
 */
package org.eclipse.scanning.test.points;

import static org.junit.Assert.assertArrayEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import org.eclipse.scanning.api.points.IPointGenerator;
import org.eclipse.scanning.api.points.IPosition;
import org.eclipse.scanning.api.scan.ScanEstimator;

/**
 * @author Matthew Gerring
 *
 */
class GeneratorUtil {

	/**
	 * Checks the points list vs the iterator
	 * @param gen
	 * @throws Exception 
	 */
	public static void testGeneratorPoints(IPointGenerator<?> gen, int... expectedShape) throws Exception {
		
		final List ponts = gen.createPoints();
		final List its   = new ArrayList<>(gen.size());
		final Iterator it = gen.iterator();
		while(it.hasNext()) its.add(it.next());
		
		IPosition[] pnts1 = array(ponts);
		IPosition[] pnts2 = array(its);
		
		if (pnts2.length!=pnts1.length) throw new Exception("Not the same size! Iterator size is "+its.size()+" full list size is "+ponts.size());
        for (int i = 0; i < pnts1.length; i++) {
			if (!pnts1[i].equals(pnts2[i])) {
				throw new Exception(pnts1[i]+" does not equal "+pnts2[i]);
			}
		}
		
		// Check the estimator. In this case it is not doing anything
		// that we don't already know, so we can test it.
		final ScanEstimator estimator = new ScanEstimator(gen, null, 100);
		if (ponts.size()!=estimator.getSize()) throw new Exception("Different size from shape estimator!");

		if (expectedShape!=null && expectedShape.length>0) {// They set one
		    int[] shape = estimator.getShape();
		    assertArrayEquals(expectedShape, shape);
		}
 	}

	private static IPosition[] array(List<IPosition> p) {
		return p.toArray(new IPosition[p.size()]);
	}
}

@@ -131,33 +131,8 @@
 st;%0A
-import java.util.Arrays;%0A
 impo
@@ -461,16 +461,42 @@
 ram gen%0A
+%09 * @param expectedShape %0A
 %09 * @thr
@@ -638,16 +638,17 @@
  List po
+i
 nts = ge
@@ -828,16 +828,17 @@
 array(po
+i
 nts);%0A%09%09
@@ -1000,16 +1000,17 @@
  is %22+po
+i
 nts.size
@@ -1368,16 +1368,17 @@
 %09%09if (po
+i
 nts.size

fix typo of points as ponts in GeneratorUtil