role-model / roleR

R package implementing the RoLE model
https://role-model.github.io/roleR
GNU General Public License v3.0
1 stars 2 forks source link

env_filtering C fun test failure #104

Closed diazrenata closed 1 year ago

diazrenata commented 1 year ago

@jidec, can you take a look at this test failure? I am not familiar enough with the expected behavior of the C functions to know what to fix here!

From test_cpp_02_death_probs.R:


test_that("env filtering outputs a vector of the right length", {

    # create a test model and get data from a step and the params
    m <- quickModel()
    d <- m@modelSteps[[2]]
    p <- m@params

    # duplicate the data for comparison after the call_birth method
    d_start <- rlang::duplicate(d)

    # call_birth using the params from iter = 1 on the dead_index at 0, with the parent at index 3
    # indices start from 0 
    out <- cFun(type="vector",fun_name="get_filtering_death_probs",data=d,params=p,i=1)
    expect_true(m@params@niter == length(out))

    # try copying one liner into R
    # check edge cases 
    # make sure if you give it a negative number it doesnt work 
    # make sure vector is the right shape
    # wont be an opportunity to mess things up as we will check things in R

    # what is the expected behavior of this vector? can test using different params
})

Failure is that m@params@niter does not equal length(out).

Note that I changed the niter in quickParams to 200 (in order to get species diversity to emerge for some of the tests).

Thanks!

diazrenata commented 1 year ago

Another one, in test_cpp_08_speciation_local_meta.R:


test_that("update_speciation_local_meta sets the indv that was birthed or immigrated to the new species", {
    # create a test model and get data from a step and the params
    m <- quickModel()
    d <- m@modelSteps[[1]]
    p <- m@params

    # duplicate the data for comparison after the call_birth method
    d_start <- rlang::duplicate(d)

    #  update_speciation_local_meta, making the individual at dead_index 0 the new species 
    out <- cFun(type="data",fun_name="update_speciation_local_meta",data=d,params=p,i=1, 
                dead_index=0, dispersed_this_iter = TRUE,speciation_sp=0)

    # compare these two - the species of the new individual should equal the number of tips (as it is the newest tip)
    expect_true(d@localComm@indSpecies[1] == d@phylo@n)
})

Failure is that d@localComm@indSpecies[1] is not equal to d@phylo@n.

jidec commented 1 year ago

re. test_that("env filtering outputs a vector of the right length") - this was a typo, niter must have been an accident as the length of the env filtering probs should actually be compared to the number of individuals in the local community - fixed and test passes

re. test_that("update_speciation_local_meta") - this was also a typo - "out" should actually be named "d" - d the object that was check was not getting updated by the function - fixed and test passes

I also finished test_that("update_speciation_local_meta updates the species last origin step") which was unfinished and now passes.

I will close this issue but please let me know of any other weird test failures.