Skip to content

Commit

Permalink
Update regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stewid committed Mar 19, 2017
1 parent 4641edc commit 69dbac2
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 125 deletions.
12 changes: 8 additions & 4 deletions tests/SEIR.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,12 @@ stopifnot(file.exists(pdf_file))
unlink(pdf_file)

## Check that C SEIR run function fails for a misspecified SEIR model
res <- .Call("SEIR_run", NULL, NULL, NULL, PACKAGE = "SimInf")
stopifnot(identical(res$error, -10L))
res <- tools::assertError(.Call("SEIR_run", NULL, NULL, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid model.",
res[[1]]$message)) > 0)

res <- .Call("SEIR_run", "SEIR", NULL, NULL, PACKAGE = "SimInf")
stopifnot(identical(res$error, -10L))
res <- tools::assertError(.Call("SEIR_run", "SEIR", NULL, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid model.",
res[[1]]$message)) > 0)
12 changes: 8 additions & 4 deletions tests/SIR.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,12 @@ stopifnot(file.exists(pdf_file))
unlink(pdf_file)

## Check that C SIR run function fails for misspecified SIR model
res <- .Call("SIR_run", NULL, NULL, NULL, PACKAGE = "SimInf")
stopifnot(identical(res$error, -10L))
res <- tools::assertError(.Call("SIR_run", NULL, NULL, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid model.",
res[[1]]$message)) > 0)

res <- .Call("SIR_run", "SIR", NULL, NULL, PACKAGE = "SimInf")
stopifnot(identical(res$error, -10L))
res <- tools::assertError(.Call("SIR_run", "SIR", NULL, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid model.",
res[[1]]$message)) > 0)
12 changes: 8 additions & 4 deletions tests/SISe.R
Original file line number Diff line number Diff line change
Expand Up @@ -1088,11 +1088,15 @@ stopifnot(file.exists(pdf_file))
unlink(pdf_file)

## Check that C SISe run function fails for misspecified SISe model
res <- .Call("SISe_run", NULL, NULL, NULL, PACKAGE = "SimInf")
stopifnot(identical(res$error, -10L))
res <- tools::assertError(.Call("SISe_run", NULL, NULL, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid model.",
res[[1]]$message)) > 0)

res <- .Call("SISe_run", "SISe", NULL, NULL, PACKAGE = "SimInf")
stopifnot(identical(res$error, -10L))
res <- tools::assertError(.Call("SISe_run", "SISe", NULL, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid model.",
res[[1]]$message)) > 0)

## Check error non-finite v
model <- SISe(u0 = u0,
Expand Down
12 changes: 8 additions & 4 deletions tests/SISe3.R
Original file line number Diff line number Diff line change
Expand Up @@ -1512,11 +1512,15 @@ stopifnot(file.exists(pdf_file))
unlink(pdf_file)

## Check that C SISe3 run function fails for misspecified SISe3 model
res <- .Call("SISe3_run", NULL, NULL, NULL, PACKAGE = "SimInf")
stopifnot(identical(res$error, -10L))
res <- tools::assertError(.Call("SISe3_run", NULL, NULL, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid model.",
res[[1]]$message)) > 0)

res <- .Call("SISe3_run", "SISe3", NULL, NULL, PACKAGE = "SimInf")
stopifnot(identical(res$error, -10L))
res <- tools::assertError(.Call("SISe3_run", "SISe3", NULL, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid model.",
res[[1]]$message)) > 0)

## Check error non-finite v
model <- SISe3(u0 = u0,
Expand Down
12 changes: 8 additions & 4 deletions tests/SISe3_sp.R
Original file line number Diff line number Diff line change
Expand Up @@ -1635,11 +1635,15 @@ stopifnot(file.exists(pdf_file))
unlink(pdf_file)

## Check that C SISe3_sp run function fails for misspecified SISe3_sp model
res <- .Call("SISe3_sp_run", NULL, NULL, NULL, PACKAGE = "SimInf")
stopifnot(identical(res$error, -10L))
res <- tools::assertError(.Call("SISe3_sp_run", NULL, NULL, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid model.",
res[[1]]$message)) > 0)

res <- .Call("SISe3_sp_run", "SISe3_sp", NULL, NULL, PACKAGE = "SimInf")
stopifnot(identical(res$error, -10L))
res <- tools::assertError(.Call("SISe3_sp_run", "SISe3_sp", NULL, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid model.",
res[[1]]$message)) > 0)

## Check error non-finite v
model <- SISe3_sp(u0 = u0,
Expand Down
12 changes: 8 additions & 4 deletions tests/SISe_sp.R
Original file line number Diff line number Diff line change
Expand Up @@ -1107,11 +1107,15 @@ stopifnot(file.exists(pdf_file))
unlink(pdf_file)

## Check that C SISe_sp run function fails for misspecified SISe_sp model
res <- .Call("SISe_sp_run", NULL, NULL, NULL, PACKAGE = "SimInf")
stopifnot(identical(res$error, -10L))
res <- tools::assertError(.Call("SISe_sp_run", NULL, NULL, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid model.",
res[[1]]$message)) > 0)

res <- .Call("SISe_sp_run", "SISe_sp", NULL, NULL, PACKAGE = "SimInf")
stopifnot(identical(res$error, -10L))
res <- tools::assertError(.Call("SISe_sp_run", "SISe_sp", NULL, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid model.",
res[[1]]$message)) > 0)

## Check error non-finite v
model <- SISe_sp(u0 = u0,
Expand Down
16 changes: 8 additions & 8 deletions tests/sample_select.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ model <- SISe3(u0 = u0,
## Replace proportion = 1 with proportion = 10
model@events@proportion <- 10

res <- .Call("SISe3_run", model, 1L, NULL, PACKAGE = "SimInf")
res <- tools::assertError(SimInf:::siminf_error(res$error))
res <- tools::assertError(.Call("SISe3_run", model, 1L, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Unable to sample individuals for event.",
res[[1]]$message)) > 0)

if (SimInf:::have_openmp()) {
res <- .Call("SISe3_run", model, 2L, NULL, PACKAGE = "SimInf")
res <- tools::assertError(SimInf:::siminf_error(res$error))
res <- tools::assertError(.Call("SISe3_run", model, 2L,
NULL, PACKAGE = "SimInf"))
stopifnot(length(grep("Unable to sample individuals for event.",
res[[1]]$message)) > 0)
}
Expand Down Expand Up @@ -318,14 +318,14 @@ model <- SISe3(u0 = u0,
## Replace proportion = 0 with proportion = -1
model@events@proportion <- -1

res <- .Call("SISe3_run", model, 1L, NULL, PACKAGE = "SimInf")
res <- tools::assertError(SimInf:::siminf_error(res$error))
res <- tools::assertError(.Call("SISe3_run", model, 1L, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Unable to sample individuals for event.",
res[[1]]$message)) > 0)

if (SimInf:::have_openmp()) {
res <- .Call("SISe3_run", model, 2L, NULL, PACKAGE = "SimInf")
res <- tools::assertError(SimInf:::siminf_error(res$error))
res <- tools::assertError(.Call("SISe3_run", model, 2L, NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Unable to sample individuals for event.",
res[[1]]$message)) > 0)
}
Expand Down
177 changes: 84 additions & 93 deletions tests/siminf.R
Original file line number Diff line number Diff line change
Expand Up @@ -833,12 +833,13 @@ if (SimInf:::have_openmp()) {
NULL,
PACKAGE = "SimInf")

res <- .Call("SISe_run",
demo_model(model = "SISe"),
NULL,
"1",
PACKAGE = "SimInf")
stopifnot(identical(res$error, -6L))
res <- tools::assertError(.Call("SISe_run",
demo_model(model = "SISe"),
NULL,
"1",
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid 'seed' value",
res[[1]]$message)) > 0)

.Call("SISe_run",
demo_model(model = "SISe"),
Expand All @@ -864,33 +865,37 @@ stopifnot(identical(res$error, -6L))
1,
PACKAGE = "SimInf")

res <- .Call("SISe_run",
demo_model(model = "SISe"),
NULL,
NA_integer_,
PACKAGE = "SimInf")
stopifnot(identical(res$error, -6L))

res <- .Call("SISe_run",
demo_model(model = "SISe"),
NULL,
NA_real_,
PACKAGE = "SimInf")
stopifnot(identical(res$error, -6L))

res <- .Call("SISe_run",
demo_model(model = "SISe"),
NULL,
c(1L, 2L),
PACKAGE = "SimInf")
stopifnot(identical(res$error, -6L))

res <- .Call("SISe_run",
demo_model(model = "SISe"),
NULL,
c(1, 2),
PACKAGE = "SimInf")
stopifnot(identical(res$error, -6L))
res <- tools::assertError(.Call("SISe_run",
demo_model(model = "SISe"),
NULL,
NA_integer_,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid 'seed' value",
res[[1]]$message)) > 0)

res <- tools::assertError(.Call("SISe_run",
demo_model(model = "SISe"),
NULL,
NA_real_,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid 'seed' value",
res[[1]]$message)) > 0)

res <- tools::assertError(.Call("SISe_run",
demo_model(model = "SISe"),
NULL,
c(1L, 2L),
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid 'seed' value",
res[[1]]$message)) > 0)

res <- tools::assertError(.Call("SISe_run",
demo_model(model = "SISe"),
NULL,
c(1, 2),
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid 'seed' value",
res[[1]]$message)) > 0)

## Check extraction of number of threads
.Call("SISe_run",
Expand All @@ -911,72 +916,58 @@ stopifnot(identical(res$error, -6L))
NULL,
PACKAGE = "SimInf")

res <- .Call("SISe_run",
demo_model(model = "SISe"),
-1L,
NULL,
PACKAGE = "SimInf")
stopifnot(identical(res$error, -7L))

res <- .Call("SISe_run",
demo_model(model = "SISe"),
-1,
NULL,
PACKAGE = "SimInf")
stopifnot(identical(res$error, -7L))

res <- .Call("SISe_run",
demo_model(model = "SISe"),
"1",
NULL,
PACKAGE = "SimInf")
stopifnot(identical(res$error, -7L))

res <- .Call("SISe_run",
demo_model(model = "SISe"),
c(1L, 1L),
NULL,
PACKAGE = "SimInf")
stopifnot(identical(res$error, -7L))

res <- .Call("SISe_run",
demo_model(model = "SISe"),
c(1, 1),
NULL,
PACKAGE = "SimInf")
stopifnot(identical(res$error, -7L))

res <- .Call("SISe_run",
demo_model(model = "SISe"),
NA_integer_,
NULL,
PACKAGE = "SimInf")
stopifnot(identical(res$error, -7L))

res <- .Call("SISe_run",
demo_model(model = "SISe"),
NA_real_,
NULL,
PACKAGE = "SimInf")
stopifnot(identical(res$error, -7L))

## Check error codes in siminf_error
res <- tools::assertError(SimInf:::siminf_error("err"))
stopifnot(length(grep("'err' must be an integer vector of length 1",
res <- tools::assertError(.Call("SISe_run",
demo_model(model = "SISe"),
-1L,
NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid 'threads' value",
res[[1]]$message)) > 0)

res <- tools::assertError(.Call("SISe_run",
demo_model(model = "SISe"),
-1,
NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid 'threads' value",
res[[1]]$message)) > 0)

res <- tools::assertError(.Call("SISe_run",
demo_model(model = "SISe"),
"1",
NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid 'threads' value",
res[[1]]$message)) > 0)

res <- tools::assertError(SimInf:::siminf_error(c(-1L, -1L)))
stopifnot(length(grep("'err' must be an integer vector of length 1",
res <- tools::assertError(.Call("SISe_run",
demo_model(model = "SISe"),
c(1L, 1L),
NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid 'threads' value",
res[[1]]$message)) > 0)

res <- tools::assertError(SimInf:::siminf_error(-1.1))
stopifnot(length(grep("'err' must be an integer vector of length 1",
res <- tools::assertError(.Call("SISe_run",
demo_model(model = "SISe"),
c(1, 1),
NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid 'threads' value",
res[[1]]$message)) > 0)

res <- tools::assertError(SimInf:::siminf_error(-10))
stopifnot(length(grep("Invalid model",
res <- tools::assertError(.Call("SISe_run",
demo_model(model = "SISe"),
NA_integer_,
NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid 'threads' value",
res[[1]]$message)) > 0)

res <- tools::assertError(SimInf:::siminf_error(-9000))
stopifnot(length(grep("Unknown error code",
res <- tools::assertError(.Call("SISe_run",
demo_model(model = "SISe"),
NA_real_,
NULL,
PACKAGE = "SimInf"))
stopifnot(length(grep("Invalid 'threads' value",
res[[1]]$message)) > 0)

0 comments on commit 69dbac2

Please sign in to comment.