Skip to content

Commit

Permalink
Test for Genetic Algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikola-Mircic committed Jan 4, 2024
1 parent d88fb5b commit f595006
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
29 changes: 29 additions & 0 deletions test/genetic_algorithm.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using GeneticAlgorithm

@testset "GeneticAlgorithm" begin
#=
| Find four numbers that add up to 143.
|
| x1 + x2 + x3 + x4 = 143
| x1=?, x2=?, x3=?, x4=?
=#

populationSize = 100
genesLength = 4
minGene = 0
maxGene = 143

elitePercent = 0.15
mutationPercent = 0.2
numOfIterations = 100

population = generatePopulation(populationSize, genesLength, minGene, maxGene)

num_gen, best = geneticAlgorithm(population,
elitePercent,
mutationPercent,
makeCrossoverFunc([1;3]),
numOfIterations)

@test fitFunction(best) < 0.1 # Test if the absolute error is smaller than 0.1
end
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Test

@testset "Tests" begin
a = 5
@test a == 5
include("genetic_algorithm.jl")
end

0 comments on commit f595006

Please sign in to comment.