private static EvolutionResult<DoubleGene, Double> result( final int min, final int max, final Optimize opt ) { return EvolutionResult.of( opt, population(min, max), 1L, EvolutionDurations.ZERO, 1, 1, 1 ); }
@Test public void limit() { final Predicate<EvolutionResult<?, Double>> l = Limits.byFitnessConvergence(5, 10, 0.015); int g = 0; while (l.test(result(10 + g, 100 + g, Optimize.MAXIMUM))) { ++g; } Assert.assertEquals(g, 69); }
@Test public void bufferDoubleMoments() { final long seed = 0xdeadbeef; final int capacity = 10; final Random random = new Random(seed); final Buffer buffer = new Buffer(capacity); DoubleMomentStatistics statistics = new DoubleMomentStatistics(); for (int i = 0; i < buffer.capacity(); ++i) { final double value = random.nextDouble()*1000; buffer.accept(value); statistics.accept(value); final DoubleMoments moments = DoubleMoments.of(statistics); Assert.assertEquals(moments, buffer.doubleMoments(1000)); } final Random sr = new Random(seed); for (int i = 0; i < buffer.capacity(); ++i) { statistics = statistics(new Random(seed), i + 1, buffer.capacity() - 1); final double value = random.nextDouble()*1000; buffer.accept(value); statistics.accept(value); final DoubleMoments moments = DoubleMoments.of(statistics); Assert.assertEquals(moments, buffer.doubleMoments(1000)); } }