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.

1 change: 1 addition & 0 deletions .idea/.name

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

6 changes: 6 additions & 0 deletions .idea/compiler.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.

9 changes: 9 additions & 0 deletions .idea/misc.xml

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

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