package org.eclipse.scanning.test.points;

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.eclipse.dawnsci.analysis.dataset.roi.LinearROI;
import org.eclipse.dawnsci.analysis.dataset.roi.RectangularROI;
import org.eclipse.scanning.api.points.GeneratorException;
import org.eclipse.scanning.api.points.IPointGenerator;
import org.eclipse.scanning.api.points.IPointGeneratorService;
import org.eclipse.scanning.api.points.Point;
import org.eclipse.scanning.api.points.models.OneDEqualSpacingModel;
import org.eclipse.scanning.api.points.models.OneDStepModel;
import org.eclipse.scanning.points.PointGeneratorFactory;
import org.junit.Before;
import org.junit.Test;

public class LinearTest {

	// TODO FIXME Test Linear Numerically
	
	private IPointGeneratorService service;
	
	@Before
	public void before() throws Exception {
		service = new PointGeneratorFactory();
	}
	
	@Test
	public void testOneDEqualSpacing() throws Exception {
		
		LinearROI roi = new LinearROI(new double[]{0,0}, new double[]{3,3});

        OneDEqualSpacingModel model = new OneDEqualSpacingModel();
        model.setPoints(10);
		
		// Get the point list
		IPointGenerator<OneDEqualSpacingModel,Point> gen = service.createGenerator(model, roi);
		List<Point> pointList = gen.createPoints();
		
		assertEquals(pointList.size(), gen.size());
		assertEquals(pointList.size(), 10);
        GeneratorUtil.testGeneratorPoints(gen);
	}
	
	@Test(expected = GeneratorException.class)
	public void testOneDEqualSpacingNoROI() throws GeneratorException {
		
        OneDEqualSpacingModel model = new OneDEqualSpacingModel();
        model.setPoints(10);
		
		// Get the point list
		IPointGenerator<OneDEqualSpacingModel,Point> gen = service.createGenerator(model, null);
		gen.createPoints();
	}

	@Test(expected = GeneratorException.class)
	public void testOneDEqualSpacingNoPoints() throws Exception {
		
		LinearROI roi = new LinearROI(new double[]{0,0}, new double[]{3,3});

        OneDEqualSpacingModel model = new OneDEqualSpacingModel();
        model.setPoints(0);
		
		// Get the point list
		IPointGenerator<OneDEqualSpacingModel,Point> gen = service.createGenerator(model, roi);
		List<Point> pointList = gen.createPoints();
        GeneratorUtil.testGeneratorPoints(gen);
	}

	
	@Test
	public void testOneDStep() throws Exception {
		
		LinearROI roi = new LinearROI(new double[]{0,0}, new double[]{3,3});

        OneDStepModel model = new OneDStepModel();
        model.setStep(0.3);
		
		// Get the point list
		IPointGenerator<OneDStepModel,Point> gen = service.createGenerator(model, roi);
		List<Point> pointList = gen.createPoints();
		
		assertEquals(pointList.size(), gen.size());
		assertEquals(15, pointList.size());
        GeneratorUtil.testGeneratorPoints(gen);
	}
	
	@Test(expected = GeneratorException.class)
	public void testOneDStepNoStep() throws Exception {
		
		LinearROI roi = new LinearROI(new double[]{0,0}, new double[]{3,3});

        OneDStepModel model = new OneDStepModel();
        model.setStep(0);
		
		// Get the point list
		IPointGenerator<OneDStepModel,Point> gen = service.createGenerator(model, roi);
		List<Point> pointList = gen.createPoints();
        GeneratorUtil.testGeneratorPoints(gen);
		
	}
	
	@Test(expected = GeneratorException.class)
	public void testOneDStepWrongROI() throws Exception {
		
		RectangularROI roi = new RectangularROI(new double[]{0,0}, new double[]{3,3});

        OneDStepModel model = new OneDStepModel();
        model.setStep(0);
		
		// Get the point list
		IPointGenerator<OneDStepModel,Point> gen = service.createGenerator(model, roi);
		List<Point> pointList = gen.createPoints();
        GeneratorUtil.testGeneratorPoints(gen);
		
	}


}

@@ -3242,24 +3242,468 @@
 n);%0A%09%09%0A%09%7D%0A%09%0A
+%09@Test(expected = GeneratorException.class)%0A%09public void testOneDStepNegativeStep() throws Exception %7B%0A%0A%09%09LinearROI roi = new LinearROI(new double%5B%5D%7B0,0%7D, new double%5B%5D%7B3,3%7D);%0A%0A%09%09OneDStepModel model = new OneDStepModel();%0A%09%09model.setStep(-0.3);%0A%0A%09%09// Get the point list%0A%09%09IPointGenerator%3COneDStepModel,Point%3E gen = service.createGenerator(model, roi);%0A%09%09List%3CPoint%3E pointList = gen.createPoints();%0A%09%09GeneratorUtil.testGeneratorPoints(gen);%0A%0A%09%7D%0A%0A
 %09@Test(expec

Add test for OneDStepModel with negative step size