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

🔥 Remove superfluous messages in tests #296

Merged
merged 1 commit into from
Oct 9, 2023
Merged
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
7 changes: 2 additions & 5 deletions exercises/practice/acronym/test_acronym.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
source("./acronym.R")
library(testthat)

context("acronym")

test_that("Abbreviate a phrase", {
input <- "Portable Network Graphics"
expect_equal(acronym(input), "PNG")
Expand Down Expand Up @@ -32,7 +30,8 @@ test_that("Very long abbreviation", {
input <- paste(
"Rolling On The Floor Laughing So Hard ",
"That My Dogs Came Over And Licked Me",
sep = "")
sep = ""
)
expect_equal(acronym(input), "ROTFLSHTMDCOALM")
})

Expand All @@ -50,5 +49,3 @@ test_that("Underscore emphasis", {
input <- "The Road _Not_ Taken"
expect_equal(acronym(input), "TRNT")
})

message("All tests passed for exercise: acronym")
41 changes: 21 additions & 20 deletions exercises/practice/allergies/test_allergies.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
source("./allergies.R")
library(testthat)

context("allergies")

test_that("no allergies means not allergic", {
x <- allergy(0)
expect_false(allergic_to(x, "peanuts"))
Expand Down Expand Up @@ -45,42 +43,45 @@ test_that("allergic to just strawberries", {
test_that("allergic to eggs and peanuts", {
x <- allergy(3)
expect_true(setequal(
list_allergies(x),
c("eggs", "peanuts"))
)
list_allergies(x),
c("eggs", "peanuts")
))
})

test_that("allergic to more than eggs but not peanuts", {
x <- allergy(5)
expect_true(setequal(
list_allergies(x),
c("eggs", "shellfish"))
)
list_allergies(x),
c("eggs", "shellfish")
))
})

test_that("allergic to lots of stuff", {
x <- allergy(248)
expect_true(setequal(
list_allergies(x),
c("strawberries", "tomatoes", "chocolate", "pollen", "cats"))
)
list_allergies(x),
c("strawberries", "tomatoes", "chocolate", "pollen", "cats")
))
})

test_that("allergic to everything", {
x <- allergy(255)
expect_true(setequal(
list_allergies(x),
c("eggs", "peanuts", "shellfish", "strawberries", "tomatoes",
"chocolate", "pollen", "cats")))
list_allergies(x),
c(
"eggs", "peanuts", "shellfish", "strawberries", "tomatoes",
"chocolate", "pollen", "cats"
)
))
})

test_that("ignore non allergen score parts", {
x <- allergy(509)
expect_true(setequal(
list_allergies(x),
c("eggs", "shellfish", "strawberries", "tomatoes",
"chocolate", "pollen", "cats"))
)
list_allergies(x),
c(
"eggs", "shellfish", "strawberries", "tomatoes",
"chocolate", "pollen", "cats"
)
))
})

message("All tests passed for exercise: allergies")
154 changes: 98 additions & 56 deletions exercises/practice/anagram/test_anagram.R
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")
)
}
)
4 changes: 0 additions & 4 deletions exercises/practice/armstrong-numbers/test_armstrong-numbers.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
source("./armstrong-numbers.R")
library(testthat)

context("armstrong-numbers")

test_that("Zero is an Armstrong number", {
expect_equal(is_armstrong_number(0), TRUE)
})
Expand Down Expand Up @@ -38,5 +36,3 @@ test_that("Seven-digit number that is an Armstrong number", {
test_that("Seven-digit number that is not an Armstrong number", {
expect_equal(is_armstrong_number(9926314), FALSE)
})

message("All tests passed for exercise: armstrong-numbers")
Loading