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

Improve instructions and tests for Anagram exercise #185

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions exercises/practice/anagram/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Instructions

An anagram is a rearrangement of letters to form a new word.
Given a word and a list of candidates, select the sublist of anagrams of the given word.
Given a word and a vector of candidates, return the subset of anagrams of the given word.

Given `"listen"` and a list of candidates like `"enlists" "google"
"inlets" "banana"` the program should return a list containing
`"inlets"`.
For example, given the subject `"listen"` and a vector of candidates like `"Enlists" "Google"
"Inlets" "Banana"` the program should return a vector containing
`"Inlets"`.

Note that the function should not return a candidate if it is the same word as the subject.
40 changes: 20 additions & 20 deletions exercises/practice/anagram/test_anagram.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ context("anagram")
test_that("no matches", {
subject <- "diaper"
candidates <- c("hello", "world", "zombies", "pants")
expect_equal(anagram(subject, candidates),
c())
expect_length(anagram(subject, candidates),
0)
})

test_that("detects simple anagram", {
Expand All @@ -20,8 +20,8 @@ test_that("detects simple anagram", {
test_that("does not detect false positives", {
subject <- "galea"
candidates <- c("eagle")
expect_equal(anagram(subject, candidates),
c())
expect_length(anagram(subject, candidates),
0)
})

test_that("detects multiple anagrams", {
Expand All @@ -34,8 +34,8 @@ test_that("detects multiple anagrams", {
test_that("does not detect anagram subsets", {
subject <- "good"
candidates <- c("dog", "goody")
expect_equal(anagram(subject, candidates),
c())
expect_length(anagram(subject, candidates),
0)
})

test_that("detects anagram", {
Expand Down Expand Up @@ -63,8 +63,8 @@ test_that("does not detect indentical words", {
test_that("does not detect non-anagrams with identical checksum", {
subject <- "mass"
candidates <- c("last")
expect_equal(anagram(subject, candidates),
c())
expect_length(anagram(subject, candidates),
0)
})

test_that("detects anagrams case-insensitively", {
Expand All @@ -91,43 +91,43 @@ test_that("detects anagrams using case-insensitve possible matches", {
test_that("does not detect a word as its own anagram", {
subject <- "banana"
candidates <- c("Banana")
expect_equal(anagram(subject, candidates),
c())
expect_length(anagram(subject, candidates),
0)
})

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_length(anagram(subject, candidates),
0)
})

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

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

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

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

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