Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 45 additions & 29 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}

Original file line number Diff line number Diff line change
@@ -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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@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());
}
}
43 changes: 24 additions & 19 deletions app/src/main/java/com/example/simpleparadox/listycity/City.java
Original file line number Diff line number Diff line change
@@ -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<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;
}

@Override
public int compareTo(City o) {
return city.compareTo(o.getCityName());
}
}
Original file line number Diff line number Diff line change
@@ -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<City> 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<City> getCities() {
List<City> 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();
}

}
Original file line number Diff line number Diff line change
@@ -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());
}

}
Loading