-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestCases.R
More file actions
33 lines (24 loc) · 842 Bytes
/
testCases.R
File metadata and controls
33 lines (24 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# testCases.R
library(RUnit)
# Load source files
source("rSquared.R")
source("mase.R")
# Test the rSquared function and that it correctly tests the accuracy of a predicted vector of values.
rSquared.test <- function() {
actualValues <- c(1, 2, 3)
predictedValues <- c(1.5, 2, 2.5)
result <- 1 - (
((1 - 1.5)^2 + (2 - 2)^2 + (3 - 2.5)^2) /
((1 - 2)^2 + (2 - 2)^2 + (3 - 2)^2)
)
checkEquals(rSquared(actualValues = actualValues, predictedValues = predictedValues), result)
}
mase.test <- function() {
actualValues <- c(1, 2, 3)
predictedValues <- c(1.5, 2, 2.5)
result <- (abs(1 - 1.5) + abs(2 - 2) + abs(3 - 2.5)) /
((3 / (3-1)) * (abs(3 - 2) + abs(2 - 1)))
checkEquals(mase(actualValues = actualValues, predictedValues = predictedValues), result)
}
# Print test outputs
print(rSquared.test())