Skip to content

Commit 3018f6a

Browse files
committed
tests
1 parent c540b64 commit 3018f6a

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

tests/create_testing_df.R

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#' @title Data frame for tests
2+
#'
3+
#' @description Produces data frame to test stuff
4+
#'
5+
#' @param k rows
6+
#' @param distmean findable thing
7+
#' @param distsd lalala
8+
#'
9+
#' @return df for testing
10+
#'
11+
#' @examples
12+
#'
13+
#' @export create.testing.df
14+
15+
16+
create.testing.df <- function(k = 100, distmean = 150, distsd = 25) {
17+
test_df <- as.data.frame(matrix(nrow = k, ncol = 4))
18+
colnames(test_df) <- c("id", "variable", "min", "max")
19+
vars <- c("A", "B", "C")
20+
test_df_two <- test_df
21+
test_df$variable <- rep(vars, times = ceiling(k/length(vars)))[1:k]
22+
test_df$min <- round(runif(100, min = -699, max = 699), digits = 0)
23+
test_df$max <- test_df$min + (round(runif(100, min = 1, max = 299), digits = 0))
24+
25+
26+
test_df_two$min <- round(rnorm(k, mean = distmean, sd = distsd), digits = 0)
27+
test_df_two$max <- test_df_two$min + round(rnorm(k, mean = 35, sd = 9), digits = 0)
28+
test_df_two$variable <- "D"
29+
30+
test_df <- rbind(test_df, test_df_two)
31+
rm(test_df_two)
32+
test_df <- test_df[sample(nrow(test_df)),]
33+
34+
test_df$id <- paste("ID_", 1:nrow(test_df), sep ="")
35+
return(test_df)
36+
}

tests/testthat/test-datplot_utility.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,21 @@ testmat <- as.data.frame(matrix(c(1,2,3,4,6,6,8,8,0,0,50,-200,5,-200,50,5), byro
1616
test_that("switch.dating returns values correctly", {
1717
expect_equal(switch.dating(as.data.frame(testmat), DAT_err), corrmat)
1818
})
19+
20+
source(file = "../create_testing_df.R")
21+
testdf <- create.testing.df()
22+
23+
fristlast <- matrix(nrow = nrow(testdf), ncol = 2)
24+
for (r in 1:nrow(testdf)) {
25+
seq <- get.step.sequence(datmin = testdf[r,3],
26+
datmax = testdf[r,4],
27+
stepsize = 25)
28+
fristlast[r,1] <- seq[1]
29+
fristlast[r,2] <- seq[length(seq)]
30+
}
31+
32+
library(testthat)
33+
test_that("sequence returns first and last values", {
34+
expect_equal(fristlast[,1], testdf[,3])
35+
expect_equal(fristlast[,2], testdf[,4])
36+
})

tests/testthat/test-datsteps.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source(file = "../create_testing_df.R")
2+
testdf <- create.testing.df()
3+
4+
test_that("error for wrong value of stepsize", {
5+
expect_error(datsteps(testdf, stepsize = "test"))
6+
})

0 commit comments

Comments
 (0)