Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
context("print.labelled") | ||
|
||
test_that( | ||
"print labelled vector", | ||
{ | ||
a <- set_label(1:10, "integers") | ||
expect_output( | ||
print(a), | ||
"integers" | ||
) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, "") | ||
) | ||
} | ||
) |