" Warning: Replacing docs for ... " repeated

Hi
After introducing a test for a function, this one

"""
    mutation_operator(offspring, mutation_percentage)

Apply mutation to `offspring` based on `mutation_percentage`.
"""
function mutation_operator(offspring, mutation_percentage)
    mutated_offspring = Array{Float64,1}()
    genes_to_mutate = floor(Int, mutation_percentage * length(offspring) / 100)
    indexes_to_mutate = rand(1:length(offspring), genes_to_mutate)

    for (index, gene) in enumerate(offspring)
        if index in indexes_to_mutate
            new_gene = rand()
            push!(mutated_offspring, new_gene)
        else
            push!(mutated_offspring, gene)
        end
    end

    return mutated_offspring
end

And here’s the test

include("../../src/methods/evolution.jl")

using Test

@testset "create_new_individual" begin
    # Use higher mutation rate (50%) to ensure mutation happens with small chromosome size
    test_mutation_rate = 50

    parents = (
        Individual([1.0, 2.0], 0.5, ALPHA()),
        Individual([3.0, 4.0], 0.8, ALPHA())
    )

    offspring1, offspring2 = create_new_individual(parents, test_mutation_rate)

    # Test that function returns two offspring arrays
    @test typeof(offspring1) == Array{Float64,1}
    @test typeof(offspring2) == Array{Float64,1}
    @test length(offspring1) == 2
    @test length(offspring2) == 2

    # Test that offspring are different from each other
    @test offspring1 != offspring2

    # Test that offspring are different from original parents (crossover + mutation should change them)
    @test offspring1 != parents[1].chromosome || offspring1 != parents[2].chromosome
    @test offspring2 != parents[1].chromosome || offspring2 != parents[2].chromosome
end

I’m getting repeated errors of the kind:

┌ Warning: Replacing docs for `Main.BraveNewAlgorithm.mutation_operator :: Tuple{Any, Any}` in module `Main.BraveNewAlgorithm`
└ @ Base.Docs docs/Docs.jl:243
┌ Warning: Replacing docs for `Main.BraveNewAlgorithm.mutation_operator :: Tuple{Any, Any}` in module `Main.BraveNewAlgorithm`
└ @ Base.Docs docs/Docs.jl:243
┌ Warning: Replacing docs for `Main.BraveNewAlgorithm.mutation_operator :: Tuple{Any, Any}` in module `Main.BraveNewAlgorithm`
└ @ Base.Docs docs/Docs.jl:243
┌ Warning: Replacing docs for `Main.BraveNewAlgorithm.mutation_operator :: Tuple{Any, Any}` in module `Main.BraveNewAlgorithm`
└ @ Base.Docs docs/Docs.jl:243
┌ Warning: Replacing docs for `Main.BraveNewAlgorithm.mutation_operator :: Tuple{Any, Any}` in module `Main.BraveNewAlgorithm`
└ @ Base.Docs docs/Docs.jl:243

I have no idea why this is. There’s no other definition of the function, here’s the git grep:

src/methods/evolution.jl:    mutated_chromosome = mutation_operator(chromosome, config_parameters.mutation_rate[caste.name])
src/methods/evolution.jl:    return mutation_operator(chromosome, config_parameters.mutation_rate[caste.name])
src/methods/evolution.jl:    offspring1_mutated = mutation_operator(offspring1, mutation_rate)
src/methods/evolution.jl:    offspring2_mutated = mutation_operator(offspring2, mutation_rate)
src/methods/local_search.jl:        mutated_offspring = mutation_operator(final_chromosome, population_model.config_parameters.mutation_rate[caste.name])
src/operators/mutation.jl:    mutation_operator(offspring, mutation_percentage)
src/operators/mutation.jl:function mutation_operator(offspring, mutation_percentage)
test/operators/mutation_test.jl:mutated_chromosomes = [mutation_operator(embryo.chromosome, config_parameters_entity.mutation_rate["ALPHA"]) for embryo in embryos]
test/operators/mutation_test.jl:@testset "Test mutation_operator when called then different chromosome returned" begin
test/operators/mutation_test.jl:# @testset "Test mutation_operator when called then different chromosomes returned" begin
test/operators/mutation_test.jl:#     mutated_offspring = mutation_operator(offspring, config_parameters_entity.mutation_rate["ALPHA"])

There’s a single definition of the function. Although there’s no error, I feel I’m missing something important here so I’d like to know. Please notice that the “redefinition” warning does not correspond to the actual signature of the function that’s defined.

Hi,

maybe I am missing it, but I cannot see where in your test your function is actually being called, so it is a bit hard to tell.

Maybe the reason for the redefinition is the include statement at the top of the test? Is there a reason you are directly includeing your source file instead of simply using the module being tested?

It’s been called from within create_new_individual.
The reason is that it does not work without that include. I know, I have no idea. Suggestions are welcome.