Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion exercises/acronym/src/example/java/Acronym.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
import java.util.regex.Pattern;

public class Acronym {
public static String generate(String phrase){
private final String acronym;

public Acronym(String phrase) {
acronym = generateAcronym(phrase);
}

public String get() {
return acronym;
}

private String generateAcronym(String phrase){
final Pattern BREAK_WORDS = Pattern.compile("[A-Z]+[a-z]*|[a-z]+");
final Matcher matcher = BREAK_WORDS.matcher(phrase);
final StringBuilder b = new StringBuilder();
Expand Down
17 changes: 8 additions & 9 deletions exercises/acronym/src/test/java/AcronymTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,67 @@

public class AcronymTest {


@Test
public void fromTitleCasedPhrases() {
final String phrase = "Portable Network Graphics";
final String expected = "PNG";
assertEquals(expected, Acronym.generate(phrase));
assertEquals(expected, new Acronym(phrase).get());
}

@Ignore
@Test
public void fromOtherTitleCasedPhrases() {
final String phrase = "Ruby on Rails";
final String expected = "ROR";
assertEquals(expected, Acronym.generate(phrase));
assertEquals(expected, new Acronym(phrase).get());
}

@Ignore
@Test
public void fromInconsistentlyCasedPhrases() {
final String phrase = "HyperText Markup Language";
final String expected = "HTML";
assertEquals(expected, Acronym.generate(phrase));
assertEquals(expected, new Acronym(phrase).get());
}

@Ignore
@Test
public void fromPhrasesWithPunctuation() {
final String phrase = "First In, First Out";
final String expected = "FIFO";
assertEquals(expected, Acronym.generate(phrase));
assertEquals(expected, new Acronym(phrase).get());
}

@Ignore
@Test
public void fromOtherPhrasesWithPunctuation() {
final String phrase = "PHP: Hypertext Preprocessor";
final String expected = "PHP";
assertEquals(expected, Acronym.generate(phrase));
assertEquals(expected, new Acronym(phrase).get());
}

@Ignore
@Test
public void fromPhrasesWithNonAcronymAllCapsWord() {
final String phrase = "GNU Image Manipulation Program";
final String expected = "GIMP";
assertEquals(expected, Acronym.generate(phrase));
assertEquals(expected, new Acronym(phrase).get());
}

@Ignore
@Test
public void fromPhrasesWithPunctuationAndSentenceCasing() {
final String phrase = "Complementary metal-oxide semiconductor";
final String expected = "CMOS";
assertEquals(expected, Acronym.generate(phrase));
assertEquals(expected, new Acronym(phrase).get());
}

@Ignore
@Test
public void fromPhraseWithSingleLetterWord() {
final String phrase = "Cat in a Hat";
final String expected = "CIAH";
assertEquals(expected, Acronym.generate(phrase));
assertEquals(expected, new Acronym(phrase).get());
}

}