|
| 1 | +context("test boxplot2") |
| 2 | + |
| 3 | + |
| 4 | +df_ex <- replicate(4, runif(100)) |
| 5 | +df_ex2 <- data.frame(nam = rep(LETTERS[1:2], each = 50), val = df_ex[, 1L]) |
| 6 | +xy <- boxplot2(df_ex) |
| 7 | +xy2 <- boxplot2(df_ex, probs = c(.01, 0.25, .5, .75, .99), at = 2:5) |
| 8 | +xy3 <- boxplot2(val ~ nam, data = df_ex2) |
| 9 | +grDevices::graphics.off() |
| 10 | + |
| 11 | +test_that("expected errors", { |
| 12 | + expect_error(boxplot2(df_ex, add = TRUE)) |
| 13 | + expect_error(boxplot2(df_ex, probs = c(.01))) |
| 14 | + expect_error(boxplot2(df_ex, probs = c(.01, 0.25, .5, .75, 2))) |
| 15 | + expect_error(boxplot2(df_ex, probs = c(.01, 0.25, .5, .75, -2))) |
| 16 | +}) |
| 17 | + |
| 18 | + |
| 19 | +test_that("expected output", { |
| 20 | + expect_identical(xy$x, 1:4) |
| 21 | + expect_identical(xy2$x, 2:5) |
| 22 | + expect_identical(xy3$x, 1:2) |
| 23 | + expect_identical(row.names(xy2$y), c("1%", "25%", "50%", "75%", "99%")) |
| 24 | + expect_identical(row.names(xy2$y), c("1%", "25%", "50%", "75%", "99%")) |
| 25 | + expect_true( |
| 26 | + all( |
| 27 | + xy2$y[,1] == quantile(df_ex[,1], probs = c(.01, 0.25, .5, .75, .99)) |
| 28 | + ) |
| 29 | + ) |
| 30 | +}) |
| 31 | + |
| 32 | + |
| 33 | +# dfa <- data.frame(name = rep(LETTERS[1:4], 25), val = runif(100)) |
| 34 | +# boxplot2(val ~ name, data = dfa, add = TRUE, vc_cex = c(4, 40, 2)) |
0 commit comments