Skip to content

Commit

Permalink
add tests for accessing population individuals
Browse files Browse the repository at this point in the history
  • Loading branch information
alyst committed Sep 20, 2016
1 parent f680dc4 commit 6051e08
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/test_population.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6051e08

Please sign in to comment.