Skip to content

Commit

Permalink
added tests to show how to access the population and fitness values w…
Browse files Browse the repository at this point in the history
…hen using a population opt
  • Loading branch information
robertfeldt committed Aug 23, 2016
1 parent a4b1b36 commit 92cc0d8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/test_toplevel_bboptimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 92cc0d8

Please sign in to comment.