Skip to content
This repository has been archived by the owner on Mar 27, 2018. It is now read-only.

Commit

Permalink
Fixup unit tests after scanpointgenerator changes
Browse files Browse the repository at this point in the history
generator.names has been renamed to generator.axes

generator.num has been renamed to generator.size

Units given to generators now need to be an array matching the length of
the given axes array.

The random offset algorithm has changed, and value comparisons need to
be updated.
  • Loading branch information
c-mita committed Feb 24, 2017
1 parent e493d97 commit 9c1fa49
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ public LineIterator(OneDEqualSpacingGenerator gen) {
double yStep = step * Math.sin(line.getAngle());

PyList names = new PyList(Arrays.asList(new String[] {model.getFastAxisName(), model.getSlowAxisName()}));
PyList units = new PyList(Arrays.asList(new String[] {"mm", "mm"}));
double[] start = {line.getxStart() + xStep/2, line.getyStart() + yStep/2};
double[] stop = {line.getxStart() + xStep * (numPoints - 0.5), line.getyStart() + yStep * (numPoints - 0.5)};

@SuppressWarnings("unchecked")
Iterator<IPosition> iterator = (Iterator<IPosition>) lineGeneratorFactory.createObject(
names, "mm", start, stop, numPoints);
names, units, start, stop, numPoints);
pyIterator = iterator;
}

Expand All @@ -78,12 +79,13 @@ public LineIterator(OneDStepGenerator gen) {
double yStep = model.getStep() * Math.sin(line.getAngle());

PyList names = new PyList(Arrays.asList(new String[] {model.getFastAxisName(), model.getSlowAxisName()}));
PyList units = new PyList(Arrays.asList(new String[] {"mm", "mm"}));
double[] start = {line.getxStart(), line.getyStart()};
double[] stop = {line.getxStart() + xStep * numPoints, line.getyStart() + yStep * numPoints};

@SuppressWarnings("unchecked")
Iterator<IPosition> iterator = (Iterator<IPosition>) lineGeneratorFactory.createObject(
names, "mm", start, stop, numPoints);
names, units, start, stop, numPoints);
pyIterator = iterator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.scanning.test.points;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -146,11 +147,11 @@ public void testSimpleToDict() throws Exception {
PyList gens = (PyList) dict.get("generators");
PyDictionary line1 = (PyDictionary) gens.get(0);

assertEquals("Temperature", (String) ((PyList) line1.get("name")).get(0));
assertEquals("mm", line1.get("units"));
assertEquals("Temperature", (String) ((PyList) line1.get("axes")).get(0));
assertArrayEquals(new String[] {"mm"}, ((PyList) line1.get("units")).toArray());
assertEquals(290.0, (double) ((PyList) line1.get("start")).get(0), 1E-10);
assertEquals(295.0, (double) ((PyList) line1.get("stop")).get(0), 1E-10);
assertEquals(6, (int) line1.get("num"));
assertEquals(6, (int) line1.get("size"));

PyList excluders = (PyList) dict.get("excluders");
PyList mutators = (PyList) dict.get("mutators");
Expand All @@ -171,17 +172,17 @@ public void testNestedToDict() throws Exception {
PyDictionary line1 = (PyDictionary) gens.get(0);
PyDictionary line2 = (PyDictionary) gens.get(1);

assertEquals("Temperature", (String) ((PyList) line1.get("name")).get(0));
assertEquals("mm", line1.get("units"));
assertEquals("Temperature", (String) ((PyList) line1.get("axes")).get(0));
assertArrayEquals(new String[] {"mm"}, ((PyList) line1.get("units")).toArray());
assertEquals(290.0, (double) ((PyList) line1.get("start")).get(0), 1E-10);
assertEquals(295.0, (double) ((PyList) line1.get("stop")).get(0), 1E-10);
assertEquals(6, (int) line1.get("num"));
assertEquals(6, (int) line1.get("size"));

assertEquals("Position", (String) ((PyList) line2.get("name")).get(0));
assertEquals("mm", line2.get("units"));
assertEquals("Position", (String) ((PyList) line2.get("axes")).get(0));
assertArrayEquals(new String[] {"mm"}, ((PyList) line1.get("units")).toArray());
assertEquals(1.0, (double) ((PyList) line2.get("start")).get(0), 1E-10);
assertEquals(4.0, (double) ((PyList) line2.get("stop")).get(0), 1E-10);
assertEquals(6, (int) line2.get("num"));
assertEquals(6, (int) line2.get("size"));

PyList excluders = (PyList) dict.get("excluders");
PyList mutators = (PyList) dict.get("mutators");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@

package org.eclipse.scanning.test.points;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import java.util.List;
import java.util.Iterator;

import org.eclipse.scanning.api.points.IPointGenerator;
import org.eclipse.scanning.api.points.IPointGeneratorService;
import org.eclipse.scanning.api.points.IPosition;
import org.eclipse.scanning.api.points.Point;
import org.eclipse.scanning.api.points.models.BoundingBox;
import org.eclipse.scanning.api.points.models.GridModel;
import org.eclipse.scanning.api.points.models.RandomOffsetGridModel;
import org.eclipse.scanning.points.PointGeneratorService;
import org.junit.Before;
Expand All @@ -44,22 +45,27 @@ public void testSimpleBox() throws Exception {
box.setFastAxisLength(5);
box.setSlowAxisLength(10);

RandomOffsetGridModel model = new RandomOffsetGridModel("x", "y");
model.setSlowAxisPoints(5);
model.setFastAxisPoints(5);
model.setBoundingBox(box);
model.setSeed(10);
model.setOffset(25);
RandomOffsetGridModel rm = new RandomOffsetGridModel("x", "y");
rm.setSlowAxisPoints(5);
rm.setFastAxisPoints(5);
rm.setBoundingBox(box);
rm.setSeed(10);
rm.setOffset(25);
IPointGenerator<RandomOffsetGridModel> rg = service.createGenerator(rm);
GeneratorUtil.testGeneratorPoints(rg, 5, 5);

IPointGenerator<RandomOffsetGridModel> gen = service.createGenerator(model);
List<IPosition> pointList = gen.createPoints();

assertEquals(new Point("x", 0, 0.012403455250000084,"y", 0, 0.09924303325000006), pointList.get(0));
assertEquals(new Point("x", 1, 0.837235318,"y", 0, 0.1643560529999999), pointList.get(1));
assertEquals(new Point("x", 2, 2.20470153075,"y", 0, 0.018593022749999966), pointList.get(2));
assertEquals(new Point("x", 3, 3.057925353,"y", 0, -0.024424061750000003), pointList.get(3));
assertEquals(new Point("x", 4, 3.78130160075,"y", 0, 0.021858763000000003), pointList.get(4));
assertEquals(new Point("x", 0, 0.09698760274999996,"y", 1, 1.83863665575), pointList.get(5));
GridModel m = new GridModel("x", "y");
m.setSlowAxisPoints(5);
m.setFastAxisPoints(5);
m.setBoundingBox(box);
IPointGenerator<GridModel> g = service.createGenerator(m);

for (Iterator<IPosition> it1 = rg.iterator(), it2 = g.iterator(); it1.hasNext() && it2.hasNext();) {
IPosition t1 = it1.next();
IPosition t2 = it2.next();
assertTrue(Math.abs(t1.getValue("x") - t2.getValue("x")) <= 0.25 * 1.25);
assertTrue(Math.abs(t1.getValue("y") - t2.getValue("y")) <= 0.25 * 2.5);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ public void testJLineGeneratorFactory2D() {
JythonObjectFactory lineGeneratorFactory = ScanPointGeneratorFactory.JLineGenerator2DFactory();

PyList names = new PyList(Arrays.asList(new String[] {"X", "Y"}));
PyList units = new PyList(Arrays.asList(new String[] {"mm", "mm"}));
double[] start = {1.0, 2.0};
double[] stop = {5.0, 10.0};

@SuppressWarnings("unchecked")
Iterator<IPosition> iterator = (Iterator<IPosition>) lineGeneratorFactory.createObject(
names, "mm", start, stop, 5);
names, units, start, stop, 5);

List<Object> expected_points = new ArrayList<Object>();
expected_points.add(new Point("X", 0, 1.0, "Y", 0, 2.0, false));
Expand Down Expand Up @@ -160,12 +161,13 @@ public void testJLissajousGeneratorFactory() {
box.put("centre", new double[] {0.0, 0.0});

PyList names = new PyList(Arrays.asList(new String[] {"X", "Y"}));
PyList units = new PyList(Arrays.asList(new String[] {"mm", "mm"}));
int numLobes = 2;
int numPoints = 500;

@SuppressWarnings("unchecked")
Iterator<IPosition> iterator = (Iterator<IPosition>) lissajousGeneratorFactory.createObject(
names, "mm", box, numLobes, numPoints);
names, units, box, numLobes, numPoints);

List<Object> expected_points = new ArrayList<Object>();
expected_points.add(new Point("X", 0, 0.0, "Y", 0, 0.0, false));
Expand Down Expand Up @@ -263,28 +265,20 @@ public void testJCompoundGeneratorFactoryWithMutatedRaster() {
generators, excluders, mutators);

List<Object> expected_points = new ArrayList<Object>();
// expected_points.add(new MapPosition("x:0:1.1984860665000001, y:0:2.0248069105"));
// expected_points.add(new MapPosition("x:1:2.328712106, y:0:1.674470636"));
// expected_points.add(new MapPosition("x:2:3.0371860455, y:0:2.4094030615"));
// expected_points.add(new MapPosition("x:3:3.9511518765, y:0:2.115850706"));
// expected_points.add(new MapPosition("x:4:5.043717526, y:0:1.5626032015"));
// expected_points.add(new MapPosition("x:0:0.6772733115, y:1:4.1939752055"));
// expected_points.add(new MapPosition("x:1:1.5828061555000001, y:1:3.9489767459999996"));
// expected_points.add(new MapPosition("x:2:3.3888981960000004, y:1:3.661987452"));
// expected_points.add(new MapPosition("x:3:3.9093635265, y:1:4.2730717205"));
// expected_points.add(new MapPosition("x:4:4.554744956, y:1:3.8436031415"));
expected_points.add(new Point("x", 0, 1.0248069105000002, "y", 0, 2.1984860665));
expected_points.add(new Point("x", 1, 1.674470636, "y", 0, 2.328712106));
expected_points.add(new Point("x", 2, 3.4094030615, "y", 0, 2.0371860455));
expected_points.add(new Point("x", 3, 4.115850706, "y", 0, 1.9511518765));
expected_points.add(new Point("x", 4, 4.5626032015, "y", 0, 2.043717526));
expected_points.add(new Point("x", 0, 1.1939752055, "y", 1, 3.6772733115));
expected_points.add(new Point("x", 1, 1.9489767459999996, "y", 1, 3.5828061555000001));
expected_points.add(new Point("x", 2, 2.661987452, "y", 1, 4.3888981960000004));
expected_points.add(new Point("x", 3, 4.2730717205, "y", 1, 3.9093635265));
expected_points.add(new Point("x", 4, 4.8436031415, "y", 1, 3.554744956));

int index = 0;
// This list of values can be regenerated by running the iterator and printing
// the points. The toString() method is then inverted to a Point using parse.
expected_points.add(Point.parse("y(0)=2.3467273793292063, x(0)=1.3423125841287693"));
expected_points.add(Point.parse("y(0)=1.9389526430608128, x(1)=2.386072452619223"));
expected_points.add(Point.parse("y(0)=2.2767811479924203, x(2)=3.2131047487987914"));
expected_points.add(Point.parse("y(0)=1.585269318447744, x(3)=3.9674925148644236"));
expected_points.add(Point.parse("y(0)=2.397560627408689, x(4)=5.266805527444651"));
expected_points.add(Point.parse("y(1)=3.5015289536680863, x(0)=1.3197151394141176"));
expected_points.add(Point.parse("y(1)=4.341493416307841, x(1)=2.150155718356873"));
expected_points.add(Point.parse("y(1)=4.480657927454603, x(2)=3.377400373778632"));
expected_points.add(Point.parse("y(1)=4.1811883078611425, x(3)=4.067826935687993"));
expected_points.add(Point.parse("y(1)=4.308295570036465, x(4)=4.779800611147611"));

int index = 0;
while (iterator.hasNext() && index < 10){ // Just get first few points

Object point = iterator.next();
Expand Down

0 comments on commit 9c1fa49

Please sign in to comment.