inst/unitTests/runitPhGcode.R

## runitsPhGcode.R test suite
## by Ph. Grosjean <phgrosjean@sciviews.org>
## Run it simply by example(unitTests.PhGcode) TODO: adapt this!

## Create a few objects we need for our tests
# ...

## Create a very simple 'svTest' object
#test_R <- svTest(function () {
#	checkTrue(1 < 2)
#})

## The test cases
.setUp <- function () {
	## Executed before each test function
	# ...
	library(PhGcode)
	
	## Create a function (just an example, replace with real code here)
	foo <- function(x) return(x)
}

.tearDown <- function () {
	## Executed after each test function
	## Restore previous exclusion list
	# ...
	## Remove our object with tests in .GlobalEnv
	rm(foo, envir = .GlobalEnv)
	
	## Detach and unload package
	#detach("package:PhGcode", unload = TRUE)
}

testCube <- function () {
	checkEqualsNumeric(8, cube(2), "cube(2) must return 8)")
	checkEqualsNumeric(-8, cube(-2), "cube(-2) must return -8)")
	checkEqualsNumeric(0, cube(0), "cube(0) must return 0)")
	checkEqualsNumeric(c(1, 8, 27), cube(1:3), "cube(1:3) must return 1, 8, 27)")
	checkTrue(is.nan(cube(NaN)), "cube(NaN) must return NaN")
	checkEqualsNumeric(8, cube(2L), "cube(2L) (integer) must return 8)")
	checkException(cube("a"), "cube(\"a\") raises an exception")
}

testCbrt <- function () {
	checkEqualsNumeric(2, cbrt(8), "cbrt(8) must return 2)")
	checkTrue(is.nan(cbrt(-8)), "cbrt(-8) must return NaN)")
	checkEqualsNumeric(0, cbrt(0), "cbrt(0) must return 0)")
	checkEqualsNumeric(c(1, 2, 3), cbrt(c(1, 8, 27)), "cbrt(c(1, 8, 27)) must return 1, 2, 3)")
	checkTrue(is.nan(cbrt(NaN)), "cbrt(NaN) must return NaN")
	checkEqualsNumeric(2, cbrt(8L), "cbrt(8L) (integer) must return 2)")
	checkException(cbrt("a"), "cbrt(\"a\") raises an exception")
}
phgrosjean/R-code documentation built on May 25, 2019, 2:55 a.m.