Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void testFilesInRDirectoryAreStudentFiles() throws IOException {

TestUtils.collectPaths(projectPath, studentFiles, studentFilePolicy);

assertEquals(1, studentFiles.size());
assertEquals(2, studentFiles.size());
assertTrue(studentFiles.contains("R" + File.separator + "arithmetics.R"));
}

Expand All @@ -43,7 +43,7 @@ public void testFilesInTestthatDirectoryAreNotStudentFiles() throws IOException

TestUtils.collectPaths(projectPath, studentFiles, studentFilePolicy);

assertEquals(1, studentFiles.size());
assertEquals(2, studentFiles.size());
assertFalse(studentFiles.contains(
"test" + File.separatorChar + "testthat"
+ File.separatorChar + "testArithmetics.R"));
Expand All @@ -55,7 +55,7 @@ public void testResultRInTmcDirectoryIsNotAStudentFile() throws IOException {

TestUtils.collectPaths(projectPath, studentFiles, studentFilePolicy);

assertEquals(1, studentFiles.size());
assertEquals(2, studentFiles.size());
assertFalse(studentFiles.contains("tmc" + File.separatorChar + "result.R"));
}
}
}
73 changes: 73 additions & 0 deletions tmc-langs-r/src/test/resources/passing/R/week1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
##These exercises are taken from the course "Data-analyysi R-ohjelmistolla"
#(https://wiki.helsinki.fi/pages/viewpage.action?pageId=135074576).
##

##Exercise 1

a1 <- 4 + 10
b1 <- 5*a1
c1 <- b1^3
d1 <- exp(b1)
e1 <- d1^(1/10)
f1 <- sin(c1)
res1 <- (b1 + c1 + e1 + f1)

##Exercise 2

a2 <- 51%%7

##Excercise 3
a3 <- 51%%7 + 51%/%7

##Excercise 4
v4_1 <- c(20, 5, -2, 3, 47)
v4_2 <- seq(0, 100, 5)
v4_3 <- c(v4_1, v4_2)
v4_4 <- v4_3[(v4_3 > 3) & (v4_3 < 50)]
v4_5 <- v4_4[(v4_4 %% 10) == 0]

##Exercise 5
v5_1 <- rep(0, 1, 50)
v5_1[c(F, T)] <- 2

sum5_1 <- sum(v5_1)
v5_1
v5_2 <- v5_1
v5_2[c(T, F)] <- 1.2
sum5_2 <- sum(v5_2)

##Excerice 6

A <- matrix(c(3, 5, 6, 1/2, sqrt(5), 16, 0, 2, 0),nrow = 3, ncol = 3, byrow = TRUE)


##Excercise 7
B <- c(1, 1, 0)%*% solve(A)

##Excercise 8
I_3 <- diag(c(1, 1, 1))
A_8 <- A %*%I_3

##Excercise 9
is_eq_matrix <- t(A) == A
is_eq_matrix <- F

##Excercise 10
C_10 <- matrix(c(runif(20, min = 1, max=20)), ncol=4)
v10_1 <- C_10[C_10 < 5]
number10 <- length(v10_1)

D_10 <- C_10
D_10[D_10 < 5] <- 10

E_10 <- D_10
E_10 <- D_10[c(T, T, T, T, F),c(F,T,T, T)]


##Excercise 11
C_11 <- matrix(1:100, ncol=2)
C_11[c(F, T)] <- NA

##Excercise 12
C_12 <- C_11
C_12[is.na(C_12)] <- 0
79 changes: 79 additions & 0 deletions tmc-langs-r/src/test/resources/passing/test/testthat/testWeek1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
library('testthat')
source('../../R/week1.R')

points_for_all_tests(c("r4"))

help_A <- matrix(c(3, 5, 6, 1/2, sqrt(5), 16, 0, 2, 0),nrow = 3, ncol = 3, byrow = TRUE)

test("Exercise 1 is correct", c("r4.1"), {
expect_equal(a1, 14)
expect_equal(b1, 70)
expect_equal(c1, 343000)
expect_true(abs(e1-1096.63) < 0.1)
expect_true(abs(f1 - 0.7920019) < 0.1)
expect_true(abs(res1 - 344167.4) < 0.1)
})

test("Exercise 2 is correct", c("r4.2"), {
expect_equal(a2, 2)
})

test("Exercise 3 is correct", c("r4.3", "r4.4"), {
expect_equal(a3, 9)
})

test("Exercise 4 is correct", c("r4.5"), {
expect_equal(v4_1, c(20, 5, -2, 3, 47))
expect_equal(v4_2, c(0:20)*5)
expect_equal(v4_3, c(c(20, 5, -2, 3, 47), seq(0, 100, 5)))
expect_equal(v4_4, c(20, 5, 47, 5, 10, 15, 20, 25, 30, 35, 40, 45))
expect_equal(v4_5, c(20, 10, 20, 30, 40))
})

test("Exercise 5 is correct", c("r4.6"), {
t1 <- rep(0, 1, 50)
t1[c(F, T)] <- 2
expect_equal(v5_1, t1)
expect_equal(sum5_1, 50)
expect_equal(sum5_2, 80)
})

test("Exercise 6 is correct", c("r4.7"), {
expect_equal(A, matrix(c(3, 5, 6, 1/2, sqrt(5), 16, 0, 2, 0),nrow = 3, ncol = 3, byrow = TRUE))
})

test("Exercise 7 is correct", c("r4.8"), {
expect_equal(A, help_A)
})

test("Exercise 8 is correct", c("r4.9"), {
expect_equal(B, c(1, 1, 0)%*%solve(help_A))
})

test("Exercise 9 is correct", c("r4.10"), {
expect_equal(I_3, diag(c(1, 1, 1)))
expect_equal(A_8, help_A)
})

test("Exercise 10 is correct", c("r4.11"), {
expect_false(is_eq_matrix)
})

test("Exercise 11 is correct", c("r4.12"), {
expect_true(number10 < 10)

expect_true(dim(E_10)[1] == 4)
expect_true(dim(E_10)[2] == 3)
})

test("Exercise 12 is correct", c("r4.13"), {
M <- matrix(1:100, ncol=2)
M[c(F, T)] <- NA
expect_equal(C_11, M)
})

test("Exercise 13 is correct", c("r4.14"), {
M <- matrix(1:100, ncol=2)
M[c(F, T)] <- 0
expect_equal(C_12, M)
})