Skip to content

Commit

Permalink
Merge pull request #130 from keaven/testthat-helper
Browse files Browse the repository at this point in the history
Move independently programmed functions for validation to `helper.R`
  • Loading branch information
nanxstats authored Feb 21, 2024
2 parents 81837cd + 2dfdb32 commit ae18ea5
Show file tree
Hide file tree
Showing 38 changed files with 54 additions and 98 deletions.
2 changes: 2 additions & 0 deletions tests/gsDesign_independent_code.R → tests/testthat/helper.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file was formerly stored as `tests/gsDesign_independent_code.R` and is
# now moved to `tests/testthat/helper.R` to follow testthat best practices.

# This script contains independently programmed functions for validating some of
# the functions of the gsDesign package.
Expand Down
4 changes: 1 addition & 3 deletions tests/testthat/test-independent-test-binomialSPRT.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
## For such test cases,the tolerance is set to 1e-6 (= 0.000001), a sufficiently
## low value.

source('../gsDesign_independent_code.R')

validate_vd <- Validate_comp_sprt_bnd(
alpha = 0.1, beta = 0.15, p0 = 0.05, p1 = 0.25,
nmin = 10, nmax = 35
Expand All @@ -22,7 +20,7 @@ exct_des <- gsBinomialExact(


testthat::test_that(desc = "Test binomialSPRT function
source : independent R Program-gsDesign_independent_code.R", code = {
source : independent R Program-helper.R", code = {
binSPRT <- binomialSPRT(
p0 = 0.05,
p1 = 0.25,
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-independent-test-eEvents.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
# #----------------------------------
# ### Testing eEvents function
# For comparing floating-point numbers, an exact match cannot be expected.
Expand All @@ -8,7 +7,7 @@ source('../gsDesign_independent_code.R')

test_that(
desc = "test: checking number of events on a single arm
source : gsDesign_independent_code.R",
source : helper.R",
code = {
nEv <- eEvents(
lambda = 0.2, eta = 0.1, gamma = 1,
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-independent-test-gsBoundCP.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#---------------
##gsBoundCP
#--------------
Expand Down Expand Up @@ -33,7 +32,7 @@ testthat::test_that(desc = "Test: out of range theta", code = {


testthat::test_that(desc = "Test: output validation
source: gsDesign_independent_code.R",
source: helper.R",
code = {
x = gsDesign(k =3, test.type=1, delta = 0.22)
local_edition(3)
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-independent-test-gsCPOS.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#------------
## gsCPOS
#------------
Expand Down Expand Up @@ -33,7 +32,7 @@ testthat::test_that(desc = "Test: checking out of range i ", code = {


testthat::test_that(desc = "Test: output validation
source: gsDesign_independent_code.R", code = {
source: helper.R", code = {
x <- gsDesign(k = 3, test.type = 2, n.fix = 800)
theta = c(-1.50, -0.75, 0.00, 0.75, 1.50)
wgts = c(0.064758798, 0.301137432, 0.199471140, 0.301137432, 0.064758798)
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-test-gsNormalGrid.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
# Testing gsNormalGrid() : normalGrid() is intended to be used for computation of
# the expected value of a function of a normal random variable.
# The function produces grid points and weights to be used for numerical integration.
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-independent-test-gsPI.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#---------------
## gsPI

Expand Down Expand Up @@ -53,7 +52,7 @@ testthat::test_that(desc = "Test: checking variable type", code = {


testthat::test_that(desc = "Test: checking output validation
source: gsDesign_independent_code.R",
source: helper.R",
code = {

x <- gsDesign(k = 4, n.fix = 1371, timing = c(0.25,0.5, 0.7),
Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test-independent-test-gsPP.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
source('../gsDesign_independent_code.R')
#---------------
### Testing gsPP:
#---------------

# testing TestCase1_gsPP test.type = 2
testthat::test_that(desc = "Test: checking output validation,
source: gsDesign_independent_code.R",
source: helper.R",
code = {
x <- gsDesign(k = 4, test.type = 2, n.fix = 800)
zi <- 1
Expand All @@ -25,7 +24,7 @@ testthat::test_that(desc = "Test: checking output validation,

# testing TestCase1_gsPP test.type = 1
testthat::test_that(desc = "Test: checking output validation,
source: gsDesign_independent_code.R",
source: helper.R",
code = {
x <- gsDesign(k = 4, test.type = 1, n.fix = 800)
zi <- 0
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-independent-test-gsPosterior.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#--------------------------------------------
### Testing gsPosterior:
#---------------------------------------------
Expand Down Expand Up @@ -101,7 +100,7 @@ testthat::test_that(desc = "Test: checking z variable types.", code = {

testthat::test_that(
desc = "Test: checking Output validation,
source: /tests/cytel/gsDesign_independent_code.R",
source: helper.R",
code = {
x <- gsDesign(k = 3, test.type = 1, n.fix = 800)
theta <- seq(-3, 3, 0.75)
Expand Down
7 changes: 3 additions & 4 deletions tests/testthat/test-independent-test-gsZ.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
source('../gsDesign_independent_code.R')
#---------------
### Testing gsZ:
#---------------


testthat::test_that(
desc = "test: checking output validation density = 0,
source independent R Program gsDesign_independent_code.R",
source independent R Program helper.R",
code = {
x <- gsDesign(k = 3, test.type = 1, n.fix = 800)
theta <- c(0, 0.5)
Expand All @@ -33,7 +32,7 @@ testthat::test_that(desc = "test: checking error x$n.I", code = {

testthat::test_that(
desc = "test : checking output validation,
source : independent R Program gsDesign_independent_code.R",
source : independent R Program helper.R",
code = {
x <- gsDesign(k = 3, test.type = 1, n.fix = 800)
theta <- c(0, 2, 0.5)
Expand All @@ -52,7 +51,7 @@ testthat::test_that(

testthat::test_that(
desc = "test : checking output validation,
source : independent R Program gsDesign_independent_code.R",
source : independent R Program helper.R",
code = {
x <- gsDesign(k = 4, test.type = 2, n.fix = 800)
theta <- c(0, 0.1, 0.05)
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-test-hGraph.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#-------------------------------------------------------------------------------
# hGraph : hGraph() plots a multiplicity graph defined by user inputs. The graph
# can also be used with the **gMCPLite** package to evaluate a set of
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-test-plot.binomialSPRT.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
# --------------------------------------------
# Test plot.binomialSPRT function
#----------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
# --------------------------------------------
# Test plot.gsBinomialExact function
#----------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-test-plot.gsDesign.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
# --------------------------------------------
# Test plot.gsDesign function
## save_gg_plot() is used for storing plots created using ggplot2 package,
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-test-plot.gsProbability.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
# --------------------------------------------
# Test plot.gsProbability function
## save_gg_plot() is used for storing plots created using ggplot2 package,
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-test-plot.ssrCP.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#----------------------
# plot.ssrCP
#---------------------
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-test-plotHR.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#################################################
# Test plotHR function
#################################################
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-test-plotRR.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#################################################
# Test plotRR function
#################################################
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-test-plotgsCP.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#-------------------------------------------------------------------------------
# expected CP Calculations done using East 6.5
# source file : tests/benchmarks/gsqplot.cywx
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-test-plotgsPower.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#-------------------------------------------------------------------------------
# Probability Calculations done using East 6.5',
# source : tests/benchmarks/gsqplot.cywx
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-test-plotgsZ.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#################################################
# Test plotgsZ function
#################################################
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-test-plotsf.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#------------
## plotsf
#-----------
Expand Down
7 changes: 3 additions & 4 deletions tests/testthat/test-independent-test-sfBetaDist.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#-----------------------------------
### Testing sfBetaDist function
#-----------------------------------
Expand Down Expand Up @@ -134,7 +133,7 @@ testthat::test_that("Test: param - Checking Variable Type, Out-of-Range,


testthat::test_that("Test: output validation for param of length 2 :
Source: gsDesign_independent_code.R)", {
Source: helper.R)", {

t <- c(.01, .05, .1, .25, .5,1)
param<-c(0.25,0.1)
Expand All @@ -148,7 +147,7 @@ testthat::test_that("Test: output validation for param of length 2 :


testthat::test_that("Test: for param of length 2, t of length 5 :
Source: gsDesign_independent_code.R)", {
Source: helper.R)", {

t <- c(.01, .05, .1, .25, .5)
param<-c(0.25,0.1)
Expand All @@ -162,7 +161,7 @@ testthat::test_that("Test: for param of length 2, t of length 5 :


testthat::test_that("Test: for param of length 2, t of length 7 :
Source: gsDesign_independent_code.R)", {
Source: helper.R)", {

t <- c(.01, .05, .1, .25, .5, 1, 1.02)
param<-c(0.25,0.1)
Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test-independent-test-sfCauchy.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#----------------------------------
### Testing sfCauchy function
#----------------------------------
Expand Down Expand Up @@ -144,7 +143,7 @@ testthat::test_that("Test: param - Testing incorrect variable type,


testthat::test_that("Test: output validation param length as 2,
Source: gsDesign_independent_code.R", {
Source: helper.R", {

t <- c(0.25, 0.5, 0.75, 1)
param <- c(1, 2)
Expand All @@ -158,7 +157,7 @@ testthat::test_that("Test: output validation param length as 2,


testthat::test_that("Test: output validation param length as 4,
Source: gsDesign_independent_code.R", {
Source: helper.R", {
t <- c(0.25, 0.5, .75, 1)
param <- c(0.2, 0.4, 0.1, 0.3)
alpha <- 0.05
Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test-independent-test-sfExtremeValue.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#-----------------------------------
### Testing sfExtremeValue function
#-----------------------------------
Expand Down Expand Up @@ -139,7 +138,7 @@ testthat::test_that("Test: param - Testing incorrect variable type,


testthat::test_that("Test: output validation param length as 2,
Source: gsDesign_independent_code.R", {
Source: helper.R", {

t <- c(0.2, 0.15, .75, 1)
param<-c(0.1, 0.2)
Expand All @@ -153,7 +152,7 @@ testthat::test_that("Test: output validation param length as 2,


testthat::test_that("Test: output validation param length as 4,
Source: gsDesign_independent_code.R", {
Source: helper.R", {

t <- c(0.2, 0.15, 0.75, 1)
param<-c(0.1, 0.2, 0.2, 0.3)
Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test-independent-test-sfExtremeValue2.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
### Testing sfExtremeValue2 function
#-----------------------------------

Expand Down Expand Up @@ -136,7 +135,7 @@ testthat::test_that("Test: param - Testing incorrect variable type,


testthat::test_that("Test: output validation param length as 2,
Source: gsDesign_independent_code.R)", {
Source: helper.R)", {

t <- c(.25, .5, .75, 1)
param <- c(.1, .2)
Expand All @@ -150,7 +149,7 @@ testthat::test_that("Test: output validation param length as 2,


testthat::test_that("Test: output validation param length as 4,
Source: gsDesign_independent_code.R", {
Source: helper.R", {

t <- c(.25,.5,.75,1)
param <- c(.4, .5,.2,.3)
Expand Down
8 changes: 3 additions & 5 deletions tests/testthat/test-independent-test-sfGapped.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source('../gsDesign_independent_code.R')

#-----------------------------------
### Testing sfGapped function
#-----------------------------------
Expand Down Expand Up @@ -145,7 +143,7 @@ testthat::test_that("Test: param - Checking Variable Type,


testthat::test_that("Test: sfNormal,
Source: gsDesign_independent_code.R", {
Source: helper.R", {
tx <- c(0.167,0.333,0.5,0.667,0.833,1)
param <- list(trange = c(.2, .8), sf = gsDesign::sfNormal, param = c(1,2))
alpha<-0.05
Expand All @@ -157,7 +155,7 @@ testthat::test_that("Test: sfNormal,


testthat::test_that("Test: sfExponential: Output verification,
Source: gsDesign_independent_code.R", {
Source: helper.R", {

tx <- c(0.167,0.333,0.5,0.667,0.833,1)
param <- list(trange = c(.2, .8), sf = gsDesign::sfExponential, param = 1.5 )
Expand All @@ -170,7 +168,7 @@ testthat::test_that("Test: sfExponential: Output verification,


testthat::test_that("Test: sfLDPocock: Output verification,
Source: gsDesign_independent_code.R", {
Source: helper.R", {


tx <- c(0.167,0.333,0.5,0.667,0.833,1)
Expand Down
7 changes: 3 additions & 4 deletions tests/testthat/test-independent-test-sfLogistic.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source('../gsDesign_independent_code.R')
#-----------------------------------
# Test sfLogistic function
#-----------------------------------
Expand Down Expand Up @@ -152,7 +151,7 @@ testthat::test_that("Test: param - Checking Variable Type,


testthat::test_that("Test: output validation param of length 2,
Source: gsDesign_independent_code.R", {
Source: helper.R", {

t <- c(0.33, 0.67, 1)
param<-c(0, 1)
Expand All @@ -164,7 +163,7 @@ testthat::test_that("Test: output validation param of length 2,
})

testthat::test_that("Test: output validation param of length 2, t of length 4,
Source: gsDesign_independent_code.R", {
Source: helper.R", {

t <- c(0.2, 0.5, 0.7, 1)
param<-c(1, 1)
Expand All @@ -177,7 +176,7 @@ testthat::test_that("Test: output validation param of length 2, t of length 4,


testthat::test_that("Test: output validation param of length 4,
Source: gsDesign_independent_code.R", {
Source: helper.R", {

t <- c(0.33, 0.67, 1)
param<-c(0.01, .1, .1, 0.4)
Expand Down
Loading

0 comments on commit ae18ea5

Please sign in to comment.