joshwlambert / DAISIEmainland

Simulate phylogenetic data on islands with a evolving mainland pool

Home Page:https://joshwlambert.github.io/DAISIEmainland/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`mainland_sample_type` can be nonsense

richelbilderbeek opened this issue · comments

Dear DAISIEmainland maintainer,

Thanks for DAISIEmainland and its many tests to ensure its correctness.

In test-sim_island.R, I was happy to find the many tests to confirm that a user receives a nice error message, shown here for reference:

test_that("sim_island fails with incorrect input", {
  expect_error(sim_island(
    total_time = "nonsense",
    island_pars = c(1, 1, 10, 1, 1),
    mainland_clade = create_test_mainland_clade(mainland_scenario = 1),
    mainland_sample_prob = 1)
  )

  expect_error(sim_island(
    total_time = 1,
    island_pars = "nonsense",
    mainland_clade = create_test_mainland_clade(mainland_scenario = 1),
    mainland_sample_prob = 1)
  )

  expect_error(sim_island(
    total_time = 1,
    island_pars = c("nonsense", 1, 10, 1, 1),
    mainland_clade = create_test_mainland_clade(mainland_scenario = 1),
    mainland_sample_prob = 1)
  )

  expect_error(sim_island(
    total_time = 1,
    island_pars = c(1, "nonsense", 10, 1, 1),
    mainland_clade = create_test_mainland_clade(mainland_scenario = 1),
    mainland_sample_prob = 1)
  )

  expect_error(sim_island(
    total_time = 1,
    island_pars = c(1, 1, "nonsense", 1, 1),
    mainland_clade = create_test_mainland_clade(mainland_scenario = 1),
    mainland_sample_prob = 1)
  )

  expect_error(sim_island(
    total_time = 1,
    island_pars = c(1, 1, 10, "nonsense", 1),
    mainland_clade = create_test_mainland_clade(mainland_scenario = 1),
    mainland_sample_prob = 1)
  )

  expect_error(sim_island(
    total_time = 1,
    island_pars = c(1, 1, 10, 1, "nonsense"),
    mainland_clade = create_test_mainland_clade(mainland_scenario = 1),
    mainland_sample_prob = 1)
  )

  expect_error(sim_island(
    total_time = 1,
    island_pars = c(1, 1, 10, 1, 1),
    mainland_clade = "nonsense",
    mainland_sample_prob = 1)
  )

  expect_error(sim_island(
    total_time = 1,
    island_pars = c(1, 1, 10, 1, 1),
    mainland_clade = create_test_mainland_clade(mainland_scenario = 1),
    mainland_sample_prob = "nonsense")
  )
})

These tests check all the input arguments of sim_island to be valid.

Except for one: mainland_sample_type, is missing.

I suggest to add the following test (I have confiremed it fails now) to ensure that sim_island properly checks all inputs:

  expect_error(sim_island(
    total_time = 1,
    island_pars = c(1, 1, 10, 1, 1),
    mainland_clade = create_test_mainland_clade(mainland_scenario = 1),
    mainland_sample_prob = 1,
    mainland_sample_type = "nonsense")
  )

Note that I found out when I used mainland_sample_type = "ideal", which is an invalid input (complete is the value I should have used here).

Thanks for considering my suggestion!

Note to self: just add

  testit::assert(mainland_sample_type == "unsampled" ||
                   mainland_sample_type == "undiscovered" ||
                   mainland_sample_type == "complete")

which I copied from another function :-)

Fixed, will close when merged to main.