diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 000000000..526b4c25c --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 000000000..a5f05cd8c --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 0d17b9380..61c01743f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,29 +1,45 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 29 - buildToolsVersion "29.0.2" - defaultConfig { - applicationId "com.example.simpleparadox.listycity" - minSdkVersion 15 - targetSdkVersion 29 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.0.2' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' -} +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.2" + defaultConfig { + applicationId "com.example.simpleparadox.listycity" + minSdkVersion 15 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + } +} + +tasks.withType(Test) { + useJUnitPlatform() + testLogging { + exceptionFormat "full" + events "started", "skipped", "passed", "failed" + showStandardStreams true + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.0.1' +} + diff --git a/app/src/androidTest/java/com/example/simpleparadox/listycity/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/simpleparadox/listycity/ExampleInstrumentedTest.java index 14b60b236..8ebda9f57 100644 --- a/app/src/androidTest/java/com/example/simpleparadox/listycity/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/example/simpleparadox/listycity/ExampleInstrumentedTest.java @@ -1,27 +1,28 @@ -package com.example.simpleparadox.listycity; - -import android.content.Context; - -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - - assertEquals("com.example.simpleparadox.listycity", appContext.getPackageName()); - } -} +package com.example.simpleparadox.listycity; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; +//import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.example.simpleparadox.listycity", appContext.getPackageName()); + } +} diff --git a/app/src/main/java/com/example/simpleparadox/listycity/City.java b/app/src/main/java/com/example/simpleparadox/listycity/City.java index fb6fbd1d1..ad43a057c 100644 --- a/app/src/main/java/com/example/simpleparadox/listycity/City.java +++ b/app/src/main/java/com/example/simpleparadox/listycity/City.java @@ -1,19 +1,24 @@ -package com.example.simpleparadox.listycity; - -public class City { - private String city; - private String province; - - City(String city, String province){ - this.city = city; - this.province = province; - } - - String getCityName(){ - return this.city; - } - - String getProvinceName(){ - return this.province; - } -} +package com.example.simpleparadox.listycity; + +public class City implements Comparable{ + private String city; + private String province; + + City(String city, String province){ + this.city = city; + this.province = province; + } + + String getCityName(){ + return this.city; + } + + String getProvinceName(){ + return this.province; + } + + @Override + public int compareTo(City o) { + return city.compareTo(o.getCityName()); + } +} diff --git a/app/src/main/java/com/example/simpleparadox/listycity/CityList.java b/app/src/main/java/com/example/simpleparadox/listycity/CityList.java new file mode 100644 index 000000000..9fe0e0f0d --- /dev/null +++ b/app/src/main/java/com/example/simpleparadox/listycity/CityList.java @@ -0,0 +1,61 @@ +package com.example.simpleparadox.listycity; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * This is a class that keeps track of a list of city objects + */ +public class CityList { + private List cities = new ArrayList<>(); + + /** + * This adds a city to the list if the city does not exist + * @param city + * This is a candidate city to add + */ + public void add(City city) { + if (cities.contains(city)) { + throw new IllegalArgumentException(); + } + cities.add(city); + } + + /** + * This delete a city to the list if the city exists + * @param city + * This is a candidate city to delete + */ + public void delete(City city) { + if (cities.contains(city)) { + cities.remove(city); + + } + else{ + throw new IllegalArgumentException(); + } + + } + + /** + * This returns a sorted list of cities + * @return + * Return the sorted list + */ + public List getCities() { + List list = cities; + Collections.sort(list); + return list; + } + + /** + * This returns a number of cities + * @return + * Return the total sum of city number + */ + public int getCount() { + return cities.size(); + } + +} diff --git a/app/src/test/java/com/example/simpleparadox/listycity/CityListTest.java b/app/src/test/java/com/example/simpleparadox/listycity/CityListTest.java new file mode 100644 index 000000000..54314aec7 --- /dev/null +++ b/app/src/test/java/com/example/simpleparadox/listycity/CityListTest.java @@ -0,0 +1,98 @@ +package com.example.simpleparadox.listycity; + +import org.junit.jupiter.api.Test; + + +import static org.junit.jupiter.api.Assertions.*; + +class CityListTest { + + 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.getCities().size()); + + City city = new City("Regina", "Saskatchewan"); + cityList.add(city); + + assertEquals(2, cityList.getCities().size()); + assertTrue(cityList.getCities().contains(city)); + } + + @Test + void testAddException() { + CityList cityList = mockCityList(); + + City city = new City("Yellowknife", "Northwest Territories"); + cityList.add(city); + + assertThrows(IllegalArgumentException.class, () -> { + cityList.add(city); + }); + } + + @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 testDelete() { + CityList cityList = mockCityList(); + + assertEquals(1, cityList.getCities().size()); + + City city = new City("Edmonton", "Alberta"); + cityList.delete(city); + + assertEquals(0, cityList.getCities().size()); + assertFalse(cityList.getCities().contains(city)); + } + + @Test + void testDeleteException() { + CityList cityList = mockCityList(); + + City city = new City("Yellowknife", "Northwest Territories"); + cityList.delete(city); + + assertThrows(IllegalArgumentException.class, () -> { + cityList.delete(city); + }); + } + @Test + void testGetCount() + { + CityList cityList = mockCityList(); + + assertEquals(0, cityList.getCount()); + + City city = new City("Charlottetown", "Prince Edward Island"); + cityList.add(city); + assertEquals(1, cityList.getCount()); + + City city2 = new City("Yellowknife", "Northwest Territories"); + cityList.add(city2); + assertEquals(2, cityList.getCount()); + } + +} diff --git a/app/src/test/java/com/example/simpleparadox/listycity/ExampleUnitTest.java b/app/src/test/java/com/example/simpleparadox/listycity/ExampleUnitTest.java index b5f0d24f0..6b2be547f 100644 --- a/app/src/test/java/com/example/simpleparadox/listycity/ExampleUnitTest.java +++ b/app/src/test/java/com/example/simpleparadox/listycity/ExampleUnitTest.java @@ -1,17 +1,17 @@ -package com.example.simpleparadox.listycity; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() { - assertEquals(4, 2 + 2); - } +package com.example.simpleparadox.listycity; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 5509623ab..cbff3ccd7 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:7.0.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -25,3 +25,4 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir } + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 36854e580..39b076627 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip diff --git a/index.html b/index.html new file mode 100644 index 000000000..43bba5016 --- /dev/null +++ b/index.html @@ -0,0 +1,373 @@ + + + + + +CityList + + + + + + + + + + + + + + +
+ +
+ +
+
+ +

Class CityList

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • com.example.simpleparadox.listycity.CityList
    • +
    +
  • +
+
+
    +
  • +
    +
    public class CityList
    +extends java.lang.Object
    +
    This is a class that keeps track of a list of city objects
    +
  • +
+
+
+
    +
  • + +
    +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + +
      Constructors 
      ConstructorDescription
      CityList() 
      +
    • +
    +
    + +
    +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voidadd​(com.example.simpleparadox.listycity.City city) +
      This adds a city to the list if the city does not exist
      +
      voiddelete​(com.example.simpleparadox.listycity.City city) +
      This delete a city to the list if the city exists
      +
      java.util.List<com.example.simpleparadox.listycity.City>getCities() +
      This returns a sorted list of cities
      +
      intgetCount() +
      This returns a number of cities
      +
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
    +
  • +
+
+
+
    +
  • + +
    +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        CityList

        +
        public CityList()
        +
      • +
      +
    • +
    +
    + +
    +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        add

        +
        public void add​(com.example.simpleparadox.listycity.City city)
        +
        This adds a city to the list if the city does not exist
        +
        +
        Parameters:
        +
        city - This is a candidate city to add
        +
        +
      • +
      + + + +
        +
      • +

        delete

        +
        public void delete​(com.example.simpleparadox.listycity.City city)
        +
        This delete a city to the list if the city exists
        +
        +
        Parameters:
        +
        city - This is a candidate city to delete
        +
        +
      • +
      + + + +
        +
      • +

        getCities

        +
        public java.util.List<com.example.simpleparadox.listycity.City> getCities()
        +
        This returns a sorted list of cities
        +
        +
        Returns:
        +
        Return the sorted list
        +
        +
      • +
      + + + +
        +
      • +

        getCount

        +
        public int getCount()
        +
        This returns a number of cities
        +
        +
        Returns:
        +
        Return the total sum of city number
        +
        +
      • +
      +
    • +
    +
    +
  • +
+
+
+
+ +
+ +
+ + diff --git a/package-summary.html b/package-summary.html new file mode 100644 index 000000000..e29063670 --- /dev/null +++ b/package-summary.html @@ -0,0 +1,164 @@ + + + + + +com.example.simpleparadox.listycity + + + + + + + + + + + + + + +
+ +
+
+
+

Package com.example.simpleparadox.listycity

+
+
+
    +
  • + + + + + + + + + + + + +
    Class Summary 
    ClassDescription
    CityList +
    This is a class that keeps track of a list of city objects
    +
    +
  • +
+
+
+
+ +
+ + diff --git a/package-tree.html b/package-tree.html new file mode 100644 index 000000000..bf9359e21 --- /dev/null +++ b/package-tree.html @@ -0,0 +1,155 @@ + + + + + +com.example.simpleparadox.listycity Class Hierarchy + + + + + + + + + + + + + + +
+ +
+
+
+

Hierarchy For Package com.example.simpleparadox.listycity

+
+
+
+

Class Hierarchy

+
    +
  • java.lang.Object +
      +
    • com.example.simpleparadox.listycity.CityList
    • +
    +
  • +
+
+
+
+ + +