File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
exercises/concept/karls-languages Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 22 "authors" : [
33 " jmrunkle"
44 ],
5+ "contributors" : [
6+ " Valmati"
7+ ],
58 "files" : {
69 "solution" : [
710 " src/main/java/LanguageList.java"
Original file line number Diff line number Diff line change @@ -9,7 +9,9 @@ public boolean isEmpty() {
99 }
1010
1111 public void addLanguage (String language ) {
12- languages .add (language );
12+ if (!containsLanguage (language )) {
13+ languages .add (language )
14+ }
1315 }
1416
1517 public void removeLanguage (String language ) {
Original file line number Diff line number Diff line change @@ -34,6 +34,17 @@ public void removeLanguage() {
3434 assertThat (languageList .isEmpty ()).isTrue ();
3535 }
3636
37+ @ Test
38+ @ Tag ("task:3" )
39+ @ DisplayName ("The removeLanguage method correctly removes a language from the list that has been added twice" )
40+ public void removeLanguageTwice () {
41+ languageList .addLanguage ("Python" );
42+ languageList .addLanguage ("Python" );
43+ languageList .removeLanguage ("Python" );
44+
45+ assertThat (languageList .isEmpty ()).isTrue ();
46+ }
47+
3748 @ Test
3849 @ Tag ("task:4" )
3950 @ DisplayName ("The firstLanguage method returns the first language that was added to the list" )
@@ -56,6 +67,16 @@ public void countThree() {
5667 assertThat (languageList .count ()).isEqualTo (3 );
5768 }
5869
70+ @ Test
71+ @ Tag ("task:5" )
72+ @ DisplayName ("The count method returns 1 when the same language has been added twice" )
73+ public void countOne () {
74+ languageList .addLanguage ("Python" );
75+ languageList .addLanguage ("Python" );
76+
77+ assertThat (languageList .count ()).isEqualTo (1 );
78+ }
79+
5980 @ Test
6081 @ Tag ("task:5" )
6182 @ DisplayName ("The count method returns 0 when the list is empty" )
You can’t perform that action at this time.
0 commit comments