diff --git a/test/test_population.jl b/test/test_population.jl index ba3268eb..e36101f8 100644 --- a/test/test_population.jl +++ b/test/test_population.jl @@ -11,6 +11,29 @@ facts("Population") do @fact isnafitness(fitness(p1, 1), fs) --> true @fact isnafitness(fitness(p1, 4), fs) --> true + context("accessing individuals") do + @fact typeof(p1[1]) --> Vector{Float64} + @fact length(p1[1]) --> numdims(p1) + @fact isa(BlackBoxOptim.viewer(p1, 1), AbstractVector{Float64}) --> true + @fact length(BlackBoxOptim.viewer(p1, 1)) --> numdims(p1) + @fact typeof(p1[popsize(p1)]) --> Vector{Float64} # last solution vector + @fact_throws BoundsError p1[0] + @fact_throws BoundsError p1[popsize(p1)+1] + @fact_throws BoundsError BlackBoxOptim.viewer(p1, 0) + @fact_throws BoundsError BlackBoxOptim.viewer(p1, popsize(p1)+1) + rand_solution_idx = rand(2:(popsize(p1)-1)) + @fact isa(p1[rand_solution_idx], Array{Float64, 1}) --> true # random solution vector + end + + context("accessing individuals fitness") do + # and to access their fitness values: + @fact typeof(fitness(p1, 1)) --> Float64 + @fact typeof(fitness(p1, popsize(p1))) --> Float64 + rand_solution_idx = rand(2:(popsize(p1)-1)) + @fact_throws BoundsError fitness(p1, 0) + @fact_throws BoundsError fitness(p1, popsize(p1)+1) + end + context("candidates pool") do @fact BlackBoxOptim.candi_pool_size(p1) --> 0 candi1 = BlackBoxOptim.acquire_candi(p1, 1)