Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RTest: A package for human readable tests in R
library(RTest)
# Overwrite testthat as.expectation.logical for more comprehensive output
assignInNamespace("as.expectation.logical", RTest::as.expectation.logical, ns="testthat", pos="package:testthat")
my_function <<- function(data = data.frame(x=c(1,2),y=c(1,2))){
stopifnot(dim(data)[2]==2)
data[,"sum"] <- apply(data,1,function(x){sum(x)})
return(data)
}
RTest.execute(getwd(),"RTest_medium.xml")
<?xml version="1.0" encoding="UTF-8"?>
<RTestCase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../xsd/RTest.xsd">
<ID>RTest_TC-medium</ID>
<synopsis>
<version>01</version>
<author>Sebastian Wolf</author>
<creation-date>2018-12-11</creation-date>
</synopsis>
<input-data>
<data.frame name="test01">
<col-defs>
<coldef name="x" type="numeric" />
<coldef name="y" type="numeric" />
</col-defs>
<row>
<cell>1</cell>
<cell>2</cell>
</row>
<row>
<cell>1</cell>
<cell>2</cell>
</row>
</data.frame>
</input-data>
<tests>
<RTest>
<my_function test-desc="Test data.frame">
<params>
<RTestData_input_data param="data" name="test01" />
</params>
<reference>
<col-defs>
<coldef name="x" type="numeric" />
<coldef name="y" type="numeric" />
<coldef name="sum" type="numeric" />
</col-defs>
<row>
<cell>1</cell>
<cell>2</cell>
<cell>3</cell>
</row>
<row>
<cell>1</cell>
<cell>2</cell>
<cell>3</cell>
</row>
</reference>
<testspec>
<execution execution-type="silent" />
<return-value compare-type="equal" diff-type="absolute"
tolerance="0.001" />
</testspec>
</my_function>
<my_function test-desc="Test data.frame">
<params>
<RTestData_input_data param="data" name="test01" />
</params>
<reference>
<col-defs>
<coldef name="x" type="numeric" />
<coldef name="y" type="numeric" />
<coldef name="sum" type="numeric" />
</col-defs>
<row>
<cell>1</cell>
<cell>2</cell>
<cell>3</cell>
</row>
<row>
<cell>1</cell>
<cell>2</cell>
<cell>3.5</cell>
</row>
</reference>
<testspec>
<execution execution-type="silent" />
<return-value compare-type="equal" diff-type="absolute"
tolerance="0.001" />
</testspec>
</my_function>
</RTest>
</tests>
</RTestCase>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.