@Test public void shouldGetMaximumValuesWithAFrontWithThreePointReturnTheCorrectValue() { int numberOfPoints = 3; int numberOfDimensions = 3; Front front = new ArrayFront(numberOfPoints, numberOfDimensions); Point point1 = new ArrayPoint(numberOfDimensions); point1.setDimensionValue(0, 10.0); point1.setDimensionValue(1, 12.0); point1.setDimensionValue(2, -1.0); Point point2 = new ArrayPoint(numberOfDimensions); point2.setDimensionValue(0, 8.0); point2.setDimensionValue(1, 80.0); point2.setDimensionValue(2, 0.32); Point point3 = new ArrayPoint(numberOfDimensions); point3.setDimensionValue(0, 5.0); point3.setDimensionValue(1, 50.0); point3.setDimensionValue(2, 3.0); front.setPoint(0, point1); front.setPoint(1, point2); front.setPoint(2, point3); double[] expectedResult = {10.0, 80.0, 3.0}; assertArrayEquals(expectedResult, FrontUtils.getMaximumValues(front), EPSILON); }
/** * Given a frontA with point [2,3] and a frontB with point [1,2], the value of the * setCoverage(frontA, frontB) == 0 and setCoverage(frontB, frontA) == 1 */ @Test public void shouldExecuteReturnTheRightValueIfTheFrontsContainOnePointWhichIsNotTheSame() { int numberOfPoints = 1; int numberOfDimensions = 2; Front frontA = new ArrayFront(numberOfPoints, numberOfDimensions); Front frontB = new ArrayFront(numberOfPoints, numberOfDimensions); Point point1 = new ArrayPoint(numberOfDimensions); point1.setDimensionValue(0, 2.0); point1.setDimensionValue(1, 3.0); Point point2 = new ArrayPoint(numberOfDimensions); point2.setDimensionValue(0, 1.0); point2.setDimensionValue(1, 2.0); frontA.setPoint(0, point1); frontB.setPoint(0, point2); Pair<Double, Double> result = setCoverage.evaluate( new ImmutablePair( FrontUtils.convertFrontToSolutionList(frontA), FrontUtils.convertFrontToSolutionList(frontB))); assertEquals(0.0, result.getLeft(), EPSILON); assertEquals(1.0, result.getRight(), EPSILON); }
/** * The front has the points [0.1, 0.9], [0.2, 0.8], [0.3, 0.7], [0.4, 0.6]. The inverted front is * [0.9, 0.1], [0.8, 0.2], [0.7, 0.3], [0.6, 0.4] */ @Test public void shouldGetInvertedFrontReturnTheCorrectFrontIfItComposedOfFourPoints() { int numberOfDimensions = 2; int numberOfPoints = 4; Point point1 = new ArrayPoint(numberOfDimensions); point1.setDimensionValue(0, 0.1); point1.setDimensionValue(1, 0.9); Point point2 = new ArrayPoint(numberOfDimensions); point2.setDimensionValue(0, 0.2); point2.setDimensionValue(1, 0.8); Point point3 = new ArrayPoint(numberOfDimensions); point3.setDimensionValue(0, 0.3); point3.setDimensionValue(1, 0.7); Point point4 = new ArrayPoint(numberOfDimensions); point4.setDimensionValue(0, 0.4); point4.setDimensionValue(1, 0.6); Front front = new ArrayFront(numberOfPoints, numberOfDimensions); front.setPoint(0, point1); front.setPoint(1, point2); front.setPoint(2, point3); front.setPoint(3, point4); Front newFront = FrontUtils.getInvertedFront(front); assertEquals(0.9, newFront.getPoint(0).getDimensionValue(0), EPSILON); assertEquals(0.1, newFront.getPoint(0).getDimensionValue(1), EPSILON); assertEquals(0.8, newFront.getPoint(1).getDimensionValue(0), EPSILON); assertEquals(0.2, newFront.getPoint(1).getDimensionValue(1), EPSILON); assertEquals(0.7, newFront.getPoint(2).getDimensionValue(0), EPSILON); assertEquals(0.3, newFront.getPoint(2).getDimensionValue(1), EPSILON); assertEquals(0.6, newFront.getPoint(3).getDimensionValue(0), EPSILON); assertEquals(0.4, newFront.getPoint(3).getDimensionValue(1), EPSILON); }
@Test public void shouldDistanceToClosestPointReturnMaxZeroIfThePointIsTheOnlyPointInTheFront() { int numberOfDimensions = 2; int numberOfPoints = 1; Point point = new ArrayPoint(numberOfDimensions); point.setDimensionValue(0, 2); point.setDimensionValue(1, 4); Front front = new ArrayFront(numberOfPoints, numberOfDimensions); front.setPoint(0, point); assertEquals(0.0, FrontUtils.distanceToClosestPoint(point, front), EPSILON); }
@Test public void shouldGetMaximumValuesWithAFrontWithOnePointReturnTheCorrectValue() { int numberOfPoints = 1; int numberOfDimensions = 2; Front front = new ArrayFront(numberOfPoints, numberOfDimensions); Point point = new ArrayPoint(numberOfDimensions); point.setDimensionValue(0, 10.0); point.setDimensionValue(1, 12.0); front.setPoint(0, point); double[] expectedResult = {10.0, 12.0}; assertArrayEquals(expectedResult, FrontUtils.getMaximumValues(front), EPSILON); }
/** Case C: the front has the point [3.0, -2.0]. The inverted front is [0.0, 1.0] */ @Test public void shouldGetInvertedFrontReturnTheCorrectFrontIfItComposedOfOnePointCaseC() { int numberOfDimensions = 2; int numberOfPoints = 1; Point point1 = new ArrayPoint(numberOfDimensions); point1.setDimensionValue(0, 3.0); point1.setDimensionValue(1, -2.0); Front front = new ArrayFront(numberOfPoints, numberOfDimensions); front.setPoint(0, point1); Front newFront = FrontUtils.getInvertedFront(front); assertEquals(0.0, newFront.getPoint(0).getDimensionValue(0), EPSILON); assertEquals(1.0, newFront.getPoint(0).getDimensionValue(1), EPSILON); }
@Test public void shouldDistanceToClosestPointReturnTheCorrectValueIfTheFrontHasHasOnePoint() { int numberOfDimensions = 2; int numberOfPoints = 1; Point point1 = new ArrayPoint(numberOfDimensions); point1.setDimensionValue(0, 2); point1.setDimensionValue(1, 4); Point point2 = new ArrayPoint(numberOfDimensions); point2.setDimensionValue(0, 6); point2.setDimensionValue(1, 7); Front front = new ArrayFront(numberOfPoints, numberOfDimensions); front.setPoint(0, point1); assertEquals(5.0, FrontUtils.distanceToClosestPoint(point2, front), EPSILON); }
/** Case A: the front has two points and one of them is the point passed as a parameter */ @Test public void shouldDistanceToNearestPointClosestTheCorrectValueIfTheFrontHasTwoPointsCaseA() { int numberOfDimensions = 2; int numberOfPoints = 2; Point point1 = new ArrayPoint(numberOfDimensions); point1.setDimensionValue(0, 2); point1.setDimensionValue(1, 4); Point point2 = new ArrayPoint(numberOfDimensions); point2.setDimensionValue(0, 6); point2.setDimensionValue(1, 7); Front front = new ArrayFront(numberOfPoints, numberOfDimensions); front.setPoint(0, point1); front.setPoint(1, point2); assertEquals(0.0, FrontUtils.distanceToClosestPoint(point1, front), EPSILON); }
@Test public void shouldExecuteReturnOneIfTheSecondFrontIsEmpty() { int numberOfDimensions = 2; Front frontA = new ArrayFront(1, numberOfDimensions); Front frontB = new ArrayFront(0, numberOfDimensions); Point point1 = new ArrayPoint(numberOfDimensions); point1.setDimensionValue(0, 10.0); point1.setDimensionValue(1, 12.0); frontA.setPoint(0, point1); Pair<Double, Double> result = setCoverage.evaluate( new ImmutablePair( FrontUtils.convertFrontToSolutionList(frontA), FrontUtils.convertFrontToSolutionList(frontB))); assertEquals(1.0, result.getLeft(), EPSILON); }
/** Case A: The front has one point */ @Test public void shouldConvertFrontToSolutionListReturnTheCorrectListCaseA() { int numberOfDimensions = 2; int numberOfPoints = 1; Front front = new ArrayFront(numberOfPoints, numberOfDimensions); Point point1 = new ArrayPoint(numberOfDimensions); point1.setDimensionValue(0, 0.1); point1.setDimensionValue(1, 0.9); front.setPoint(0, point1); List<PointSolution> list; list = FrontUtils.convertFrontToSolutionList(front); assertEquals(1, list.size()); assertEquals(0.1, list.get(0).getObjective(0), EPSILON); assertEquals(0.9, list.get(0).getObjective(1), EPSILON); }
/** Case A: The front has one point */ @Test public void shouldConvertFrontToArrayReturnTheCorrectArrayCaseA() { int numberOfDimensions = 2; int numberOfPoints = 1; Front front = new ArrayFront(numberOfPoints, numberOfDimensions); Point point1 = new ArrayPoint(numberOfDimensions); point1.setDimensionValue(0, 0.1); point1.setDimensionValue(1, 0.9); front.setPoint(0, point1); double[][] doubleFront; doubleFront = FrontUtils.convertFrontToArray(front); assertEquals(1, doubleFront.length); assertEquals(0.1, doubleFront[0][0], EPSILON); assertEquals(0.9, doubleFront[0][1], EPSILON); }
/** * Given a frontA with points [0.0,6.0], [2.0,3.0],[4.0,2.0] and a frontB with points [1.0,7.0], * [2.5,3.0], [5.0, 2.5], the value of setCoverage(frontA, frontB) == 1 and setCoverage(frontB, * frontA) == 0 */ @Test public void shouldExecuteReturnTheCorrectValueCaseB() { int numberOfPoints = 3; int numberOfDimensions = 2; Front frontA = new ArrayFront(numberOfPoints, numberOfDimensions); Front frontB = new ArrayFront(numberOfPoints, numberOfDimensions); Point point1 = new ArrayPoint(numberOfDimensions); point1.setDimensionValue(0, 0.0); point1.setDimensionValue(1, 6.0); Point point2 = new ArrayPoint(numberOfDimensions); point2.setDimensionValue(0, 2.0); point2.setDimensionValue(1, 3.0); Point point3 = new ArrayPoint(numberOfDimensions); point3.setDimensionValue(0, 4.0); point3.setDimensionValue(1, 2.0); frontA.setPoint(0, point1); frontA.setPoint(1, point2); frontA.setPoint(2, point3); Point point4 = new ArrayPoint(numberOfDimensions); point4.setDimensionValue(0, 1.0); point4.setDimensionValue(1, 7.0); Point point5 = new ArrayPoint(numberOfDimensions); point5.setDimensionValue(0, 2.5); point5.setDimensionValue(1, 3.0); Point point6 = new ArrayPoint(numberOfDimensions); point6.setDimensionValue(0, 5.0); point6.setDimensionValue(1, 2.5); frontB.setPoint(0, point4); frontB.setPoint(1, point5); frontB.setPoint(2, point6); Pair<Double, Double> result = setCoverage.evaluate( new ImmutablePair( FrontUtils.convertFrontToSolutionList(frontA), FrontUtils.convertFrontToSolutionList(frontB))); assertEquals(1.0, result.getLeft(), EPSILON); assertEquals(0.0, result.getRight(), EPSILON); }
/** Case A: The front has one three points */ @Test public void shouldConvertFrontToSolutionListReturnTheCorrectListCaseB() { int numberOfDimensions = 4; int numberOfPoints = 3; Front front = new ArrayFront(numberOfPoints, numberOfDimensions); Point point1 = new ArrayPoint(numberOfDimensions); point1.setDimensionValue(0, 0.1); point1.setDimensionValue(1, 0.9); point1.setDimensionValue(2, -2.23); point1.setDimensionValue(3, 0.0); Point point2 = new ArrayPoint(numberOfDimensions); point2.setDimensionValue(0, 0.2); point2.setDimensionValue(1, 0.8); point2.setDimensionValue(2, 25.08); point2.setDimensionValue(3, -232420.8); Point point3 = new ArrayPoint(numberOfDimensions); point3.setDimensionValue(0, 0.3); point3.setDimensionValue(1, 0.7); point3.setDimensionValue(2, 32342); point3.setDimensionValue(3, 0.4E+23); front.setPoint(0, point1); front.setPoint(1, point2); front.setPoint(2, point3); List<PointSolution> list; list = FrontUtils.convertFrontToSolutionList(front); assertEquals(3, list.size()); assertEquals(0.1, list.get(0).getObjective(0), EPSILON); assertEquals(0.8, list.get(1).getObjective(1), EPSILON); assertEquals(32342, list.get(2).getObjective(2), EPSILON); assertEquals(.4E+23, list.get(2).getObjective(3), EPSILON); }
/** Case A: The front has one three points */ @Test public void shouldConvertFrontToArrayReturnTheCorrectArrayCaseB() { int numberOfDimensions = 4; int numberOfPoints = 3; Front front = new ArrayFront(numberOfPoints, numberOfDimensions); Point point1 = new ArrayPoint(numberOfDimensions); point1.setDimensionValue(0, 0.1); point1.setDimensionValue(1, 0.9); point1.setDimensionValue(2, -2.23); point1.setDimensionValue(3, 0.0); Point point2 = new ArrayPoint(numberOfDimensions); point2.setDimensionValue(0, 0.2); point2.setDimensionValue(1, 0.8); point2.setDimensionValue(2, 25.08); point2.setDimensionValue(3, -232420.8); Point point3 = new ArrayPoint(numberOfDimensions); point3.setDimensionValue(0, 0.3); point3.setDimensionValue(1, 0.7); point3.setDimensionValue(2, 32342); point3.setDimensionValue(3, 0.4E+23); front.setPoint(0, point1); front.setPoint(1, point2); front.setPoint(2, point3); double[][] doubleFront; doubleFront = FrontUtils.convertFrontToArray(front); assertEquals(3, doubleFront.length); assertEquals(0.1, doubleFront[0][0], EPSILON); assertEquals(0.8, doubleFront[1][1], EPSILON); assertEquals(32342, doubleFront[2][2], EPSILON); assertEquals(.4E+23, doubleFront[2][3], EPSILON); }