diff --git a/exercises/concept/karls-languages/.meta/config.json b/exercises/concept/karls-languages/.meta/config.json index 2315fc3c5..a36f6081a 100644 --- a/exercises/concept/karls-languages/.meta/config.json +++ b/exercises/concept/karls-languages/.meta/config.json @@ -2,6 +2,9 @@ "authors": [ "jmrunkle" ], + "contributors": [ + "Valmati" + ], "files": { "solution": [ "src/main/java/LanguageList.java" diff --git a/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java b/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java index 13df5f4a2..f37d2df15 100644 --- a/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java +++ b/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java @@ -9,7 +9,9 @@ public boolean isEmpty() { } public void addLanguage(String language) { - languages.add(language); + if (!containsLanguage(language)) { + languages.add(language) + } } public void removeLanguage(String language) { diff --git a/exercises/concept/karls-languages/src/test/java/LanguageListTest.java b/exercises/concept/karls-languages/src/test/java/LanguageListTest.java index 551d6cfc9..0e088c517 100644 --- a/exercises/concept/karls-languages/src/test/java/LanguageListTest.java +++ b/exercises/concept/karls-languages/src/test/java/LanguageListTest.java @@ -34,6 +34,17 @@ public void removeLanguage() { assertThat(languageList.isEmpty()).isTrue(); } + @Test + @Tag("task:3") + @DisplayName("The removeLanguage method correctly removes a language from the list that has been added twice") + public void removeLanguageTwice() { + languageList.addLanguage("Python"); + languageList.addLanguage("Python"); + languageList.removeLanguage("Python"); + + assertThat(languageList.isEmpty()).isTrue(); + } + @Test @Tag("task:4") @DisplayName("The firstLanguage method returns the first language that was added to the list") @@ -56,6 +67,16 @@ public void countThree() { assertThat(languageList.count()).isEqualTo(3); } + @Test + @Tag("task:5") + @DisplayName("The count method returns 1 when the same language has been added twice") + public void countOne() { + languageList.addLanguage("Python"); + languageList.addLanguage("Python"); + + assertThat(languageList.count()).isEqualTo(1); + } + @Test @Tag("task:5") @DisplayName("The count method returns 0 when the list is empty")