Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from zacchaeusluke/master
Add acronym exercise
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Acronym | ||
|
||
Convert a phrase to its acronym. | ||
|
||
Techies love their TLA (Three Letter Acronyms)! | ||
|
||
Help generate some jargon by writing a program that converts a long name | ||
like Portable Network Graphics to its acronym (PNG). | ||
|
||
## Installation | ||
See [this guide](https://github.com/exercism/xr/blob/master/docs/INSTALLATION.md) for instructions on how to setup your local R environment. | ||
|
||
## How to implement your solution | ||
In each problem folder, there is a file named `<exercise_name>.R` containing a function that returns a `NULL` value. Place your implementation inside the body of the function. | ||
|
||
## How to run tests | ||
Inside of RStudio, simply execute the `test_<exercise_name>.R` script. This can be conveniently done with [testthat's `auto_test` function](https://www.rdocumentation.org/packages/testthat/topics/auto_test). Because exercism code and tests are in the same folder, use this same path for both `code_path` and `test_path` parameters. On the command-line, you can also run `Rscript test_<exercise_name>.R`. | ||
|
||
## Source | ||
|
||
Julien Vanier [https://github.com/monkbroc](https://github.com/monkbroc) | ||
|
||
## Submitting Incomplete Solutions | ||
It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
acronym <- function(input) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
source("./acronym.R") | ||
library(testthat) | ||
|
||
context("acronym") | ||
|
||
test_that("Abbreviate a phrase", { | ||
input <- "Portable Network Graphics" | ||
expect_equal(acronym(input), "PNG") | ||
}) | ||
|
||
test_that("Lowercase words", { | ||
input <- "Ruby on Rails" | ||
expect_equal(acronym(input), "ROR") | ||
}) | ||
|
||
test_that("Punctuation", { | ||
input <- "First In, First Out" | ||
expect_equal(acronym(input), "FIFO") | ||
}) | ||
|
||
test_that("All caps word", { | ||
input <- "GNU Image Manipulation Program" | ||
expect_equal(acronym(input), "GIMP") | ||
}) | ||
|
||
test_that("Punctuation without whitespace", { | ||
input <- "Complementary metal-oxide semiconductor" | ||
expect_equal(acronym(input), "CMOS") | ||
}) | ||
|
||
message("All tests passed for exercise: acronym") |