Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 14 additions & 63 deletions exercises/practice/anagram/test_anagram.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@ test_that("no matches", {
c())
})

test_that("detects simple anagram", {
subject <- "ant"
candidates <- c("tan", "stand", "at")
test_that("detects anagram", {
subject <- "listen"
candidates <- c("enlists", "google", "inlets", "banana")
expect_equal(anagram(subject, candidates),
c("tan"))
c("inlets"))
})

test_that("does not detect false positives", {
subject <- "galea"
candidates <- c("eagle")
test_that("detects multiple anagrams", {
subject <- "allergy"
candidates <-
c("gallery", "ballerina", "regally", "clergy", "largely", "leading")
expect_equal(anagram(subject, candidates),
c())
c("gallery", "regally", "largely"))
})

test_that("detects multiple anagrams", {
subject <- "master"
candidates <- c("stream", "pigeon", "maters")
test_that("character overlap is disregarded", {
subject <- "galea"
candidates <- c("eagle")
expect_equal(anagram(subject, candidates),
c("stream", "maters"))
c())
})

test_that("does not detect anagram subsets", {
Expand All @@ -38,21 +39,6 @@ test_that("does not detect anagram subsets", {
c())
})

test_that("detects anagram", {
subject <- "listen"
candidates <- c("enlists", "google", "inlets", "banana")
expect_equal(anagram(subject, candidates),
c("inlets"))
})

test_that("detects multiple anagrams", {
subject <- "allergy"
candidates <-
c("gallery", "ballerina", "regally", "clergy", "largely", "leading")
expect_equal(anagram(subject, candidates),
c("gallery", "regally", "largely"))
})

test_that("does not detect indentical words", {
subject <- "corn"
candidates <- c("corn", "dark", "Corn", "rank", "CORN", "cron", "park")
Expand All @@ -67,20 +53,6 @@ test_that("does not detect non-anagrams with identical checksum", {
c())
})

test_that("detects anagrams case-insensitively", {
subject <- "Orchestra"
candidates <- c("cashregister", "Carthorse", "radishes")
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"))
})

test_that("detects anagrams using case-insensitve possible matches", {
subject <- "orchestra"
candidates <- c("cashregister", "Carthorse", "radishes")
Expand All @@ -95,7 +67,7 @@ test_that("does not detect a word as its own anagram", {
c())
})

test_that("does not detect a anagram if the original word is repeated", {
test_that("does not detect an anagram if the original word is repeated", {
subject <- "go"
candidates <- c("go Go GO")
expect_equal(anagram(subject, candidates),
Expand All @@ -109,25 +81,4 @@ test_that("anagrams must use all letters exactly once", {
c())
})

test_that("eliminates anagrams with the same checksum", {
subject <- "mass"
candidates <- c("last")
expect_equal(anagram(subject, candidates),
c())
})

test_that("capital word is not own anagram", {
subject <- "BANANA"
candidates <- c("Banana")
expect_equal(anagram(subject, candidates),
c())
})

test_that("anagrams must use all letters exactly once", {
subject <- "patter"
candidates <- c("tapper")
expect_equal(anagram(subject, candidates),
c())
})

message("All tests passed for exercise: anagram")