context("selection") test_that("selectInd_and_getResponse",{ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitA(10) SP$setVarE(h2=0.5) pop = newPop(founderPop, simParam=SP) pop2 = selectInd(pop, 5, simParam=SP) expect_equal(pop2@id, pop[order(pop@pheno, decreasing=TRUE)[1:5]]@id) pop2b = selectInd(pop, 5, trait="Trait1", simParam=SP) expect_equal(pop2@id, pop2b@id) squaredDeviation = function(x, optima=0) (x - optima)^2 pop3 = selectInd(pop, 5, trait=squaredDeviation, selectTop=TRUE, simParam=SP) expect_equal(pop3@id, pop[order(squaredDeviation(pop@pheno), decreasing=TRUE)[1:5]]@id) pop4 = selectInd(pop, 5, trait=squaredDeviation, selectTop=FALSE, simParam=SP) expect_equal(pop4@id, pop[order(squaredDeviation(pop@pheno), decreasing=FALSE)[1:5]]@id) pop@misc = list(smth=rnorm(10), smth2=rnorm(10)) useFunc = function(pop, trait=NULL) pop@misc$smth + pop@misc$smth2 pop5 = selectInd(pop, 5, use=useFunc, simParam=SP) expect_equal(pop5@id, pop[order(useFunc(pop), decreasing=TRUE)[1:5]]@id) useFunc2 = function(pop, trait=NULL) cbind(pop@misc$smth, pop@misc$smth2) trtFunc = function(x) rowSums(x) pop6 = selectInd(pop, 5, trait=trtFunc, use=useFunc2, simParam=SP) expect_equal(pop5@id, pop6@id) })