Skip to content

Commit

Permalink
Update acronym tests to version 1.7.0 (#117)
Browse files Browse the repository at this point in the history
* Update acronym tests to version 1.7.0

* Update acronym example.R to pass new tests

* Disambiguate variable name
  • Loading branch information
jonmcalder authored Mar 31, 2019
1 parent 5af1a07 commit 94a76fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
14 changes: 4 additions & 10 deletions exercises/acronym/example.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
acronym <- function(input) {
# split the string by spaces or hyphens
split <- strsplit(input, " |-")

# get the first letter of each substring
first_letters <- substring(split[[1]], 1, 1)

# join the acronym back together & make uppercase
acronym <- paste(toupper(first_letters), collapse = "")

return(acronym)
words <- strsplit(input, " |-")[[1]]
words <- gsub("[[:punct:]]", "", words)
first_letters <- lapply(words, substring, 1, 1)
toupper(paste(first_letters, collapse = ""))
}
16 changes: 15 additions & 1 deletion exercises/acronym/test_acronym.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,19 @@ test_that("Very long abbreviation", {
expect_equal(acronym(input), "ROTFLSHTMDCOALM")
})

message("All tests passed for exercise: acronym")
test_that("Consecutive delimiters", {
input <- "Something - I made up from thin air"
expect_equal(acronym(input), "SIMUFTA")
})

test_that("Apostrophes", {
input <- "Halley's Comet"
expect_equal(acronym(input), "HC")
})

test_that("Underscore emphasis", {
input <- "The Road _Not_ Taken"
expect_equal(acronym(input), "TRNT")
})

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

0 comments on commit 94a76fb

Please sign in to comment.