Skip to content

Commit 9d9508a

Browse files
committed
progress test #30
1 parent 743cb1f commit 9d9508a

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

DispersalTrait.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,15 @@ float DispersalTrait::getAlleleValueAtLocus(short whichChromosome, int position)
456456
}
457457

458458
#if RSDEBUG // Testing only
459+
460+
// Get allele ID at locus
461+
float DispersalTrait::getAlleleIDAtLocus(short whichChromosome, int position) const {
462+
auto it = genes.find(position);
463+
if (it == genes.end())
464+
throw runtime_error("The Dispersal locus queried for its allele value does not exist.");
465+
return it->second[whichChromosome].get()->getAlleleValue();
466+
}
467+
459468
// Create a default set of alleles for testing
460469
map<int, vector<shared_ptr<Allele>>> createTestEmigTrGenotype(
461470
const int genomeSz,

DispersalTrait.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class DispersalTrait : public QuantitativeTrait {
5757
int startChr) {
5858
(this->*_inherit_func_ptr)(fromMother, parentGenes, recomPositions, startChr);
5959
}
60+
float getAlleleIDAtLocus(short whichChromosome, int position) const;
6061
#endif
6162

6263
private:

unit_tests/testIndividual.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,11 @@ void testGenetics() {
562562
}
563563
}
564564

565+
bool haveSameEmigD0Allele(const Individual& indA, const Individual& indB, const int& position, short whichHaplo = 0) {
566+
return indA.getTrait(E_D0)->getAlleleValueAtLocus(whichHaplo, position)
567+
== indB.getTrait(E_D0)->getAlleleValueAtLocus(whichHaplo, position);
568+
}
569+
565570
void testIndividual() {
566571

567572
// Kernel-based transfer
@@ -580,7 +585,6 @@ void testIndividual() {
580585
// Count times c1 = A & B; c2 = B & C have same alleles
581586
// Assert c1 > c2
582587
{
583-
584588
Patch* pPatch = new Patch(0, 0);
585589
Cell* pCell = new Cell(0, 0, (intptr)pPatch, 0);
586590

@@ -605,7 +609,23 @@ void testIndividual() {
605609
indFather.setUpGenes(pSpecies, 1.0);
606610
Individual indChild = Individual(pCell, pPatch, 0, 0, 0, 0.0, false, 0);
607611

608-
indChild.inheritTraits(pSpecies, &indMother, &indFather, 1.0); cout << endl;
612+
indChild.inheritTraits(pSpecies, &indMother, &indFather, 1.0);
613+
614+
int countRecombineTogetherAB = 0;
615+
int countRecombineTogetherAC = 0;
616+
617+
// for i in ...
618+
{
619+
bool hasInheritedA0 = haveSameEmigD0Allele(indChild, indMother, 0);
620+
bool hasInheritedB0 = haveSameEmigD0Allele(indChild, indMother, 1);
621+
bool hasInheritedC0 = haveSameEmigD0Allele(indChild, indMother, 2);
622+
623+
countRecombineTogetherAB += (hasInheritedA0 && hasInheritedB0)
624+
|| (!hasInheritedA0 && !hasInheritedB0);
625+
countRecombineTogetherAC += (hasInheritedA0 && hasInheritedC0)
626+
|| (!hasInheritedA0 && !hasInheritedC0);
627+
}
628+
assert(countRecombineTogetherAB > countRecombineTogetherAC);
609629
}
610630
}
611631

0 commit comments

Comments
 (0)