From d4cc70dfdd3b27ec0cbb3be62476848fd8b96da0 Mon Sep 17 00:00:00 2001 From: Morgan Benton Date: Sat, 10 Jan 2015 18:26:49 -0500 Subject: [PATCH 1/6] added hello-world; updated config.json; created run_tests scripts --- .DS_Store | Bin 0 -> 6148 bytes bin/run_tests.R | 29 +++++++++++++++++++++++++++++ bin/run_tests.bat | 12 ++++++++++++ config.json | 6 +++--- hello-world/example.R | 3 +++ hello-world/hello-world_test.R | 14 ++++++++++++++ 6 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 .DS_Store create mode 100755 bin/run_tests.R create mode 100644 bin/run_tests.bat create mode 100644 hello-world/example.R create mode 100644 hello-world/hello-world_test.R diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8b6339a56b4c4cb76313a3df62979b8da67845a8 GIT binary patch literal 6148 zcmeH~JqiLr422W55Nx)zoW=uqgF*BJUO;pa1kpn5=jgutG_KaN$O|OjB(q_6U$L_h z5#2odwMZu-bGT7f76zusr*f2w+|K>ubiCiMR&tvptpM+2u%Fum6`%rCfC^9nDlj4i z@*tltM)XX46e>Uk#-V_H9}3)9lP&0<4g?uRzEqg^zI56wHPO))TycF}?arq#hf1*pJ4fobHOo&P)dxA}k2!juY7fj?6~ zXWRXDgO|#)_2c!de#ok=8yxh@5#D|Rkl0bYgu7wC*aED{7DNTc9|4zvfeQRoffrzp B5oZ7Z literal 0 HcmV?d00001 diff --git a/bin/run_tests.R b/bin/run_tests.R new file mode 100755 index 00000000..59f987b3 --- /dev/null +++ b/bin/run_tests.R @@ -0,0 +1,29 @@ +#!/usr/bin/env Rscript +# run_tests -- run R tests for exercism.io +# the following were useful in writing this script: +# http://mazamascience.com/WorkingWithData/?p=888 for writing command line scripts +# http://www.johnmyleswhite.com/notebook/2010/08/17/unit-testing-in-r-the-bare-minimum/ for using RUnit + + +# function to determine if a package is installed +# will install it if necessary and load it +# otherwise stops the script with an error message +# source: http://stackoverflow.com/q/9341635 +install.if.necessary <- function(package.name) { + if ( !require(package.name, character.only=TRUE) ) { + install.packages(package.name, repos="http://cran.cnr.Berkeley.edu/") + if ( !require(package.name, character.only=TRUE) ) stop( paste( package.name, " not found") ) + } +} + +# make sure RUnit is installed and loaded +install.if.necessary("RUnit") + +# define a test suite; looks for files named "^.*_test.R" in current directory +test.suite <- defineTestSuite("exercism", dirs = getwd(), testFileRegex = "^.*_test\\.R" ) + +# run the tests +test.result <- runTestSuite(test.suite) + +# output the result +printTextProtocol(test.result) \ No newline at end of file diff --git a/bin/run_tests.bat b/bin/run_tests.bat new file mode 100644 index 00000000..6327f21a --- /dev/null +++ b/bin/run_tests.bat @@ -0,0 +1,12 @@ +@echo OFF + +REM The location of the registry key for the current version of R +set R_PATH_KEY=HKLM\Software\R-core\R +set R_PATH_VAL=InstallPath + +REM Get the path where R is installed +set R_PATH= +for /f "tokens=2,*" %%a in ('reg query %R_PATH_KEY% /v %R_PATH_VAL% ^| findstr %R_PATH_VAL%') do (set R_PATH=%%b) + +REM Run run_tests.R +Rscript "%R_PATH%"\bin\run_tests.R \ No newline at end of file diff --git a/config.json b/config.json index ef79bff9..2f30198a 100644 --- a/config.json +++ b/config.json @@ -1,10 +1,10 @@ { "slug": "r", "language": "R", - "repository": "https://github.com/exercism/xr", - "active": false, + "repository": "https://github.com/morphatic/xr", + "active": true, "problems": [ - + "hello-world" ], "deprecated": [ diff --git a/hello-world/example.R b/hello-world/example.R new file mode 100644 index 00000000..eddc2723 --- /dev/null +++ b/hello-world/example.R @@ -0,0 +1,3 @@ +say.hello <- function() { + return("Hello, World!") +} \ No newline at end of file diff --git a/hello-world/hello-world_test.R b/hello-world/hello-world_test.R new file mode 100644 index 00000000..736509ec --- /dev/null +++ b/hello-world/hello-world_test.R @@ -0,0 +1,14 @@ +test.hello.world <- function() { + + # default filename is example.R + filename <- "example.R" + + # check for hello-world.R + if (file.exists("hello-world.R")) filename <- "hello-world.R" + + # load the code to be tested + source(filename) + + # test the output + checkEquals(say.hello(), "Hello, World!") +} \ No newline at end of file From 0e54f068121bc7d30d9b242ecd1b34bad4c6ba6a Mon Sep 17 00:00:00 2001 From: Morgan Benton Date: Sun, 11 Jan 2015 00:05:05 -0500 Subject: [PATCH 2/6] added .gitignore and removed .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 2 ++ config.json | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) delete mode 100644 .DS_Store create mode 100644 .gitignore diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 8b6339a56b4c4cb76313a3df62979b8da67845a8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~JqiLr422W55Nx)zoW=uqgF*BJUO;pa1kpn5=jgutG_KaN$O|OjB(q_6U$L_h z5#2odwMZu-bGT7f76zusr*f2w+|K>ubiCiMR&tvptpM+2u%Fum6`%rCfC^9nDlj4i z@*tltM)XX46e>Uk#-V_H9}3)9lP&0<4g?uRzEqg^zI56wHPO))TycF}?arq#hf1*pJ4fobHOo&P)dxA}k2!juY7fj?6~ zXWRXDgO|#)_2c!de#ok=8yxh@5#D|Rkl0bYgu7wC*aED{7DNTc9|4zvfeQRoffrzp B5oZ7Z diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d4eb940a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +tmp diff --git a/config.json b/config.json index 2f30198a..c4770570 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,7 @@ { "slug": "r", "language": "R", - "repository": "https://github.com/morphatic/xr", + "repository": "https://github.com/exercism/xr", "active": true, "problems": [ "hello-world" From 906d1eec870b3043eb6f76b76b0d54b5649e5821 Mon Sep 17 00:00:00 2001 From: Morgan Benton Date: Mon, 26 Jan 2015 11:43:46 -0500 Subject: [PATCH 3/6] added hello-variables --- config.json | 6 ++---- hello-variables/example.R | 3 +++ hello-variables/hello-variables_test.R | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 hello-variables/example.R create mode 100644 hello-variables/hello-variables_test.R diff --git a/config.json b/config.json index c4770570..bd88a70e 100644 --- a/config.json +++ b/config.json @@ -4,15 +4,13 @@ "repository": "https://github.com/exercism/xr", "active": true, "problems": [ - "hello-world" + "hello-world", + "hello-variables" ], "deprecated": [ - ], "ignored": [ - ], "foregone": [ - ] } diff --git a/hello-variables/example.R b/hello-variables/example.R new file mode 100644 index 00000000..b3bb3145 --- /dev/null +++ b/hello-variables/example.R @@ -0,0 +1,3 @@ +say.hello.to <- function(name) { + return(paste("Hello, ", name, "!", sep="")) +} \ No newline at end of file diff --git a/hello-variables/hello-variables_test.R b/hello-variables/hello-variables_test.R new file mode 100644 index 00000000..22742a9a --- /dev/null +++ b/hello-variables/hello-variables_test.R @@ -0,0 +1,14 @@ +test.hello.variables <- function() { + + # default filename is example.R + filename <- "example.R" + + # check for hello-world.R + if (file.exists("hello-variables.R")) filename <- "hello-world.R" + + # load the code to be tested + source(filename) + + # test the output + checkEquals(say.hello.to("Bob"), "Hello, Bob!") +} \ No newline at end of file From 3a9d01665eeb7b58876142db701b14f04fa322a8 Mon Sep 17 00:00:00 2001 From: Morgan Benton Date: Mon, 26 Jan 2015 15:11:30 -0500 Subject: [PATCH 4/6] fixed typos in config.json --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index bd88a70e..c97972b6 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,7 @@ { "slug": "r", "language": "R", - "repository": "https://github.com/exercism/xr", + "repository": "https://github.com/morphatic/xr", "active": true, "problems": [ "hello-world", From 1490b4d23c403bca341622245a7ff081ab3166e8 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Feb 2015 10:53:18 -0500 Subject: [PATCH 5/6] fixed file reference in test spec --- hello-variables/hello-variables_test.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hello-variables/hello-variables_test.R b/hello-variables/hello-variables_test.R index 22742a9a..15b2f4ee 100644 --- a/hello-variables/hello-variables_test.R +++ b/hello-variables/hello-variables_test.R @@ -4,7 +4,7 @@ test.hello.variables <- function() { filename <- "example.R" # check for hello-world.R - if (file.exists("hello-variables.R")) filename <- "hello-world.R" + if (file.exists("hello-variables.R")) filename <- "hello-variables.R" # load the code to be tested source(filename) From ce3783e32aee14a293c8691d3887a0e4d5e04d81 Mon Sep 17 00:00:00 2001 From: Morgan Benton Date: Sun, 1 Mar 2015 16:26:43 -0500 Subject: [PATCH 6/6] added operate --- config.json | 3 +- operate/example.R | 22 +++++++++ operate/operate_test.R | 105 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 operate/example.R create mode 100644 operate/operate_test.R diff --git a/config.json b/config.json index c97972b6..36a75bd0 100644 --- a/config.json +++ b/config.json @@ -5,7 +5,8 @@ "active": true, "problems": [ "hello-world", - "hello-variables" + "hello-variables", + "operate" ], "deprecated": [ ], diff --git a/operate/example.R b/operate/example.R new file mode 100644 index 00000000..0d5dff3d --- /dev/null +++ b/operate/example.R @@ -0,0 +1,22 @@ +# Arithmetic Operators +add <- function( a, b ) { return( a + b ) } +subtract <- function( a, b ) { return( a - b ) } +multiply <- function( a, b ) { return( a * b ) } +divide <- function( a, b ) { return( a / b ) } +remainder <- function( a, b ) { return( a %% b ) } + +# Comparison Operators +equals <- function( a, b ) { return( a == b ) } +isIdentical <- function( a, b ) { return( identical( a, b ) ) } +notEquals <- function( a, b ) { return( a != b ) } +notIdentical <- function( a, b ) { return( ! identical( a, b ) ) } +lessThan <- function( a, b ) { return( a < b ) } +lessOrEqual <- function( a, b ) { return( a <= b ) } +greaterThan <- function( a, b ) { return( a > b ) } +greaterOrEqual <- function( a, b ) { return( a >= b ) } + +# Logical Operators +logicalAnd <- function( a, b ) { return( a & b ) } +logicalOr <- function( a, b ) { return( a | b ) } +logicalXor <- function( a, b ) { return( ( a & !b ) | ( !a & b ) ) } +logicalNot <- function( a ) { return( ! a ) } diff --git a/operate/operate_test.R b/operate/operate_test.R new file mode 100644 index 00000000..cb53396e --- /dev/null +++ b/operate/operate_test.R @@ -0,0 +1,105 @@ +test.hello.world <- function() { + + # default filename is example.R + filename <- "example.R" + + # check for hello-world.R + if (file.exists("operate.R")) filename <- "operate.R" + + # load the code to be tested + source(filename) + + # test Arithmetic Operators + checkEquals( add( 2, 2 ), 4 ) + checkEquals( add( 7, 3 ), 10 ) + checkEquals( add( 123, 456 ), 579 ) + + checkEquals( subtract( 2, 2 ), 0 ) + checkEquals( subtract( 7, 3 ), 4 ) + checkEquals( subtract( 123, 456 ), -333 ) + + checkEquals( multiply( 2, 2 ), 4 ) + checkEquals( multiply( 7, 3 ), 21 ) + checkEquals( multiply( 123, 456 ), 56088 ) + + checkEquals( divide( 2, 2 ), 1 ) + checkEquals( divide( 7, 3 ), 7/3 ) + checkEquals( divide( 123, 456 ), 123/456 ) + + checkEquals( remainder( 2, 2 ), 0 ) + checkEquals( remainder( 7, 3 ), 1 ) + checkEquals( remainder( 123, 456 ), 123 ) + + # test Comparison Operators + checkTrue( equals( 3 , 3 ) ) + checkTrue( equals( 3 , '3' ) ) + checkTrue( equals( 'Bob', 'Bob' ) ) + checkTrue( ! equals( 3 , 4 ) ) + checkTrue( ! equals( 3 , 'three' ) ) + + checkTrue( isIdentical( 3 , 3 ) ) + checkTrue( ! isIdentical( 3 , '3' ) ) + checkTrue( isIdentical( 'Bob', 'Bob' ) ) + checkTrue( ! isIdentical( 3 , 4 ) ) + checkTrue( ! isIdentical( 3 , 'three' ) ) + + checkTrue( ! notEquals( 3 , 3 ) ) + checkTrue( ! notEquals( 3 , '3' ) ) + checkTrue( ! notEquals( 'Bob', 'Bob' ) ) + checkTrue( notEquals( 3 , 4 ) ) + checkTrue( notEquals( 3 , 'three' ) ) + + checkTrue( ! notIdentical( 3 , 3 ) ) + checkTrue( notIdentical( 3 , '3' ) ) + checkTrue( ! notIdentical( 'Bob', 'Bob' ) ) + checkTrue( notIdentical( 3 , 4 ) ) + checkTrue( notIdentical( 3 , 'three' ) ) + + checkTrue( ! lessThan( 3 , 3 ) ) + checkTrue( lessThan( 3 , 4 ) ) + checkTrue( ! lessThan( 4 , 3 ) ) + checkTrue( ! lessThan( 'a', 'a' ) ) + checkTrue( lessThan( 'a', 'b' ) ) + checkTrue( ! lessThan( 'b', 'a' ) ) + + checkTrue( lessOrEqual( 3 , 3 ) ) + checkTrue( lessOrEqual( 3 , 4 ) ) + checkTrue( ! lessOrEqual( 4 , 3 ) ) + checkTrue( lessOrEqual( 'a', 'a' ) ) + checkTrue( lessOrEqual( 'a', 'b' ) ) + checkTrue( ! lessOrEqual( 'b', 'a' ) ) + + checkTrue( ! greaterThan( 3 , 3 ) ) + checkTrue( ! greaterThan( 3 , 4 ) ) + checkTrue( greaterThan( 4 , 3 ) ) + checkTrue( ! greaterThan( 'a', 'a' ) ) + checkTrue( ! greaterThan( 'a', 'b' ) ) + checkTrue( greaterThan( 'b', 'a' ) ) + + checkTrue( greaterOrEqual( 3 , 3 ) ) + checkTrue( ! greaterOrEqual( 3 , 4 ) ) + checkTrue( greaterOrEqual( 4 , 3 ) ) + checkTrue( greaterOrEqual( 'a', 'a' ) ) + checkTrue( ! greaterOrEqual( 'a', 'b' ) ) + checkTrue( greaterOrEqual( 'b', 'a' ) ) + + # test Logical Operators + checkTrue( logicalAnd( TRUE, TRUE ) ) + checkTrue( ! logicalAnd( TRUE, FALSE ) ) + checkTrue( ! logicalAnd( FALSE, TRUE ) ) + checkTrue( ! logicalAnd( FALSE, FALSE ) ) + + checkTrue( logicalOr( TRUE, TRUE ) ) + checkTrue( logicalOr( TRUE, FALSE ) ) + checkTrue( logicalOr( FALSE, TRUE ) ) + checkTrue( ! logicalOr( FALSE, FALSE ) ) + + checkTrue( ! logicalXor( TRUE, TRUE ) ) + checkTrue( logicalXor( TRUE, FALSE ) ) + checkTrue( logicalXor( FALSE, TRUE ) ) + checkTrue( ! logicalXor( FALSE, FALSE ) ) + + checkTrue( ! logicalNot( TRUE ) ) + checkTrue( logicalNot( FALSE ) ) + +} \ No newline at end of file