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/test/java/com/example/simpleparadox/listycity/failTest.java b/app/src/test/java/com/example/simpleparadox/listycity/failTest.java new file mode 100644 index 00000000..4e061f14 --- /dev/null +++ b/app/src/test/java/com/example/simpleparadox/listycity/failTest.java @@ -0,0 +1,96 @@ +package com.example.simpleparadox.listycity; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class failTest { + private CityList mockCityList() { + CityList cityList = new CityList(); + cityList.add(mockCity()); + return cityList; + } + + private City mockCity() { + return new City("Edmonton", "Alberta"); + } + + @Test + void testAdd() { + CityList cityList = mockCityList(); + + assertEquals(1, cityList.countCities()); + + cityList.add(new City("Regina", "Saskatchewan")); + + assertEquals(2, cityList.countCities()); + assertTrue(cityList.hasCity(new City("Regina", "Saskatchewan"))); + } + + @Test + void testAddException() { + CityList cityList = mockCityList(); + + City city = new City("Yellowknife", "Northwest Territories"); + cityList.add(city); + + assertThrows(IllegalArgumentException.class, () -> { + cityList.add(city); + }); + } + + @Test + void testHasCity() { + CityList cityList = mockCityList(); + + assertTrue(cityList.hasCity(mockCity())); + } + + @Test + void testGetCities() { + CityList cityList = mockCityList(); + + assertEquals(0, mockCity().compareTo(cityList.getCities().get(0))); + + City city = new City("Charlottetown", "Prince Edward Island"); + cityList.add(city); + + assertEquals(0, city.compareTo(cityList.getCities().get(0))); + assertEquals(0, mockCity().compareTo(cityList.getCities().get(1))); + } + + @Test + void testDeleteCity() { + CityList cityList = mockCityList(); + + City city = new City("Victoria", "British Columbia"); + cityList.add(city); + + assertEquals(2, cityList.countCities()); + + cityList.delete(mockCity()); + + assertEquals(1, cityList.countCities()); + assertEquals(0, city.compareTo(cityList.getCities().get(0))); + } + + @Test + void testDeleteException() { + CityList cityList = mockCityList(); + + cityList.delete(mockCity()); + + assertThrows(IllegalArgumentException.class, () -> { + cityList.delete(mockCity()); + }); + } + + @Test + void testCountCities() { + CityList cityList = mockCityList(); + + assertEquals(1, cityList.countCities()); + } +}