diff --git a/unit_tests/testIndividual.cpp b/unit_tests/testIndividual.cpp index 5c526ea..4ced6fd 100644 --- a/unit_tests/testIndividual.cpp +++ b/unit_tests/testIndividual.cpp @@ -571,42 +571,83 @@ void testGenetics() { // Genetic fitness mutations are constrained between -1 or 1 { - // Most likely (~96%) to sample a mutation > 1 - const float gammaMutShapeParam = 5.0; - const float gammaMutScaleParam = 1.0; + { + // Most likely (~96%) to sample a mutation > 1 + const float gammaMutShapeParam = 5.0; + const float gammaMutScaleParam = 1.0; - const int genomeSz = 5; - const bool isDiploid{ false }; + const int genomeSz = 5; + const bool isDiploid{ false }; - // Create species trait - const map mutationParams{ - // all alleles initialised at a single value - pair{GenParamType::SHAPE, gammaMutShapeParam}, - pair{GenParamType::SCALE, gammaMutScaleParam} - }; - const map placeholderParams = mutationParams; + // Create species trait + const map mutationParams{ + // all alleles initialised at a single value + pair{GenParamType::SHAPE, gammaMutShapeParam}, + pair{GenParamType::SCALE, gammaMutScaleParam} + }; + const map placeholderParams = mutationParams; + + SpeciesTrait* spTr = new SpeciesTrait( + TraitType::GENETIC_LOAD1, + sex_t::NA, + createTestGenePositions(genomeSz), + ExpressionType::MULTIPLICATIVE, + DistributionType::NONE, placeholderParams, // not used for genetic load + DistributionType::GAMMA, placeholderParams, // doesn't matter for this test + true, + 1.0, // every site mutates + DistributionType::GAMMA, mutationParams, + isDiploid ? 2 : 1 + ); + + // Create individual trait object + GeneticFitnessTrait traitInd(spTr); // initialisation constructor + traitInd.mutate(); + for (int i = 0; i < genomeSz; i++) { + float valAllele = traitInd.getAlleleValueAtLocus(0, i); + assert(valAllele <= 1.0); + } + } - SpeciesTrait* spTr = new SpeciesTrait( - TraitType::GENETIC_LOAD1, - sex_t::NA, - createTestGenePositions(genomeSz), - ExpressionType::MULTIPLICATIVE, - DistributionType::NONE, placeholderParams, // not used for genetic load - DistributionType::GAMMA, placeholderParams, // doesn't matter for this test - true, - 1.0, // every site mutates - DistributionType::GAMMA, mutationParams, - isDiploid ? 2 : 1 - ); + { + // 1/2 chance to sample a mutation < -1 + const float normalMutMeanParam = 0; + const float normalMutSdParam = 1.0; - // Create individual trait object - GeneticFitnessTrait traitInd(spTr); // initialisation constructor - traitInd.mutate(); - for (int i = 0; i < genomeSz; i++) { - float valAllele = traitInd.getAlleleValueAtLocus(0, i); - assert(valAllele <= 1.0); + const int genomeSz = 10; + const bool isDiploid{ false }; + + // Create species trait + const map mutationParams{ + // all alleles initialised at a single value + pair{GenParamType::MEAN, normalMutMeanParam}, + pair{GenParamType::SD, normalMutSdParam} + }; + const map placeholderParams = mutationParams; + + SpeciesTrait* spTr = new SpeciesTrait( + TraitType::GENETIC_LOAD1, + sex_t::NA, + createTestGenePositions(genomeSz), + ExpressionType::MULTIPLICATIVE, + DistributionType::NONE, placeholderParams, // not used for genetic load + DistributionType::NORMAL, placeholderParams, // doesn't matter for this test + true, + 1.0, // every site mutates + DistributionType::NORMAL, mutationParams, + isDiploid ? 2 : 1 + ); + + // Create individual trait object + GeneticFitnessTrait traitInd(spTr); // initialisation constructor + traitInd.mutate(); + for (int i = 0; i < genomeSz; i++) { + float valAllele = traitInd.getAlleleValueAtLocus(0, i); + assert(valAllele > -1.0); + } } } + } bool haveSameEmigD0Allele(const Individual& indA, const Individual& indB, const int& position, short whichHaplo = 0) {