## Not run:
# # Example 1: if else
# vec <- c("a", "b", "c")
# if("a" %in% vec) {
# print("a in here")
# } else if(any("b" > vec)) {
# cat("b not smallest")
# } else {
# str(vec)
# }
#
# # SCT option 1
# test_if_else(1,
# if_cond_test = {
# test_student_typed("%in%")
# test_student_typed("vec")
# },
# if_expr_test = test_function("print")
# else_expr_test = test_if_else(1,
# if_cond_test = test_student_typed(">"),
# if_expr_test = test_function("cat"),
# else_expr_test = test_function("str")))
#
# # SCT option 2
# ifelse <- check_if_else(1)
# ifelse %>% check_cond() %>% check_code("%in%")
# ifelse %>% check_cond() %>% check_code("vec")
# ifelse %>% check_if() %>% check_function("print")
# nestedifelse <- ifelse %>% check_else() %>% check_if_else(1)
# nestedifelse %>% check_cond() %>% check_code(">")
# nestedifelse %>% check_if() %>% check_function("cat")
# nestedifelse %>% check_else() %>% check_function("str")
#
# # Example 2: while loop
# while(x < 18) {
# x <- x + 5
# print(x)
# }
#
# # SCT Option 1
# test_while_loop(1,
# cond_test = test_student_typed(c("< 18", "18 >")),
# expr_test = {
# test_student_typed(c("x + 5", "5 + x"))
# # no actual value matching possible!!
# test_function("print", args = 'x', eval = FALSE)
# })
#
# # SCT Option 2
# w <- check_while(1)
# w %>% check_cond() %>% check_code(c("< 18", "18 >"))
# w %>% check_body() %>% check_code(c("x + 5", "5 + x"))
# w %>% check_body() %>% check_function("print") %>% test_arg("x")
#
# # Example 3: for loop
# for(i in 1:5) {
# print("hurray!")
# }
#
# # SCT Option 1
# test_for_loop(1,
# cond_test = {
# test_student_typed("in")
# test_student_typed("1")
# test_student_typed("5")
# },
# expr_test = test_function("print"), args = "x")
#
# # SCT Option 2
# f <- ex() %>% check_for(1)
# cond <- f %>% check_cond()
# cond %>% check_code("in")
# cond %>% check_code("1")
# cond %>% check_code("5")
# f %>% check_body() %>% check_function("print") %>% check_arg("x") %>% check_equal()
# ## End(Not run)
Run the code above in your browser using DataLab