From b58ba956e478f35de2945b52a1274e9e0494e8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Guillou?= Date: Thu, 2 Sep 2021 17:06:38 +1000 Subject: [PATCH 1/2] clarify instructions regarding type, case and same-word check --- exercises/practice/anagram/.docs/instructions.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/exercises/practice/anagram/.docs/instructions.md b/exercises/practice/anagram/.docs/instructions.md index 2675b583..0a790c1a 100644 --- a/exercises/practice/anagram/.docs/instructions.md +++ b/exercises/practice/anagram/.docs/instructions.md @@ -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. \ No newline at end of file From a12482e38208eeb15f7071284dabeada9f851506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Guillou?= Date: Thu, 2 Sep 2021 17:11:34 +1000 Subject: [PATCH 2/2] use length 0 for empty vectors as a more flexible test --- exercises/practice/anagram/test_anagram.R | 40 +++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/exercises/practice/anagram/test_anagram.R b/exercises/practice/anagram/test_anagram.R index f10a1a0f..6d0b276d 100644 --- a/exercises/practice/anagram/test_anagram.R +++ b/exercises/practice/anagram/test_anagram.R @@ -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", { @@ -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", { @@ -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", { @@ -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", { @@ -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")