Skip to content

Commit

Permalink
added custom tests to avoid issue with omnitest
Browse files Browse the repository at this point in the history
  • Loading branch information
seankross committed Apr 16, 2015
1 parent 7ae578d commit 5e7f439
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 8 deletions.
38 changes: 38 additions & 0 deletions R_Programming/Functions/customTests.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,42 @@ test_func7 <- function() {
ok <- all(t1, t2)
}, silent = TRUE)
exists('ok') && isTRUE(ok)
}

test_eval1 <- function(){
try({
e <- get("e", parent.frame())
expr <- e$expr
t1 <- identical(expr[[3]], 6)
expr[[3]] <- 7
t2 <- identical(eval(expr), 8)
ok <- all(t1, t2)
}, silent = TRUE)
exists('ok') && isTRUE(ok)
}

test_eval2 <- function(){
try({
e <- get("e", parent.frame())
expr <- e$expr
t1 <- identical(expr[[3]], quote(c(8, 4, 0)))
t2 <- identical(expr[[1]], quote(evaluate))
expr[[3]] <- c(5, 6)
t3 <- identical(eval(expr), 5)
ok <- all(t1, t2, t3)
}, silent = TRUE)
exists('ok') && isTRUE(ok)
}

test_eval3 <- function(){
try({
e <- get("e", parent.frame())
expr <- e$expr
t1 <- identical(expr[[3]], quote(c(8, 4, 0)))
t2 <- identical(expr[[1]], quote(evaluate))
expr[[3]] <- c(5, 6)
t3 <- identical(eval(expr), 6)
ok <- all(t1, t2, t3)
}, silent = TRUE)
exists('ok') && isTRUE(ok)
}
6 changes: 3 additions & 3 deletions R_Programming/Functions/lesson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
Output: "Type the following command and then we'll discuss how it works:
evaluate(function(x){x+1}, 6)"
CorrectAnswer: evaluate(function(x){x+1}, 6)
AnswerTests: omnitest(correctExpr='evaluate(function(x){x+1}, 6)')
AnswerTests: test_eval1()
Hint: "Just type the command evaluate(function(x){x+1}, 6)"

- Class: text
Expand All @@ -232,7 +232,7 @@
first element of the vector c(8, 4, 0). Your anonymous function should only
take one argument which should be a variable `x`."
CorrectAnswer: evaluate(function(x){x[1]}, c(8, 4, 0))
AnswerTests: omnitest(correctExpr='evaluate(function(x){x[1]}, c(8, 4, 0))')
AnswerTests: test_eval2()
Hint: "You may need to recall how to index vector elements. Remember that your
anonymous function should only have one argument, and that argument should
be named `x`."
Expand All @@ -242,7 +242,7 @@
last element of the vector c(8, 4, 0). Your anonymous function should only
take one argument which should be a variable `x`."
CorrectAnswer: evaluate(function(x){x[length(x)]}, c(8, 4, 0))
AnswerTests: omnitest(correctExpr='evaluate(function(x){x[length(x)]}, c(8, 4, 0))')
AnswerTests: test_eval3()
Hint: "You may need to recall how to index vector elements. Remember that your
anonymous function should only have one argument, and that argument should
be named `x`. Using the length() function in your anonymous function may
Expand Down
38 changes: 38 additions & 0 deletions R_Programming_Alt/Functions/customTests.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,42 @@ test_func7 <- function() {
ok <- all(t1, t2)
}, silent = TRUE)
exists('ok') && isTRUE(ok)
}

test_eval1 <- function(){
try({
e <- get("e", parent.frame())
expr <- e$expr
t1 <- identical(expr[[3]], 6)
expr[[3]] <- 7
t2 <- identical(eval(expr), 8)
ok <- all(t1, t2)
}, silent = TRUE)
exists('ok') && isTRUE(ok)
}

test_eval2 <- function(){
try({
e <- get("e", parent.frame())
expr <- e$expr
t1 <- identical(expr[[3]], quote(c(8, 4, 0)))
t2 <- identical(expr[[1]], quote(evaluate))
expr[[3]] <- c(5, 6)
t3 <- identical(eval(expr), 5)
ok <- all(t1, t2, t3)
}, silent = TRUE)
exists('ok') && isTRUE(ok)
}

test_eval3 <- function(){
try({
e <- get("e", parent.frame())
expr <- e$expr
t1 <- identical(expr[[3]], quote(c(8, 4, 0)))
t2 <- identical(expr[[1]], quote(evaluate))
expr[[3]] <- c(5, 6)
t3 <- identical(eval(expr), 6)
ok <- all(t1, t2, t3)
}, silent = TRUE)
exists('ok') && isTRUE(ok)
}
10 changes: 5 additions & 5 deletions R_Programming_Alt/Functions/lesson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@

- Class: text
Output: "Next, let's try writing a function with default arguments. You can set
default values for a function's argumets, and this can be useful if you think
someone who uses your funciton will set a certain argument to the same value
default values for a function's arguments, and this can be useful if you think
someone who uses your function will set a certain argument to the same value
most of the time."

- Class: script
Expand Down Expand Up @@ -219,7 +219,7 @@
Output: "Type the following command and then we'll discuss how it works:
evaluate(function(x){x+1}, 6)"
CorrectAnswer: evaluate(function(x){x+1}, 6)
AnswerTests: omnitest(correctExpr='evaluate(function(x){x+1}, 6)')
AnswerTests: test_eval1()
Hint: "Just type the command evaluate(function(x){x+1}, 6)"

- Class: text
Expand All @@ -232,7 +232,7 @@
first element of the vector c(8, 4, 0). Your anonymous function should only
take one argument which should be a variable `x`."
CorrectAnswer: evaluate(function(x){x[1]}, c(8, 4, 0))
AnswerTests: omnitest(correctExpr='evaluate(function(x){x[1]}, c(8, 4, 0))')
AnswerTests: test_eval2()
Hint: "You may need to recall how to index vector elements. Remember that your
anonymous function should only have one argument, and that argument should
be named `x`."
Expand All @@ -242,7 +242,7 @@
last element of the vector c(8, 4, 0). Your anonymous function should only
take one argument which should be a variable `x`."
CorrectAnswer: evaluate(function(x){x[length(x)]}, c(8, 4, 0))
AnswerTests: omnitest(correctExpr='evaluate(function(x){x[length(x)]}, c(8, 4, 0))')
AnswerTests: test_eval3()
Hint: "You may need to recall how to index vector elements. Remember that your
anonymous function should only have one argument, and that argument should
be named `x`. Using the length() function in your anonymous function may
Expand Down

0 comments on commit 5e7f439

Please sign in to comment.