-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔥 Remove superfluous messages in tests (#296)
- Loading branch information
1 parent
0c55a38
commit f701d72
Showing
40 changed files
with
577 additions
and
566 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,151 +1,193 @@ | ||
source("./anagram.R") | ||
library(testthat) | ||
|
||
context("anagram") | ||
|
||
test_that("no matches", { | ||
subject <- "diaper" | ||
candidates <- c("hello", "world", "zombies", "pants") | ||
expect_equal(anagram(subject, candidates), | ||
c()) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c() | ||
) | ||
}) | ||
|
||
test_that("detects simple anagram", { | ||
subject <- "ant" | ||
candidates <- c("tan", "stand", "at") | ||
expect_equal(anagram(subject, candidates), | ||
c("tan")) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c("tan") | ||
) | ||
}) | ||
|
||
test_that("does not detect false positives", { | ||
subject <- "galea" | ||
candidates <- c("eagle") | ||
expect_equal(anagram(subject, candidates), | ||
c()) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c() | ||
) | ||
}) | ||
|
||
test_that("detects two anagrams", { | ||
subject <- "solemn" | ||
candidates <- c("lemons", "cherry", "melons") | ||
expect_equal(anagram(subject, candidates), | ||
c("lemons", "melons")) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c("lemons", "melons") | ||
) | ||
}) | ||
|
||
test_that("does not detect anagram subsets", { | ||
subject <- "good" | ||
candidates <- c("dog", "goody") | ||
expect_equal(anagram(subject, candidates), | ||
c()) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c() | ||
) | ||
}) | ||
|
||
test_that("detects anagram", { | ||
subject <- "listen" | ||
candidates <- c("enlists", "google", "inlets", "banana") | ||
expect_equal(anagram(subject, candidates), | ||
c("inlets")) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c("inlets") | ||
) | ||
}) | ||
|
||
test_that("detects three anagrams", { | ||
subject <- "allergy" | ||
candidates <- | ||
c("gallery", "ballerina", "regally", "clergy", "largely", "leading") | ||
expect_equal(anagram(subject, candidates), | ||
c("gallery", "regally", "largely")) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c("gallery", "regally", "largely") | ||
) | ||
}) | ||
|
||
test_that("detects multiple anagrams with different case", { | ||
subject <- "nose" | ||
candidates <- | ||
c("Eons", "ONES") | ||
expect_equal(anagram(subject, candidates), | ||
c("Eons", "ONES")) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c("Eons", "ONES") | ||
) | ||
}) | ||
|
||
test_that("does not detect identical words", { | ||
subject <- "corn" | ||
candidates <- c("corn", "dark", "Corn", "rank", "CORN", "cron", "park") | ||
expect_equal(anagram(subject, candidates), | ||
c("cron")) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c("cron") | ||
) | ||
}) | ||
|
||
test_that("does not detect non-anagrams with identical checksum", { | ||
subject <- "mass" | ||
candidates <- c("last") | ||
expect_equal(anagram(subject, candidates), | ||
c()) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c() | ||
) | ||
}) | ||
|
||
test_that("detects anagrams case-insensitively", { | ||
subject <- "Orchestra" | ||
candidates <- c("cashregister", "Carthorse", "radishes") | ||
expect_equal(anagram(subject, candidates), | ||
c("Carthorse")) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c("Carthorse") | ||
) | ||
}) | ||
|
||
test_that("detects anagrams using case-insensitive subject", { | ||
subject <- "Orchestra" | ||
candidates <- c("cashregister", "carthorse", "radishes") | ||
expect_equal(anagram(subject, candidates), | ||
c("carthorse")) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c("carthorse") | ||
) | ||
}) | ||
|
||
test_that("detects anagrams using case-insensitve possible matches", { | ||
subject <- "orchestra" | ||
candidates <- c("cashregister", "Carthorse", "radishes") | ||
expect_equal(anagram(subject, candidates), | ||
c("Carthorse")) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c("Carthorse") | ||
) | ||
}) | ||
|
||
test_that("does not detect a anagram if the original word is repeated", { | ||
subject <- "go" | ||
candidates <- c("go Go GO") | ||
expect_equal(anagram(subject, candidates), | ||
c()) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c() | ||
) | ||
}) | ||
|
||
test_that("anagrams must use all letters exactly once", { | ||
subject <- "tapper" | ||
candidates <- c("patter") | ||
expect_equal(anagram(subject, candidates), | ||
c()) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c() | ||
) | ||
}) | ||
|
||
test_that("eliminates anagrams with the same checksum", { | ||
subject <- "mass" | ||
candidates <- c("last") | ||
expect_equal(anagram(subject, candidates), | ||
c()) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c() | ||
) | ||
}) | ||
|
||
test_that("words are not anagrams of themselves", { | ||
subject <- "BANANA" | ||
candidates <- c("BANANA") | ||
expect_equal(anagram(subject, candidates), | ||
c()) | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c() | ||
) | ||
}) | ||
|
||
test_that( | ||
"not an anagram even if letter case is partially different", { | ||
subject <- "BANANA" | ||
candidates <- c("Banana") | ||
expect_equal(anagram(subject, candidates), | ||
c()) | ||
}) | ||
"not an anagram even if letter case is partially different", | ||
{ | ||
subject <- "BANANA" | ||
candidates <- c("Banana") | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c() | ||
) | ||
} | ||
) | ||
|
||
test_that( | ||
"not an anagram even if letter case is completely different", { | ||
subject <- "BANANA" | ||
candidates <- c("banana") | ||
expect_equal(anagram(subject, candidates), | ||
c()) | ||
}) | ||
"not an anagram even if letter case is completely different", | ||
{ | ||
subject <- "BANANA" | ||
candidates <- c("banana") | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c() | ||
) | ||
} | ||
) | ||
|
||
test_that( | ||
"words other than themselves can be anagrams", { | ||
subject <- "LISTEN" | ||
candidates <- c("LISTEN", "Silent") | ||
expect_equal(anagram(subject, candidates), | ||
c("Silent")) | ||
}) | ||
|
||
message("All tests passed for exercise: anagram") | ||
"words other than themselves can be anagrams", | ||
{ | ||
subject <- "LISTEN" | ||
candidates <- c("LISTEN", "Silent") | ||
expect_equal( | ||
anagram(subject, candidates), | ||
c("Silent") | ||
) | ||
} | ||
) |
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
Oops, something went wrong.