Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
nutterb committed Dec 20, 2017
1 parent 2eac1dd commit 377633c
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
75 changes: 75 additions & 0 deletions tests/testthat/test-get_label.data.frame.R
@@ -0,0 +1,75 @@
context("get_label.data.frame")

test_that(
"cast an error if x is not a data frame",
{
expect_error(
get_label.data.frame(letters, a = "A")
)
}
)

test_that(
"Cast an error if any element in vars is not a column in x",
{
expect_error(
get_label(mtcars,
vars = "ABC")
)
}
)

test_that(
"Cast an error if any element in vars is not an atomic vector",
{
A <- data.frame(abc = rep(NA, 3))
A[[1]][1] <- list(letters)
A[[1]][2] <- list(LETTERS)
A[[1]][3] <- list(months)
expect_error(
get_label(A,
abc = "lists")
)
}
)

test_that(
"get_label works for data frames with no labels assigned",
{
expect_equal(get_label(mtcars),
names(mtcars))
}
)

test_that(
"get_label works for data frames with no labels assigned and vars != NULL",
{
expect_equal(get_label(mtcars, vars = c("mpg", "gear", "am")),
c("mpg", "gear", "am"))
}
)

test_that(
"get_label works for data frames with labels and vars = NULL",
{
A <- set_label(mtcars,
mpg = "miles per gallon",
gear = "gears",
am = "Automatic")
expect_equal(get_label(A),
c("miles per gallon", "cyl", "disp", "hp", "drat", "wt", "qsec",
"vs", "Automatic", "gears", "carb"))
}
)

test_that(
"get_label works for data frames with labels and vars != NULL",
{
A <- set_label(mtcars,
mpg = "miles per gallon",
gear = "gears",
am = "Automatic")
expect_equal(get_label(A, vars = c("mpg", "gear", "am", "hp")),
c("miles per gallon", "gears", "Automatic", "hp"))
}
)
12 changes: 12 additions & 0 deletions tests/testthat/test-print.labelled.R
@@ -0,0 +1,12 @@
context("print.labelled")

test_that(
"print labelled vector",
{
a <- set_label(1:10, "integers")
expect_output(
print(a),
"integers"
)
}
)
52 changes: 52 additions & 0 deletions tests/testthat/test-set_label.data.frame.R
@@ -0,0 +1,52 @@
context("set_label.data.frame")

test_that(
"cast an error if x is not a data frame",
{
expect_error(
set_label.data.frame(letters, a = "A")
)
}
)

test_that(
"Cast an error if any element in vars is not a column in x",
{
expect_error(
set_label(mtcars,
abc = "ABC")
)
}
)

test_that(
"Cast an error if any element in vars is not an atomic vector",
{
A <- data.frame(abc = rep(NA, 3))
A[[1]][1] <- list(letters)
A[[1]][2] <- list(LETTERS)
A[[1]][3] <- list(months)
expect_error(
set_label(A,
abc = "lists")
)
}
)

test_that(
"set_label works for data frames",
{
expect_silent(set_label(mtcars,
am = "Automatic",
mpg = "Miles per gallon"))
}
)

test_that(
"set_label casts and error when given an unnamed vector",
{
expect_error(
set_label(mtcars, "")
)
}
)

0 comments on commit 377633c

Please sign in to comment.