Skip to content

Commit

Permalink
extended getCaste() tests to check if matings are happening correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
LStrachan committed Dec 21, 2023
1 parent e354bb2 commit 47cca09
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions tests/testthat/test-L0_auxiliary_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -960,27 +960,54 @@ test_that("getCaste", {
SP <- SimParamBee$new(founderGenomes)
SP$nThreads = 1L
basePop <- createVirginQueens(founderGenomes, simParamBee = SP)
expect_vector(getCaste(basePop, simParamBee = SP), "virginQueens")

#Create drones
drones <- createDrones(x = basePop[1], nInd = 1000, simParamBee = SP)
droneGroups <- pullDroneGroupsFromDCA(drones, n = 10, nDrones = nFathersPoisson, simParamBee = SP)
expect_vector(getCaste(drones, simParamBee = SP), "drones")

# Create a Colony and a MultiColony class
colony <- createColony(x = basePop[2], simParamBee = SP)
colony <- cross(colony, drones = droneGroups[[1]], simParamBee = SP)

# test that all drones in colony are now fathers. Colony should only contain queen and fathers
expect_vector(getCaste(getQueen(colony, simParamBee = SP), simParamBee = SP), "queen")
expect_vector(getCaste(getFathers(colony, simParamBee = SP), simParamBee = SP), "fathers")
expect_error(getCaste(getWorkers(colony, simParamBee = SP), simParamBee = SP))
expect_error(getCaste(getDrones(colony, simParamBee = SP), simParamBee = SP))
expect_error(getCaste(getVirginQueens(colony, simParamBee = SP), simParamBee = SP))

# all caste members are now present
colony <- buildUp(x = colony, nWorkers = 20, nDrones = 5, simParamBee = SP)
colony <- addVirginQueens(colony, nInd = 5, simParamBee = SP)
expect_vector(getCaste(getQueen(colony, simParamBee = SP), simParamBee = SP), "queen")
expect_vector(getCaste(getFathers(colony, simParamBee = SP), simParamBee = SP), "fathers")
expect_vector(getCaste(getWorkers(colony, simParamBee = SP), simParamBee = SP), "workers")
expect_vector(getCaste(getDrones(colony, simParamBee = SP), simParamBee = SP), "drones")
expect_vector(getCaste(getVirginQueens(colony, simParamBee = SP), simParamBee = SP), "virginQueen")

# Check colony collapses
expect_length(getCaste(colony, collapse = FALSE, simParamBee = SP), 5)
expect_vector(getCaste(colony, collapse = TRUE, simParamBee = SP), c("queen", "fathers", "workers", "drones", "virginQueens"))

# Create virgin apiary containing 2 colonies
apiary <- createMultiColony(basePop[3:4], n = 2, simParamBee = SP)
expect_length(getCaste(apiary, simParamBee = SP), 2)
expect_vector(getCaste(getVirginQueens(apiary[[1]], simParamBee = SP), simParamBee = SP), "virginQueen")

# Mate apiaries, now only contains queens and fathers
apiary <- cross(apiary, drones = droneGroups[c(2, 3)], simParamBee = SP)
expect_vector(getCaste(getQueen(apiary[[1]], simParamBee = SP), simParamBee = SP), "queen")
expect_vector(getCaste(getFathers(apiary[[1]], simParamBee = SP), simParamBee = SP), "fathers")

# all caste members are now present in apiary
apiary <- buildUp(x = apiary, nWorkers = 10, nDrones = 2, simParamBee = SP)
apiary <- addVirginQueens(apiary, nInd = 4, simParamBee = SP)
expect_vector(getCaste(getWorkers(apiary[[1]], simParamBee = SP), simParamBee = SP), "workers")
expect_vector(getCaste(getDrones(apiary[[1]], simParamBee = SP), simParamBee = SP), "drones")
expect_vector(getCaste(getVirginQueens(apiary[[1]], simParamBee = SP), simParamBee = SP), "virginQueen")

expect_vector(getCaste(getQueen(colony, simParamBee = SP), simParamBee = SP), "queen")
expect_vector(getCaste(getFathers(colony, simParamBee = SP), simParamBee = SP), "fathers")
expect_vector(getCaste(getWorkers(colony, simParamBee = SP), simParamBee = SP), "workers")
expect_vector(getCaste(getDrones(colony, simParamBee = SP), simParamBee = SP), "drones")
expect_vector(getCaste(getVirginQueens(colony, simParamBee = SP), simParamBee = SP), "virginQueen")

bees <- c(
getQueen(colony, simParamBee = SP),
Expand All @@ -991,13 +1018,7 @@ test_that("getCaste", {
)
expect_vector(getCaste(bees, simParamBee = SP), c("queen", "fathers", "workers", "drones", "virginQueens"))

expect_length(getCaste(colony, collapse = FALSE, simParamBee = SP), 5) #This is a list

# Collapse information into a single vector
expect_vector(getCaste(colony, collapse = TRUE, simParamBee = SP), c("queen", "fathers", "workers", "drones", "virginQueens"))

#Apiary contains 2 colonies
expect_length(getCaste(apiary, simParamBee = SP), 2)
})


Expand Down

0 comments on commit 47cca09

Please sign in to comment.