Hajj-simulation/tests/StreetTest.java

49 lines
1.2 KiB
Java
Raw Normal View History

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);
}
@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);
}
}