Skip to content

Instantly share code, notes, and snippets.

@zappingseb
Last active January 8, 2019 00:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zappingseb/0f5dabe94c7d284bc543469c50a4213c to your computer and use it in GitHub Desktop.
Save zappingseb/0f5dabe94c7d284bc543469c50a4213c to your computer and use it in GitHub Desktop.
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