Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General Issue: Increase test coverage for functions in assertions.R #94

Closed
bms63 opened this issue Sep 22, 2022 · 4 comments · Fixed by #150
Closed

General Issue: Increase test coverage for functions in assertions.R #94

bms63 opened this issue Sep 22, 2022 · 4 comments · Fixed by #150
Assignees
Labels
good first issue Good for newcomers

Comments

@bms63
Copy link
Collaborator

bms63 commented Sep 22, 2022

Background Information

We need to increase test coverage for our functions. The below screenshot has the function and gap in test coverage that we need to write additional unit tests

Most of these gaps surround the messages a user receives when something goes awry.

image

Definition of Done

Unit tests are written that increase the coverage of the assertions.R file

@bms63
Copy link
Collaborator Author

bms63 commented Sep 22, 2022

You can get this report by running devtools::test_coverage()

@AniaGolab AniaGolab self-assigned this Oct 20, 2022
@AniaGolab
Copy link
Contributor

AniaGolab commented Oct 27, 2022

Hi @bms63 and @thomas-neitmann, while adding some unit tests I came across assert_character_scalar function. Just wanted to let you know that it appears that the values parameter can only take a vector of lower case letters. It throws an error if values are c("Test") or c("TEST") but it works for c("test"). Is this the desired behavior? If so, should we maybe add a note to the function description that the values should be lowercase? thank you!

@bundfussr
Copy link
Collaborator

@AniaGolab , good catch!
I assume the issue occurs when using case_sensitive = FALSE.
I think we should change

  if (!case_sensitive) {
    arg <- tolower(arg)
  }

to

  if (!case_sensitive) {
    arg <- tolower(arg)
    if (!is.null(values) {
      values <- tolower(values)
    }
  }

However, I would recommend specifying values as lower case values if case_sensitive = FALSE is used because arg is changed to lower case. So whenever you have conditions on the argument in the function code, lower case values must be used.
For me

  mode <- assert_character_scalar(mode, values = c("first", "last"), case_sensitive = FALSE)
  if (mode == "first") {

reads better than

  mode <- assert_character_scalar(mode, values = c("FIRST", "LAST"), case_sensitive = FALSE)
  if (mode == "first") {

@AniaGolab
Copy link
Contributor

Thank you @bundfussr, that indeed makes sense! I will apply those changes in my commit.

@AniaGolab AniaGolab linked a pull request Oct 28, 2022 that will close this issue
14 tasks
@bms63 bms63 closed this as completed in 34aaa81 Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Development

Successfully merging a pull request may close this issue.

3 participants