Skip to content

Commit

Permalink
Acronym: adjust API to use an instance method (#380)
Browse files Browse the repository at this point in the history
Fixes issue #351.
  • Loading branch information
FridaTveit authored and jtigger committed Mar 21, 2017
1 parent 1a70dee commit 5eb3a6e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
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());
}

}

0 comments on commit 5eb3a6e

Please sign in to comment.