Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
6ffb71154c | |||
35580a0700 | |||
8eaf53a3ca | |||
58ed0a5df8 | |||
df214053bd | |||
8ff0477873 | |||
04d1de42cf |
@ -4,8 +4,25 @@
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library" scope="TEST">
|
||||
<library name="JUnit5.4">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.4.2/junit-jupiter-5.4.2.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.4.2/junit-jupiter-api-5.4.2.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.1.1/opentest4j-1.1.1.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.4.2/junit-platform-commons-1.4.2.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.4.2/junit-jupiter-params-5.4.2.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.4.2/junit-jupiter-engine-5.4.2.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.4.2/junit-platform-engine-1.4.2.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
78
tests/CampaignTest.java
Normal file
78
tests/CampaignTest.java
Normal file
@ -0,0 +1,78 @@
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CampaignTest {
|
||||
|
||||
private Campaign campaign;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
int numberOfBusses = 50;
|
||||
campaign = new Campaign(District.ALAZIZIYA,
|
||||
numberOfBusses);
|
||||
}
|
||||
|
||||
@Test
|
||||
void VehicleSettersGettersWorkCorrcectly() {
|
||||
ArrayList<Vehicle> oldVehicles = campaign.getVehicles();
|
||||
assertSame(oldVehicles, campaign.getVehicles());
|
||||
ArrayList<Vehicle> newVehicles = new ArrayList<>();
|
||||
for (int i = 0; i < 150; i++) {
|
||||
newVehicles.add(new Bus());
|
||||
}
|
||||
campaign.setVehicles(newVehicles);
|
||||
assertNotSame(oldVehicles, newVehicles);
|
||||
assertSame(campaign.getVehicles(), newVehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
void ConstructorWithNumberOfBusses() {
|
||||
campaign = new Campaign(District.ALAZIZIYA, 60);
|
||||
assertNotNull(campaign.getVehicles());
|
||||
|
||||
ArrayList<Vehicle> list = new ArrayList<>();
|
||||
list.add(new Bus());
|
||||
list.add(new Bus());
|
||||
campaign = new Campaign(District.ALAZIZIYA, list);
|
||||
assertNotNull(campaign.getVehicles());
|
||||
assertEquals(campaign.getVehicles().size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setRouteSetsSameForAllVehicles() {
|
||||
Route r = new Route(new Street[]{new Street(200, 3, StreetNames.FOURTH_HIGHWAY1),
|
||||
new Street(500,2,StreetNames.FOURTH_HIGHWAY3)},District.ALMANSOOR, Mashier.ARAFAT);
|
||||
campaign.setRoute(r);
|
||||
assertSame(campaign.getVehicles().get(5).getRoute(), r);
|
||||
assertSame(campaign.getVehicles().get(0).getRoute(), r);
|
||||
assertSame(campaign.getVehicles().get(22).getRoute(), r);
|
||||
}
|
||||
|
||||
@Test
|
||||
void arrivalFunctionsWorkFine() {
|
||||
ArrayList<Vehicle> buses = new ArrayList<>();
|
||||
buses.add(new Bus());
|
||||
buses.add(new Bus());
|
||||
buses.add(new Bus());
|
||||
buses.add(new Bus());
|
||||
Street s = new Street(500, 3, StreetNames.FOURTH_HIGHWAY3);
|
||||
Route r = new Route(s);
|
||||
for (Vehicle v : buses) {
|
||||
((Bus)v).setCampaign(campaign);
|
||||
v.setCurrentStreet(s);
|
||||
v.setRoute(r);
|
||||
}
|
||||
campaign = new Campaign(District.ALAZIZIYA, buses);
|
||||
assertFalse(campaign.isDone());
|
||||
assertEquals(campaign.getNumberOfArrivedBuses(), 0);
|
||||
assertEquals(campaign.getArrivedVehicles().size(), 0);
|
||||
|
||||
campaign.getVehicles().get(0).arrive();//Vehicle notifies camp
|
||||
assertEquals(campaign.getNumberOfArrivedBuses(), 1);
|
||||
assertEquals(campaign.getArrivedVehicles().size(), 1);
|
||||
}
|
||||
}
|
60
tests/StreetTest.java
Normal file
60
tests/StreetTest.java
Normal file
@ -0,0 +1,60 @@
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class StreetTest {
|
||||
|
||||
private Street street;
|
||||
private double length = 100;
|
||||
|
||||
//length of street x number of lanes;
|
||||
private double totalLength = 300;
|
||||
|
||||
private int lanes = 3;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
street = new Street(length, lanes,StreetNames.FOURTH_HIGHWAY1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void correctLengthIsSet() {
|
||||
assertEquals(street.getLength(), length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void correctCombinedLengthCalculation() {
|
||||
double tLength = street.getCombinedLength();
|
||||
assertEquals(length*lanes, tLength);
|
||||
}
|
||||
|
||||
@Test
|
||||
void addVehicleToNewStreet() {
|
||||
Vehicle sedan = new Sedan(3);
|
||||
street.addVehicle(sedan);
|
||||
assertEquals(street.getVehicles().get(0), sedan);
|
||||
}
|
||||
|
||||
@Test
|
||||
void cantAddVehiclesOverCapacity() {
|
||||
Vehicle v = new Sedan(3);
|
||||
while (street.canTakeVehicles(v)){
|
||||
street.addVehicle(new Sedan(3));
|
||||
}
|
||||
boolean canTakeCars = street.canTakeVehicles(new Sedan(3));
|
||||
int cars = street.getVehicles().size();
|
||||
assertFalse(canTakeCars);
|
||||
}
|
||||
|
||||
@Test
|
||||
void capacityPointReasonable() {
|
||||
Vehicle v = new Bus();
|
||||
street.addVehicle(v);
|
||||
v.setCurrentStreet(street);
|
||||
v.move(200);
|
||||
//1 is full or crowded
|
||||
assertTrue(street.capcityPoint(0, v.getCurrentLocation()) < 0.8);
|
||||
assertTrue(street.capcityPoint(0, v.getCurrentLocation()) < 0.4);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user