From bd6108dae3be4550177d4919176d8c23a92cc7ea Mon Sep 17 00:00:00 2001 From: TUSHI26 <86578169+TUSHI26@users.noreply.github.com> Date: Tue, 24 May 2022 14:34:20 +0600 Subject: [PATCH 1/7] Delete CityListTest.java --- .../com/example/citylist/CityListTest.java | 52 ------------------- 1 file changed, 52 deletions(-) delete mode 100644 app/src/test/java/com/example/citylist/CityListTest.java diff --git a/app/src/test/java/com/example/citylist/CityListTest.java b/app/src/test/java/com/example/citylist/CityListTest.java deleted file mode 100644 index aa8ebe85..00000000 --- a/app/src/test/java/com/example/citylist/CityListTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.example.citylist; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class CityListTest { - private CityList mockCityList() { - CityList cityList = new CityList(); - cityList.add(mockCity()); - return cityList; - } - - private City mockCity() { - return new City("Edmonton", "AB"); - } - - @Test - public void testAdd() { - CityList cityList = mockCityList(); - assertEquals(1, cityList.getCities().size()); - - City city = new City("Regina", "SK"); - cityList.add(city); - - assertEquals(2, cityList.getCities().size()); - assertTrue(cityList.getCities().contains(city)); - } - - @Test - public void testAddException() { - CityList cityList = new CityList(); - City city = mockCity(); - cityList.add(city); - - assertThrows(IllegalArgumentException.class, () -> { - cityList.add(city); - }); - } - - @Test - public 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))); - } -} From 99b723f3267f2a9cc1653146973a320640cbddd9 Mon Sep 17 00:00:00 2001 From: TUSHI26 <86578169+TUSHI26@users.noreply.github.com> Date: Tue, 24 May 2022 15:55:55 +0600 Subject: [PATCH 2/7] Update CityList.java --- .../java/com/example/citylist/CityList.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/citylist/CityList.java b/app/src/main/java/com/example/citylist/CityList.java index c3cc4466..48bde713 100644 --- a/app/src/main/java/com/example/citylist/CityList.java +++ b/app/src/main/java/com/example/citylist/CityList.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; /** @@ -27,9 +28,40 @@ public void add(City city) { * @return * Return the sorted list of cities */ - public List getCities() { + public List getCities(int param) { List cityList = cities; - Collections.sort(cityList); + if(param==1){ + Collections.sort(cityList); + } + else{ + Collections.sort(cityList, new Comparator() { + @Override + public int compare(City city, City t1) { + return city.getProvinceName().compareTo(t1.getProvinceName()); + } + }); + + } + //Collections.sort(cityList); return cityList; } + + /** + * + * @param city + * if city doesnt exist,return an exception + */ + public void delete(City city){ + if(!cities.contains(city)){ + throw new IllegalArgumentException(); + + } + else{ + cities.remove(city); + } + } + + public int count(){ + return cities.size(); + } } From c958c1739705d3716de12745ce5f68fcdcff9718 Mon Sep 17 00:00:00 2001 From: TUSHI26 <86578169+TUSHI26@users.noreply.github.com> Date: Tue, 24 May 2022 15:58:06 +0600 Subject: [PATCH 3/7] Create CityListTest.java --- .../com/example/citylist/CityListTest.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 app/src/test/java/com/example/citylist/CityListTest.java diff --git a/app/src/test/java/com/example/citylist/CityListTest.java b/app/src/test/java/com/example/citylist/CityListTest.java new file mode 100644 index 00000000..fac4cd15 --- /dev/null +++ b/app/src/test/java/com/example/citylist/CityListTest.java @@ -0,0 +1,90 @@ +package com.example.citylist; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CityListTest { + private CityList mockCityList() { + CityList cityList = new CityList(); + cityList.add(mockCity()); + return cityList; + } + + private City mockCity() { + return new City("Edmonton", "AB"); + } + + @Test + public void testAdd() { + CityList cityList = mockCityList(); + assertEquals(1, cityList.getCities(1).size()); + + City city = new City("Regina", "SK"); + cityList.add(city); + + assertEquals(2, cityList.getCities(1).size()); + assertTrue(cityList.getCities(1).contains(city)); + } + @Test + public void testdelete(){ + CityList cityList=new CityList(); + City city=new City("montreal","canada"); + City city1=new City("panjab","uttorprodesh"); + cityList.add(city); + cityList.add(city1); + assertEquals(2,cityList.count()); + cityList.delete(city); + assertEquals(1,cityList.count()); + assertTrue(!cityList.getCities(1).contains(city)); + + } + @Test + public void testDeleteException() { + CityList cityList=new CityList(); + City city=new City("montreal","canada"); + City city1=new City("panjab","uttorprodesh"); + cityList.add(city); + cityList.add(city1); + + + assertThrows(IllegalArgumentException.class, () -> { + cityList.add(city); + }); + } + @Test + public void testAddException() { + CityList cityList = new CityList(); + City city = mockCity(); + cityList.add(city); + + assertThrows(IllegalArgumentException.class, () -> { + cityList.delete(city); + }); + } + + /* @Test + public void testGetCities() { + CityList cityList = mockCityList(); + assertEquals(0, mockCity().compareTo(cityList.getCities(1).get(0))); + + City city = new City("Charlottetown", "Prince Edward Island"); + cityList.add(city); + + assertEquals(0, city.compareTo(cityList.getCities(1).get(0))); + assertEquals(0, mockCity().compareTo(cityList.getCities(1).get(1))); + }*/ + @Test + public void tesTGetCities() { + CityList cityList =new CityList() ; + City city1=new City("ZZZZ","CD"); + cityList.add(city1); + //assertEquals(0, city1.compareTo(cityList.getCities(1).get(0))); + + City city = new City("Charlottetown", "Prince Edward Island"); + cityList.add(city); + + assertEquals(0, city.compareTo(cityList.getCities(2).get(0))); + assertEquals(0, city1.compareTo(cityList.getCities(2).get(1))); + } +} From b2f1150a425b4e56de3c3fe0ca42d717774696a1 Mon Sep 17 00:00:00 2001 From: TUSHI26 <86578169+TUSHI26@users.noreply.github.com> Date: Wed, 25 May 2022 01:36:17 +0600 Subject: [PATCH 4/7] Delete CityListTest.java --- .../com/example/citylist/CityListTest.java | 90 ------------------- 1 file changed, 90 deletions(-) delete mode 100644 app/src/test/java/com/example/citylist/CityListTest.java diff --git a/app/src/test/java/com/example/citylist/CityListTest.java b/app/src/test/java/com/example/citylist/CityListTest.java deleted file mode 100644 index fac4cd15..00000000 --- a/app/src/test/java/com/example/citylist/CityListTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.example.citylist; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class CityListTest { - private CityList mockCityList() { - CityList cityList = new CityList(); - cityList.add(mockCity()); - return cityList; - } - - private City mockCity() { - return new City("Edmonton", "AB"); - } - - @Test - public void testAdd() { - CityList cityList = mockCityList(); - assertEquals(1, cityList.getCities(1).size()); - - City city = new City("Regina", "SK"); - cityList.add(city); - - assertEquals(2, cityList.getCities(1).size()); - assertTrue(cityList.getCities(1).contains(city)); - } - @Test - public void testdelete(){ - CityList cityList=new CityList(); - City city=new City("montreal","canada"); - City city1=new City("panjab","uttorprodesh"); - cityList.add(city); - cityList.add(city1); - assertEquals(2,cityList.count()); - cityList.delete(city); - assertEquals(1,cityList.count()); - assertTrue(!cityList.getCities(1).contains(city)); - - } - @Test - public void testDeleteException() { - CityList cityList=new CityList(); - City city=new City("montreal","canada"); - City city1=new City("panjab","uttorprodesh"); - cityList.add(city); - cityList.add(city1); - - - assertThrows(IllegalArgumentException.class, () -> { - cityList.add(city); - }); - } - @Test - public void testAddException() { - CityList cityList = new CityList(); - City city = mockCity(); - cityList.add(city); - - assertThrows(IllegalArgumentException.class, () -> { - cityList.delete(city); - }); - } - - /* @Test - public void testGetCities() { - CityList cityList = mockCityList(); - assertEquals(0, mockCity().compareTo(cityList.getCities(1).get(0))); - - City city = new City("Charlottetown", "Prince Edward Island"); - cityList.add(city); - - assertEquals(0, city.compareTo(cityList.getCities(1).get(0))); - assertEquals(0, mockCity().compareTo(cityList.getCities(1).get(1))); - }*/ - @Test - public void tesTGetCities() { - CityList cityList =new CityList() ; - City city1=new City("ZZZZ","CD"); - cityList.add(city1); - //assertEquals(0, city1.compareTo(cityList.getCities(1).get(0))); - - City city = new City("Charlottetown", "Prince Edward Island"); - cityList.add(city); - - assertEquals(0, city.compareTo(cityList.getCities(2).get(0))); - assertEquals(0, city1.compareTo(cityList.getCities(2).get(1))); - } -} From 3961167e50742b412a8d279d4d8956f5a8ae4642 Mon Sep 17 00:00:00 2001 From: TUSHI26 <86578169+TUSHI26@users.noreply.github.com> Date: Wed, 25 May 2022 01:37:53 +0600 Subject: [PATCH 5/7] Create CityListTest.java --- .../com/example/citylist/CityListTest.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 app/src/test/java/com/example/citylist/CityListTest.java diff --git a/app/src/test/java/com/example/citylist/CityListTest.java b/app/src/test/java/com/example/citylist/CityListTest.java new file mode 100644 index 00000000..1410e26d --- /dev/null +++ b/app/src/test/java/com/example/citylist/CityListTest.java @@ -0,0 +1,92 @@ +package com.example.citylist; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CityListTest { + private CityList mockCityList() { + CityList cityList = new CityList(); + cityList.add(mockCity()); + return cityList; + } + + private City mockCity() { + return new City("Edmonton", "AB"); + } + + @Test + public void testAdd() { + CityList cityList = mockCityList(); + assertEquals(1, cityList.getCities(1).size()); + + City city = new City("Regina", "SK"); + cityList.add(city); + + assertEquals(2, cityList.getCities(1).size()); + assertTrue(cityList.getCities(1).contains(city)); + } + @Test + public void testdelete(){ + CityList cityList=new CityList(); + City city=new City("montreal","canada"); + City city1=new City("panjab","uttorprodesh"); + cityList.add(city); + cityList.add(city1); + assertEquals(2,cityList.count()); + cityList.delete(city); + assertEquals(1,cityList.count()); + assertTrue(!cityList.getCities(1).contains(city)); + + } + @Test + public void testDeleteException() { + CityList cityList=new CityList(); + City city=new City("montreal","canada"); + City city1=new City("panjab","uttorprodesh"); + cityList.add(city); + cityList.add(city1); + cityList.delete(city); + + assertThrows(IllegalArgumentException.class, () -> { + cityList.delete(city1); + }); + } + @Test + public void testAddException() { + CityList cityList = new CityList(); + City city = mockCity(); + City city1 =mockCity(); + cityList.add(city); + cityList.add(city1); + + assertThrows(IllegalArgumentException.class, () -> { + cityList.add(city1); + }); + } + + /* @Test + public void testGetCities() { + CityList cityList = mockCityList(); + assertEquals(0, mockCity().compareTo(cityList.getCities(1).get(0))); + + City city = new City("Charlottetown", "Prince Edward Island"); + cityList.add(city); + + assertEquals(0, city.compareTo(cityList.getCities(1).get(0))); + assertEquals(0, mockCity().compareTo(cityList.getCities(1).get(1))); + }*/ + @Test + public void tesTGetCities() { + CityList cityList =new CityList() ; + City city1=new City("ZZZZ","CD"); + cityList.add(city1); + //assertEquals(0, city1.compareTo(cityList.getCities(1).get(0))); + + City city = new City("Charlottetown", "Prince Edward Island"); + cityList.add(city); + + assertEquals(0, city.compareTo(cityList.getCities(2).get(0))); + assertEquals(0, city1.compareTo(cityList.getCities(2).get(1))); + } +} From 2e5ad7eed4ffd0256e943a12406223c659e99cf5 Mon Sep 17 00:00:00 2001 From: TUSHI26 <86578169+TUSHI26@users.noreply.github.com> Date: Wed, 25 May 2022 01:44:55 +0600 Subject: [PATCH 6/7] Delete CityListTest.java --- .../com/example/citylist/CityListTest.java | 92 ------------------- 1 file changed, 92 deletions(-) delete mode 100644 app/src/test/java/com/example/citylist/CityListTest.java diff --git a/app/src/test/java/com/example/citylist/CityListTest.java b/app/src/test/java/com/example/citylist/CityListTest.java deleted file mode 100644 index 1410e26d..00000000 --- a/app/src/test/java/com/example/citylist/CityListTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.example.citylist; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class CityListTest { - private CityList mockCityList() { - CityList cityList = new CityList(); - cityList.add(mockCity()); - return cityList; - } - - private City mockCity() { - return new City("Edmonton", "AB"); - } - - @Test - public void testAdd() { - CityList cityList = mockCityList(); - assertEquals(1, cityList.getCities(1).size()); - - City city = new City("Regina", "SK"); - cityList.add(city); - - assertEquals(2, cityList.getCities(1).size()); - assertTrue(cityList.getCities(1).contains(city)); - } - @Test - public void testdelete(){ - CityList cityList=new CityList(); - City city=new City("montreal","canada"); - City city1=new City("panjab","uttorprodesh"); - cityList.add(city); - cityList.add(city1); - assertEquals(2,cityList.count()); - cityList.delete(city); - assertEquals(1,cityList.count()); - assertTrue(!cityList.getCities(1).contains(city)); - - } - @Test - public void testDeleteException() { - CityList cityList=new CityList(); - City city=new City("montreal","canada"); - City city1=new City("panjab","uttorprodesh"); - cityList.add(city); - cityList.add(city1); - cityList.delete(city); - - assertThrows(IllegalArgumentException.class, () -> { - cityList.delete(city1); - }); - } - @Test - public void testAddException() { - CityList cityList = new CityList(); - City city = mockCity(); - City city1 =mockCity(); - cityList.add(city); - cityList.add(city1); - - assertThrows(IllegalArgumentException.class, () -> { - cityList.add(city1); - }); - } - - /* @Test - public void testGetCities() { - CityList cityList = mockCityList(); - assertEquals(0, mockCity().compareTo(cityList.getCities(1).get(0))); - - City city = new City("Charlottetown", "Prince Edward Island"); - cityList.add(city); - - assertEquals(0, city.compareTo(cityList.getCities(1).get(0))); - assertEquals(0, mockCity().compareTo(cityList.getCities(1).get(1))); - }*/ - @Test - public void tesTGetCities() { - CityList cityList =new CityList() ; - City city1=new City("ZZZZ","CD"); - cityList.add(city1); - //assertEquals(0, city1.compareTo(cityList.getCities(1).get(0))); - - City city = new City("Charlottetown", "Prince Edward Island"); - cityList.add(city); - - assertEquals(0, city.compareTo(cityList.getCities(2).get(0))); - assertEquals(0, city1.compareTo(cityList.getCities(2).get(1))); - } -} From 5bb538f7b44ec181aea233483bffa03ff55f5501 Mon Sep 17 00:00:00 2001 From: TUSHI26 <86578169+TUSHI26@users.noreply.github.com> Date: Wed, 25 May 2022 02:15:56 +0600 Subject: [PATCH 7/7] Create CityListTest.java --- .../com/example/citylist/CityListTest.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 app/src/test/java/com/example/citylist/CityListTest.java diff --git a/app/src/test/java/com/example/citylist/CityListTest.java b/app/src/test/java/com/example/citylist/CityListTest.java new file mode 100644 index 00000000..1410e26d --- /dev/null +++ b/app/src/test/java/com/example/citylist/CityListTest.java @@ -0,0 +1,92 @@ +package com.example.citylist; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CityListTest { + private CityList mockCityList() { + CityList cityList = new CityList(); + cityList.add(mockCity()); + return cityList; + } + + private City mockCity() { + return new City("Edmonton", "AB"); + } + + @Test + public void testAdd() { + CityList cityList = mockCityList(); + assertEquals(1, cityList.getCities(1).size()); + + City city = new City("Regina", "SK"); + cityList.add(city); + + assertEquals(2, cityList.getCities(1).size()); + assertTrue(cityList.getCities(1).contains(city)); + } + @Test + public void testdelete(){ + CityList cityList=new CityList(); + City city=new City("montreal","canada"); + City city1=new City("panjab","uttorprodesh"); + cityList.add(city); + cityList.add(city1); + assertEquals(2,cityList.count()); + cityList.delete(city); + assertEquals(1,cityList.count()); + assertTrue(!cityList.getCities(1).contains(city)); + + } + @Test + public void testDeleteException() { + CityList cityList=new CityList(); + City city=new City("montreal","canada"); + City city1=new City("panjab","uttorprodesh"); + cityList.add(city); + cityList.add(city1); + cityList.delete(city); + + assertThrows(IllegalArgumentException.class, () -> { + cityList.delete(city1); + }); + } + @Test + public void testAddException() { + CityList cityList = new CityList(); + City city = mockCity(); + City city1 =mockCity(); + cityList.add(city); + cityList.add(city1); + + assertThrows(IllegalArgumentException.class, () -> { + cityList.add(city1); + }); + } + + /* @Test + public void testGetCities() { + CityList cityList = mockCityList(); + assertEquals(0, mockCity().compareTo(cityList.getCities(1).get(0))); + + City city = new City("Charlottetown", "Prince Edward Island"); + cityList.add(city); + + assertEquals(0, city.compareTo(cityList.getCities(1).get(0))); + assertEquals(0, mockCity().compareTo(cityList.getCities(1).get(1))); + }*/ + @Test + public void tesTGetCities() { + CityList cityList =new CityList() ; + City city1=new City("ZZZZ","CD"); + cityList.add(city1); + //assertEquals(0, city1.compareTo(cityList.getCities(1).get(0))); + + City city = new City("Charlottetown", "Prince Edward Island"); + cityList.add(city); + + assertEquals(0, city.compareTo(cityList.getCities(2).get(0))); + assertEquals(0, city1.compareTo(cityList.getCities(2).get(1))); + } +}