Skip to content

Instantly share code, notes, and snippets.

@zantetsuken88
Created July 23, 2018 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zantetsuken88/060c679f1a564783ba3fef46f623c7b6 to your computer and use it in GitHub Desktop.
Save zantetsuken88/060c679f1a564783ba3fef46f623c7b6 to your computer and use it in GitHub Desktop.
Acronym

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).

Running the tests You can run all the tests for an exercise by entering

$ gradle test in your terminal.

Source Julien Vanier 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.

class Acronym {
private final String phrase;
Acronym(String phrase) {
this.phrase = phrase;
}
String get() {
String[] words = phrase.split("\\W+");
StringBuilder acronym = new StringBuilder();
for (String s : words) {
acronym.append(s.toCharArray()[0]);
}
return acronym.toString().toUpperCase();
}
}
import org.junit.Test;
import org.junit.Ignore;
import static org.junit.Assert.assertEquals;
public class AcronymTest {
@Test
public void basic() {
String phrase = "Portable Network Graphics";
String expected = "PNG";
assertEquals(expected, new Acronym(phrase).get());
}
@Ignore("Remove to run test")
@Test
public void lowercaseWords() {
String phrase = "Ruby on Rails";
String expected = "ROR";
assertEquals(expected, new Acronym(phrase).get());
}
@Ignore("Remove to run test")
@Test
public void punctuation() {
String phrase = "First In, First Out";
String expected = "FIFO";
assertEquals(expected, new Acronym(phrase).get());
}
@Ignore("Remove to run test")
@Test
public void NonAcronymAllCapsWord() {
String phrase = "GNU Image Manipulation Program";
String expected = "GIMP";
assertEquals(expected, new Acronym(phrase).get());
}
@Ignore("Remove to run test")
@Test
public void punctuationWithoutWhitespace() {
String phrase = "Complementary metal-oxide semiconductor";
String expected = "CMOS";
assertEquals(expected, new Acronym(phrase).get());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment