forked from exercism/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update acronym to match canonical-data. Refs exercism#488
- Loading branch information
Showing
2 changed files
with
25 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
object Acronym { | ||
def abbreviate(phrase: String): String = { | ||
"[A-Z]+[a-z]*|[a-z]+".r.findAllIn(phrase).map(s => s.head.toUpper).mkString | ||
"('\\w+)|(\\w+'\\w+)|(\\w+')|(\\w+)".r | ||
.findAllIn(phrase) | ||
.map(_.head.toUpper) | ||
.mkString | ||
} | ||
} |
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 |
---|---|---|
@@ -1,29 +1,44 @@ | ||
import org.scalatest.{Matchers, FunSuite} | ||
|
||
/** @version 1.3.0 */ | ||
/** @version 1.6.0 */ | ||
class AcronymTest extends FunSuite with Matchers { | ||
|
||
test("basic") { | ||
Acronym.abbreviate("Portable Network Graphics") should be ("PNG") | ||
} | ||
|
||
test("lowercase words") { | ||
pending | ||
//pending | ||
Acronym.abbreviate("Ruby on Rails") should be ("ROR") | ||
} | ||
|
||
test("punctuation") { | ||
pending | ||
//pending | ||
Acronym.abbreviate("First In, First Out") should be ("FIFO") | ||
} | ||
|
||
test("all caps word") { | ||
pending | ||
//pending | ||
Acronym.abbreviate("GNU Image Manipulation Program") should be ("GIMP") | ||
} | ||
|
||
test("punctuation without whitespace") { | ||
pending | ||
//pending | ||
Acronym.abbreviate("Complementary metal-oxide semiconductor") should be ("CMOS") | ||
} | ||
} | ||
|
||
test("very long abbreviation") { | ||
//pending | ||
Acronym.abbreviate("Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me") should be ("ROTFLSHTMDCOALM") | ||
} | ||
|
||
test("consecutive delimiters") { | ||
//pending | ||
Acronym.abbreviate("Something - I made up from thin air") should be ("SIMUFTA") | ||
} | ||
|
||
test("apostrophes") { | ||
//pending | ||
Acronym.abbreviate("Halley's Comet") should be ("HC") | ||
} | ||
} |