From a9f2d02df7bce1d0fa0e1b446876063fdd5069a1 Mon Sep 17 00:00:00 2001 From: ajnebro Date: Wed, 8 May 2024 11:53:08 +0200 Subject: [PATCH] Refactor tests --- test/operator/crossoverTest.jl | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/operator/crossoverTest.jl b/test/operator/crossoverTest.jl index 21700ea..aa8a532 100644 --- a/test/operator/crossoverTest.jl +++ b/test/operator/crossoverTest.jl @@ -57,11 +57,12 @@ function sbxCrossoverWithWithProbabilityOneChangesAllTheVariableValuesIntheRetur return !isequal(parent1, children[1]) && !isequal(parent2, children[2]) end +sbxCrossover = SBXCrossover(0.054, 20.0, []) @testset "SBX crossover tests" begin - @test SBXCrossover(0.054, 20.0, []).probability == 0.054 - @test SBXCrossover(0.054, 20.0, []).distributionIndex == 20.0 - @test numberOfDescendants(SBXCrossover(0.054, 20.0, [])) == 2 - @test numberOfRequiredParents(SBXCrossover(0.054, 20.0, [])) == 2 + @test sbxCrossover.probability == 0.054 + @test sbxCrossover.distributionIndex == 20.0 + @test numberOfDescendants(sbxCrossover) == 2 + @test numberOfRequiredParents(sbxCrossover) == 2 @test sbxCrossoverWithProbabilityZeroReturnTwoSolutionsEqualToTheParentSolutions() @test sbxCrossoverWithWithProbabilityOneChangesAllTheVariableValuesIntheReturnedSolutions() @@ -94,11 +95,12 @@ function blxAlphaCrossoverWithWithProbabilityOneChangesAllTheVariableValuesInthe return !isequal(parent1, children[1]) && !isequal(parent2, children[2]) end +blxAlphaCrossover = BLXAlphaCrossover(0.12, 0.5, []) @testset "BLX-alpha crossover tests" begin - @test BLXAlphaCrossover(0.12, 0.5, []).probability == 0.12 - @test BLXAlphaCrossover(0.12, 0.5, []).alpha == 0.5 - @test numberOfDescendants(BLXAlphaCrossover(0.12, 0.5, [])) == 2 - @test numberOfRequiredParents(BLXAlphaCrossover(0.12, 0.5, [])) == 2 + @test blxAlphaCrossover.probability == 0.12 + @test blxAlphaCrossover.alpha == 0.5 + @test numberOfDescendants(blxAlphaCrossover) == 2 + @test numberOfRequiredParents(blxAlphaCrossover) == 2 @test blxAlphaCrossoverWithProbabilityZeroReturnTwoSolutionsEqualToTheParentSolutions() @test blxAlphaCrossoverWithWithProbabilityOneChangesAllTheVariableValuesIntheReturnedSolutions()