Skip to content

Commit

Permalink
Merge pull request #99 from zacchaeusluke/master
Browse files Browse the repository at this point in the history
Add acronym exercise
  • Loading branch information
katrinleinweber committed Sep 4, 2018
2 parents c99f030 + f4beddf commit 7c1455b
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
11 changes: 11 additions & 0 deletions config.json
Expand Up @@ -360,6 +360,17 @@
"control_flow_loops",
"text_formatting"
]
},
{
"slug": "acronym",
"uuid": "54e60174-4833-418c-b9af-2fcb5722b1d6",
"core": false,
"unlocked_by": null,
"difficulty": 1,
"topics": [
"strings",
"filtering"
]
}
]
}
24 changes: 24 additions & 0 deletions exercises/acronym/README.md
@@ -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.
3 changes: 3 additions & 0 deletions exercises/acronym/acronym.R
@@ -0,0 +1,3 @@
acronym <- function(input) {

}
12 changes: 12 additions & 0 deletions exercises/acronym/example.R
@@ -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)
}
31 changes: 31 additions & 0 deletions exercises/acronym/test_acronym.R
@@ -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")

0 comments on commit 7c1455b

Please sign in to comment.