-
-
Notifications
You must be signed in to change notification settings - Fork 45
created first R problem and scripts to automate testing with RUnit #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d4cc70d
added hello-world; updated config.json; created run_tests scripts
morphatic 0e54f06
added .gitignore and removed .DS_Store
morphatic 906d1ee
added hello-variables
morphatic 3a9d016
fixed typos in config.json
morphatic 1490b4d
fixed file reference in test spec
ce3783e
added operate
morphatic ae0f388
Merge branch 'master' of https://github.com/morphatic/xr
morphatic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| .DS_Store | ||
| tmp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,17 @@ | ||
| { | ||
| "slug": "r", | ||
| "language": "R", | ||
| "repository": "https://github.com/exercism/xr", | ||
| "active": false, | ||
| "repository": "https://github.com/morphatic/xr", | ||
| "active": true, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't activate the track until there are at least 10 exercises. |
||
| "problems": [ | ||
|
|
||
| "hello-world", | ||
| "hello-variables", | ||
| "operate" | ||
| ], | ||
| "deprecated": [ | ||
|
|
||
| ], | ||
| "ignored": [ | ||
|
|
||
| ], | ||
| "foregone": [ | ||
|
|
||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| say.hello.to <- function(name) { | ||
| return(paste("Hello, ", name, "!", sep="")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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-variables.R" | ||
|
|
||
| # load the code to be tested | ||
| source(filename) | ||
|
|
||
| # test the output | ||
| checkEquals(say.hello.to("Bob"), "Hello, Bob!") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| say.hello <- function() { | ||
| return("Hello, World!") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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!") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 ) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 ) ) | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The repository needs to be
exercism/xr, as that is the canonical repo that the x-api uses to serve problems from.