diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..cb67bab4 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +ListyCity \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..61a9130c --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 00000000..a5f05cd8 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..d5d35ec4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/simpleparadox/listycity/CityList.java b/app/src/main/java/com/example/simpleparadox/listycity/CityList.java index 6da242f3..159a30d8 100644 --- a/app/src/main/java/com/example/simpleparadox/listycity/CityList.java +++ b/app/src/main/java/com/example/simpleparadox/listycity/CityList.java @@ -9,6 +9,7 @@ */ public class CityList { private List cities = new ArrayList<>(); + private int numberOfCitiesDeleted = 0; /** * This adds a city to the list if the city does not exist @@ -64,6 +65,7 @@ public void delete(City city) { for (City c : cities) { if (c.compareTo(city) == 0){ cities.remove(c); + numberOfCitiesDeleted++; break; } } @@ -77,4 +79,11 @@ public void delete(City city) { public int countCities() { return cities.size(); } + + /** + * Returns the total count of cities being removed + * @return + * An integer representing the number of cities being deleted if any + */ + public int countDeletedCities() { return numberOfCitiesDeleted; } } diff --git a/app/src/test/java/com/example/simpleparadox/listycity/CityListTest.java b/app/src/test/java/com/example/simpleparadox/listycity/CityListTest.java index 787eab7e..d61090c0 100644 --- a/app/src/test/java/com/example/simpleparadox/listycity/CityListTest.java +++ b/app/src/test/java/com/example/simpleparadox/listycity/CityListTest.java @@ -93,4 +93,14 @@ void testCountCities() { assertEquals(1, cityList.countCities()); } + + @Test + void testCountDeletedCities() { + CityList cityList = mockCityList(); + cityList.add(new City("Ottawa", "ON")); + cityList.delete(cityList.getCities().get(0)); + assertEquals(1, cityList.countDeletedCities()); + cityList.delete(cityList.getCities().get(0)); + assertEquals(2, cityList.countDeletedCities()); + } } \ No newline at end of file