AMR/tests/testthat/test-classes.R

44 lines
1.5 KiB
R
Raw Normal View History

2018-03-27 17:43:42 +02:00
context("classes.R")
test_that("rsi works", {
expect_true(as.rsi("S") < as.rsi("I"))
expect_true(as.rsi("I") < as.rsi("R"))
expect_true(as.rsi("R") > as.rsi("S"))
expect_true(is.rsi(as.rsi("S")))
2018-04-02 16:05:09 +02:00
# print plots, should not raise errors
barplot(as.rsi(c("S", "I", "R")))
plot(as.rsi(c("S", "I", "R")))
print(as.rsi(c("S", "I", "R")))
2018-03-27 17:43:42 +02:00
expect_equal(suppressWarnings(as.logical(as.rsi("INVALID VALUE"))), NA)
2018-04-02 16:05:09 +02:00
2018-03-27 17:43:42 +02:00
expect_equal(summary(as.rsi(c("S", "R"))), c("Mode" = 'rsi',
"<NA>" = "0",
"Sum S" = "1",
"Sum IR" = "1",
2018-08-01 22:37:28 +02:00
"-Sum R" = "1",
"-Sum I" = "0"))
2018-03-27 17:43:42 +02:00
})
test_that("mic works", {
expect_true(as.mic(8) == as.mic("8"))
expect_true(as.mic("1") > as.mic("<=0.0625"))
expect_true(as.mic("1") < as.mic(">=32"))
expect_true(is.mic(as.mic(8)))
2018-04-02 16:05:09 +02:00
2018-03-27 17:43:42 +02:00
expect_equal(as.double(as.mic(">=32")), 32)
expect_equal(as.integer(as.mic(">=32")), 32)
expect_equal(suppressWarnings(as.logical(as.mic("INVALID VALUE"))), NA)
2018-04-02 16:05:09 +02:00
# print plots, should not raise errors
barplot(as.mic(c(1, 2, 4, 8)))
plot(as.mic(c(1, 2, 4, 8)))
print(as.mic(c(1, 2, 4, 8)))
2018-03-27 17:43:42 +02:00
expect_equal(summary(as.mic(c(2, 8))), c("Mode" = 'mic',
"<NA>" = "0",
"Min." = "2",
"Max." = "8"))
})