Ejemplo n.º 1
0
  @Test
  public void results() {
    final Algorithm algorithm = mockery.mock(Algorithm.class);
    final OptimisationSolution mockSolution1 =
        new OptimisationSolution(Vector.of(1.0), new MinimisationFitness(1.0));
    final FunctionOptimisationProblem mockProblem = mockery.mock(FunctionOptimisationProblem.class);

    mockery.checking(
        new Expectations() {
          {
            exactly(3).of(algorithm).getBestSolution();
            will(returnValue(mockSolution1));
            exactly(3).of(algorithm).getOptimisationProblem();
            will(returnValue(mockProblem));
            exactly(3).of(mockProblem).getError(Vector.of(1.0));
            will(onConsecutiveCalls(returnValue(5.0), returnValue(4.0), returnValue(0.0)));
            exactly(3).of(algorithm).getIterations();
            will(onConsecutiveCalls(returnValue(1), returnValue(2), returnValue(3)));
          }
        });

    Measurement m = new CollectiveMeanError();
    Assert.assertEquals(5.0, ((Real) m.getValue(algorithm)).doubleValue(), 0.00001);
    Assert.assertEquals(4.5, ((Real) m.getValue(algorithm)).doubleValue(), 0.00001);
    Assert.assertEquals(3.0, ((Real) m.getValue(algorithm)).doubleValue(), 0.00001);
  }
Ejemplo n.º 2
0
  @Test
  public void testMean() {

    Algorithm algorithm = mock(Algorithm.class);

    Measurement innerMeasurement = mock(Measurement.class);
    when(innerMeasurement.getValue(any(Algorithm.class)))
        .thenReturn(Vector.of(1.0, 2.0, 3.0, 4.0, 5.0));

    MeanOfVectorMeasurement measurement = new MeanOfVectorMeasurement();
    measurement.setMeasurement(innerMeasurement);
    assertEquals(3.0, ((Real) measurement.getValue(algorithm)).doubleValue(), Maths.EPSILON);
  }