mirror of
https://github.com/davidalves04/Trabalho-Pratico-SD.git
synced 2025-12-08 12:33:31 +00:00
83 lines
2.6 KiB
Java
83 lines
2.6 KiB
Java
import java.io.IOException;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import sd.config.SimulationConfig;
|
|
import sd.model.Intersection;
|
|
import sd.model.TrafficLight;
|
|
import sd.model.TrafficLightState;
|
|
import sd.model.Vehicle;
|
|
import sd.model.VehicleType;
|
|
import sd.util.VehicleGenerator;
|
|
|
|
/**
|
|
* Basic tests for the simulation components.
|
|
*/
|
|
class SimulationTest {
|
|
|
|
@Test
|
|
void testConfigurationLoading() throws IOException {
|
|
SimulationConfig config = new SimulationConfig("src/main/resources/simulation.properties");
|
|
|
|
assertEquals(60.0, config.getSimulationDuration());
|
|
assertEquals("POISSON", config.getArrivalModel());
|
|
assertEquals(0.5, config.getArrivalRate());
|
|
assertEquals(1.0, config.getStatisticsUpdateInterval());
|
|
}
|
|
|
|
@Test
|
|
void testVehicleGeneration() throws IOException {
|
|
SimulationConfig config = new SimulationConfig("src/main/resources/simulation.properties");
|
|
VehicleGenerator generator = new VehicleGenerator(config);
|
|
|
|
Vehicle vehicle = generator.generateVehicle("TEST1", 0.0);
|
|
|
|
assertNotNull(vehicle);
|
|
assertEquals("TEST1", vehicle.getId());
|
|
assertNotNull(vehicle.getType());
|
|
assertNotNull(vehicle.getRoute());
|
|
assertTrue(!vehicle.getRoute().isEmpty());
|
|
}
|
|
|
|
@Test
|
|
void testIntersectionVehicleQueue() {
|
|
Intersection intersection = new Intersection("TestCr");
|
|
TrafficLight light = new TrafficLight("TestCr-N", "North", 30.0, 30.0);
|
|
|
|
intersection.addTrafficLight(light);
|
|
|
|
Vehicle v1 = new Vehicle("V1", VehicleType.LIGHT, 0.0,
|
|
java.util.Arrays.asList("TestCr", "S"));
|
|
|
|
intersection.configureRoute("S", "North");
|
|
|
|
// Advance route to next destination
|
|
v1.advanceRoute();
|
|
|
|
intersection.receiveVehicle(v1);
|
|
|
|
assertEquals(1, intersection.getTotalQueueSize());
|
|
assertEquals(1, intersection.getTotalVehiclesReceived());
|
|
}
|
|
|
|
@Test
|
|
void testTrafficLightStateChange() {
|
|
TrafficLight light = new TrafficLight("Test-Light", "North", 30.0, 30.0);
|
|
|
|
assertEquals(TrafficLightState.RED, light.getState());
|
|
|
|
light.changeState(TrafficLightState.GREEN);
|
|
assertEquals(TrafficLightState.GREEN, light.getState());
|
|
|
|
light.changeState(TrafficLightState.RED);
|
|
assertEquals(TrafficLightState.RED, light.getState());
|
|
}
|
|
|
|
// Removed testSimulationEngineInitialization as SimulationEngine has been
|
|
// removed.
|
|
|
|
}
|