-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolved Issue #46; updated and organized package dependencies (and r…
…emoved tibble::, added tidyr:: dependency); fixed various formatting/style/workflow errors in lookup*() functions; added warning to lookup_syn() for more than one substance; added tests.
- Loading branch information
1 parent
59b5c5c
commit f164c6e
Showing
8 changed files
with
158 additions
and
55 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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,30 +1,53 @@ | ||
### Test for single category match ### | ||
testOut_df <- data.frame( | ||
class = rep(c("cannabis"),each=5), | ||
category_match = rep(c("marijuana"), each= 5), | ||
class = rep("cannabis", each = 5), | ||
category_match = rep("marijuana", each = 5), | ||
synonym = c("420", "a-bomb", "acapulco gold", "acapulco red", "ace") | ||
) | ||
|
||
test_that("single category match works", { | ||
expect_equal(testOut_df, head(lookup_syn("draf weed"),5)) | ||
expect_equal( | ||
testOut_df, | ||
head(lookup_syn("draf weed"), 5) | ||
) | ||
}) | ||
|
||
|
||
### Test that Multiple Entries are Discarded ### | ||
test_that("Drug vector only uses first entry and throws warning", { | ||
expect_warning( | ||
lookup_syn(c("ritalin", "opium")), | ||
"Only the first element" | ||
) | ||
}) | ||
|
||
|
||
### Test Drug Category Search ### | ||
# This is the else if() part | ||
test_that("Drug category matches multiple times handled correctly", { | ||
expect_equal( | ||
data.frame( | ||
class = "stimulant", | ||
category_match = "ritalin", | ||
synonym = "kibbles and bits" | ||
), | ||
lookup_syn("ritalin") | ||
) | ||
}) | ||
|
||
|
||
### Test with multiple category matches ### | ||
testOut_df2 <- data.frame( | ||
category =c( | ||
"amphetamine" | ||
,"cocaine" | ||
,"crack" | ||
,"crack cocaine" | ||
,"khat" | ||
,"methamphetamine" | ||
,"methcathinone" | ||
,"methylphenidate" | ||
,"ritalin" | ||
,"synthetic cathinone" | ||
category = c( | ||
"amphetamine", "cocaine", "crack", "crack cocaine", "khat", | ||
"methamphetamine", "methcathinone", "methylphenidate", "ritalin", | ||
"synthetic cathinone" | ||
) | ||
) | ||
|
||
test_that("multiple category match works", { | ||
expect_equal(testOut_df2$category, lookup_syn("stimulant")$category) | ||
expect_equal( | ||
testOut_df2$category, | ||
lookup_syn("stimulant")$category | ||
) | ||
}) |
f164c6e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@labouz review please