Skip to content

Commit 55faf98

Browse files
lemoncurryFridaTveit
authored andcommitted
acronym: update v1.5.0 to v1.6.0 (exercism#1613)
* acronym: update v1.5.0 to v1.6.0 * acronym: change regex to also pass new apostrophe test * acronym: fix order of methods
1 parent 0c16c23 commit 55faf98

3 files changed

Lines changed: 26 additions & 17 deletions

File tree

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import java.util.Arrays;
22
import java.util.stream.Collectors;
33

4-
final class Acronym {
4+
class Acronym {
55

6-
private final String acronym;
6+
private String acronym;
77

88
Acronym(String phrase) {
9-
acronym = generateAcronym(phrase);
9+
this.acronym = generateAcronym(phrase);
1010
}
1111

12-
String get() {
12+
13+
String getAcronym() {
1314
return acronym;
1415
}
1516

1617
private String generateAcronym(String phrase) {
17-
return Arrays.stream(phrase.split("[^a-zA-Z]"))
18-
.filter(word -> !word.isEmpty()) // Remove empty strings from the result of phrase.split
19-
.map(word -> word.substring(0, 1)) // Get the first character of each word
20-
.collect(Collectors.joining()) // Concatenate the characters
21-
.toUpperCase();
18+
return Arrays.stream(phrase.split("(?!')\\W"))
19+
.filter(word -> !word.isEmpty()) // Remove empty strings from the result of phrase.split
20+
.map(word -> word.substring(0, 1)) // Get the first character of each word
21+
.collect(Collectors.joining()) // Concatenate the characters
22+
.toUpperCase();
2223
}
2324

2425
}

‎exercises/acronym/.meta/version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.0
1+
1.6.0

‎exercises/acronym/src/test/java/AcronymTest.java‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,63 @@ public class AcronymTest {
99
public void basic() {
1010
String phrase = "Portable Network Graphics";
1111
String expected = "PNG";
12-
assertEquals(expected, new Acronym(phrase).get());
12+
assertEquals(expected, new Acronym(phrase).getAcronym());
1313
}
1414

1515
@Ignore("Remove to run test")
1616
@Test
1717
public void lowercaseWords() {
1818
String phrase = "Ruby on Rails";
1919
String expected = "ROR";
20-
assertEquals(expected, new Acronym(phrase).get());
20+
assertEquals(expected, new Acronym(phrase).getAcronym());
2121
}
2222

2323
@Ignore("Remove to run test")
2424
@Test
2525
public void punctuation() {
2626
String phrase = "First In, First Out";
2727
String expected = "FIFO";
28-
assertEquals(expected, new Acronym(phrase).get());
28+
assertEquals(expected, new Acronym(phrase).getAcronym());
2929
}
3030

3131
@Ignore("Remove to run test")
3232
@Test
3333
public void nonAcronymAllCapsWord() {
3434
String phrase = "GNU Image Manipulation Program";
3535
String expected = "GIMP";
36-
assertEquals(expected, new Acronym(phrase).get());
36+
assertEquals(expected, new Acronym(phrase).getAcronym());
3737
}
3838

3939
@Ignore("Remove to run test")
4040
@Test
4141
public void punctuationWithoutWhitespace() {
4242
String phrase = "Complementary metal-oxide semiconductor";
4343
String expected = "CMOS";
44-
assertEquals(expected, new Acronym(phrase).get());
44+
assertEquals(expected, new Acronym(phrase).getAcronym());
4545
}
4646

4747
@Ignore("Remove to run test")
4848
@Test
4949
public void veryLongAbbreviation() {
5050
String phrase = "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me";
5151
String expected = "ROTFLSHTMDCOALM";
52-
assertEquals(expected, new Acronym(phrase).get());
52+
assertEquals(expected, new Acronym(phrase).getAcronym());
5353
}
5454

5555
@Ignore("Remove to run test")
5656
@Test
5757
public void consecutiveDelimiters() {
5858
String phrase = "Something - I made up from thin air";
5959
String expected = "SIMUFTA";
60-
assertEquals(expected, new Acronym(phrase).get());
60+
assertEquals(expected, new Acronym(phrase).getAcronym());
61+
}
62+
63+
@Ignore("Remove to run test")
64+
@Test
65+
public void apostrophes() {
66+
String phrase = "Halley's Comet";
67+
String expected = "HC";
68+
assertEquals(expected, new Acronym(phrase).getAcronym());
6169
}
6270

6371
}

0 commit comments

Comments
 (0)