Skip to content

Commit

Permalink
Add unit tests for PermutationProblem
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnebro committed Nov 17, 2024
1 parent a24876e commit 59d9b04
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/MetaJul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ include("util/utils.jl")
export Observable, EvaluationObserver, FitnessObserver, getObservable, FrontPlotObserver, register!
include("util/observer.jl")

export BinaryProblem, ContinuousProblem, constrainedProblem
export BinaryProblem, ContinuousProblem, constrainedProblem, PermutationProblem
export addObjective, addVariable, addConstraint, createSolution, evaluate, setName, name
export bounds
export numberOfVariables, numberOfObjectives, numberOfConstraints
Expand Down
2 changes: 1 addition & 1 deletion src/problem/continuousProblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function addVariable(problem::ContinuousProblem{T}, bounds::Bounds{T}) where {T<
return Nothing
end

function setName(problem::Problem{T}, name::String) where {T}
function setName(problem::ContinuousProblem{T}, name::String) where {T}
problem.name = name

return Nothing
Expand Down
18 changes: 9 additions & 9 deletions src/problem/permutationProblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@ mutable struct PermutationProblem <: AbstractPermutationProblem
name::String
end

function PermutationProblem{T}(problemName::String) where {T<:Number}
return PermutationProblem{T}([], [], [], problemName)
function PermutationProblem(problemName::String)
return PermutationProblem([], [], [], problemName)
end

function numberOfVariables(problem::PermutationProblem{T}) where {T}
function numberOfVariables(problem::PermutationProblem)
return problem.permutationLength
end

function numberOfObjectives(problem::PermutationProblem{T}) where {T}
function numberOfObjectives(problem::PermutationProblem)
return length(problem.objectives)
end

function numberOfConstraints(problem::PermutationProblem{T}) where {T}
function numberOfConstraints(problem::PermutationProblem)
return length(problem.constraints)
end

function name(problem::PermutationProblem{T}) where {T}
function name(problem::PermutationProblem)
return problem.name
end

function addObjective(problem::PermutationProblem{T}, objective::Function) where {T<:Number}
function addObjective(problem::PermutationProblem, objective::Function)
push!(problem.objectives, objective)

return Nothing
end

function addConstraint(problem::PermutationProblem{T}, constraint::Function) where {T<:Number}
function addConstraint(problem::PermutationProblem, constraint::Function)
push!(problem.constraints, constraint)

return Nothing
end

function setName(problem::Problem{T}, name::String) where {T}
function setName(problem::PermutationProblem, name::String)
problem.name = name

return Nothing
Expand Down
14 changes: 14 additions & 0 deletions test/problem/permutationProblemTest.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Test cases for permutation problem
permutationLength = 10
permutationTestProblem = PermutationProblem(permutationLength,[],[],"")
addObjective(permutationTestProblem, x -> x[1] + x[2])
addObjective(permutationTestProblem, x -> x[2] * x[2])
addConstraint(permutationTestProblem, x -> x[1] < 2)
setName(permutationTestProblem, "TestProblem")

@testset "PermutationProblem tests" begin
@test numberOfVariables(permutationTestProblem) == permutationLength
@test numberOfObjectives(permutationTestProblem) == 2
@test numberOfConstraints(permutationTestProblem) == 1
@test name(permutationTestProblem) == "TestProblem"
end
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ for testProgram in utilTests
end

problemTests = [
"problem/continuousProblemTest.jl"
"problem/continuousProblemTest.jl",
"problem/binaryProblemTest.jl",
"problem/permutationProblemTest.jl"
]

for testProgram in problemTests
Expand Down

0 comments on commit 59d9b04

Please sign in to comment.