From 92cc0d87a4406e92bfadea8c22cb16cddd4f43bd Mon Sep 17 00:00:00 2001 From: Robert Feldt Date: Tue, 23 Aug 2016 18:06:50 +0200 Subject: [PATCH] added tests to show how to access the population and fitness values when using a population opt --- test/test_toplevel_bboptimize.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/test_toplevel_bboptimize.jl b/test/test_toplevel_bboptimize.jl index 0fc4994d..e0b5cea1 100644 --- a/test/test_toplevel_bboptimize.jl +++ b/test/test_toplevel_bboptimize.jl @@ -51,6 +51,21 @@ facts("Top-level interface") do @fact isa(xpop, BlackBoxOptim.Population) --> true @fact popsize(xpop) --> greater_than(0) @fact numdims(xpop) --> 2 + + # Access a few individual solution vectors in the population... + @fact isa(xpop[1], Array{Float64, 1}) --> true # first solution vector + @fact isa(xpop[popsize(xpop)], Array{Float64, 1}) --> true # first solution vector + rand_solution_idx = rand(1:popsize(xpop)) + @fact isa(xpop[rand_solution_idx], Array{Float64, 1}) --> true # random solution vector + + # and to access their fitness values: + @fact isa(fitness(xpop, 1), Float64) --> true + @fact isa(fitness(xpop, popsize(xpop)), Float64) --> true + @fact isa(fitness(xpop, rand_solution_idx), Float64) --> true + + # Ensure the lowest fitness value is the one returned by best_fitness + min_fitness_value = minimum(map(i -> fitness(xpop, i), 1:popsize(xpop))) + @fact (min_fitness_value == best_fitness(res)) --> true end if BlackBoxOptim.enable_parallel_methods