Sample R code to demonstrate Test driven development using testthat package in R. Also how auto grading can be done.
- Open the R Project file in RStudio instead of the indvidual files so that working directory is set automatically. Else some code changes would be required to test and code folders in auto_test function.
- Have two folders, one in which code is kept and another in which testcase files are present.
- The main file is auto_code.R, that executes auto_code function with 2 parameters.
- First parameter is the folder that contains source code and second parameter is the folder that contains test cases.
- On any change of code or test cases, the auto_code runs all the test cases again.
- There is a last test case written to print result (written for failure)
- This sample also demonstrates how auto grading can be done for a R assignment.