Skip to content

Commit

Permalink
refactor / comment tests; explicit namespace references
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebaron committed Aug 2, 2024
1 parent bf20647 commit efac0a6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
16 changes: 6 additions & 10 deletions inst/base/mrgsolve-evtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mrgsolve::evdata bolus(const double amt, const int cmt) {
}

void bolus(databox& self, const double amt, const int cmt) {
mrgsolve::evdata ev = bolus(amt, cmt);
mrgsolve::evdata ev = evt::bolus(amt, cmt);
self.mevector.push_back(ev);
return;
}
Expand All @@ -29,7 +29,7 @@ mrgsolve::evdata infuse(const double amt, const int cmt, const double rate) {
}

void infuse(databox& self, const double amt, const int cmt, const double rate) {
mrgsolve::evdata ev = infuse(amt, cmt, rate);
mrgsolve::evdata ev = evt::infuse(amt, cmt, rate);
self.mevector.push_back(ev);
return;
}
Expand All @@ -44,7 +44,7 @@ mrgsolve::evdata replace(const double amt, const int cmt) {
}

void replace(databox& self, const double amt, const int cmt) {
mrgsolve::evdata ev = replace(amt, cmt);
mrgsolve::evdata ev = evt::replace(amt, cmt);
self.mevector.push_back(ev);
return;
}
Expand All @@ -58,29 +58,25 @@ mrgsolve::evdata reset() {

mrgsolve::evdata reset(const double amt, const int cmt,
const double rate = 0) {
mrgsolve::evdata ev(0, 4);
mrgsolve::evdata ev = evt::reset();
ev.cmt = cmt;
ev.amt = amt;
ev.rate = rate;
ev.now = true;
ev.check_unique = false;
return ev;
}

void reset(databox& self) {
evt::ev ev = reset();
mrgsolve::evdata ev = evt::reset();
self.mevector.push_back(ev);
return;
}

void reset(databox& self, const double amt, const int cmt,
const double rate = 0) {
evt::ev ev(0, 4);
mrgsolve::evdata ev = evt::reset();
ev.cmt = cmt;
ev.amt = amt;
ev.rate = rate;
ev.now = true;
ev.check_unique = false;
self.mevector.push_back(ev);
return;
}
Expand Down
49 changes: 29 additions & 20 deletions inst/maintenance/unit-cpp/test-evtools.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,26 @@ if(mode==8 && givedose) {
evt::retime(rep, reptime);
self.push(rep);
}
if(mode==9 && givedose) {
if(mode==9 && givedose) { // reset
evt::reset(self);
}
if(mode==10 && givedose) {
}
if(mode==10 && givedose) { // reset, non-self
evt::ev res = evt::reset();
res.time = 15;
self.push(res);
}
if(mode==11 && givedose) {
if(mode==11 && givedose) { // reset with bolus
evt::reset(self, 100, 3);
}
if(mode==12 && givedose) {
if(mode==12 && givedose) { // reset with infusion
evt::reset(self, 100, 1, 20);
}
if(mode==13 && givedose) {
if(mode==13 && givedose) { // reset with bolus, non-self
evt::ev res = evt::reset(100, 3);
self.push(res);
}
if(mode==14 && givedose) {
evt::ev res = evt::reset(100, 1, 20);
if(mode==14 && givedose) { // reset with infusion, non-self
evt::ev res = evt::reset(100, 1, 100.0/5.0);
self.push(res);
}
'
Expand Down Expand Up @@ -167,13 +167,17 @@ test_that("evtools - reset", {
out <- mrgsim(mod)
expect_true(all(out$A==0))
expect_true(all(out$C==0))
x <- filter(out, time %in% c(0,5))
# B starts at 50 and then is reset at time==5
x <- filter(out, time %in% c(0, 5))
expect_true(all(x$B==50))
# Verify value of B just before reset
x <- filter(out, time==4)
expect_equal(x$B, 50*exp(-0.1*4), tolerance = 1e-2)
mod <- param(mod, mode = 10)
out2 <- mrgsim(mod)
expect_equal(out@data, out2@data)
# Identical results if the self or non-self function is called
out1 <- mrgsim(mod, param = list(mode = 9))
out2 <- mrgsim(mod, param = list(mode = 10))
expect_equal(out1@data, out2@data)
})

test_that("evtools - reset with bolus", {
Expand All @@ -187,28 +191,33 @@ test_that("evtools - reset with bolus", {
expect_equal(x$C, 0)
x <- filter(out, time > 5)
expect_true(all(x$C==100))

# Identical results if the self method called or non-self
out1 <- mrgsim(mod, param = list(mode = 11))
out2 <- mrgsim(mod, param = list(mode = 12))

expect_identical(out1@data, out3@data)
})


test_that("evtools - reset with infusion", {
mod <- param(mod, dosetime = 5, B0 = 50, mode = 12)
out <- mrgsim(mod, rtol = 1e-12)
x <- filter(out, time %in% c(0,5))
out <- mrgsim(mod, rtol = 1e-12, delta = 0.25)
# B should be 50 to start and the reset time
x <- filter(out, time %in% c(0, 5))
expect_true(all(x$B==50))
expect_true(all(x$A==0))
# Check values of A and B just before reset
x <- filter(out, time == 4.75)
expect_equal(x$A, 0)
expect_equal(x$B, 50*exp(-0.1*4.75), tolerance = 1e-2)
# Maximum A is at the end of the infusion
# Check the infusion; Amax should be at the end of the 5 hr infusion
x <- filter(out, A==max(A))
expect_equal(x$time, 10)

# Identical results
out1 <- mrgsim(mod, param = list(mode = 11))
out2 <- mrgsim(mod, param = list(mode = 12))
out3 <- mrgsim(mod, param = list(mode = 13))
out4 <- mrgsim(mod, param = list(mode = 14))
# Identical results if the self method called or non-self
out1 <- mrgsim(mod, param = list(mode = 13))
out2 <- mrgsim(mod, param = list(mode = 14))

expect_identical(out1@data, out3@data)
expect_identical(out2@data, out4@data)
})

0 comments on commit efac0a6

Please sign in to comment.