From ba6a939a92920894251280d5509d32a7b16b4de0 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Wed, 19 Feb 2020 08:37:36 +0100 Subject: [PATCH] Only place trains if all switches are set --- fuzz1_input.txt | 3 +++ fuzz1_output.txt | 3 +++ fuzz3_output.txt | 2 +- src/edu/kit/informatik/model/ModelRailwaySimulation.java | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fuzz1_input.txt b/fuzz1_input.txt index 7bac73e..e3cd86a 100644 --- a/fuzz1_input.txt +++ b/fuzz1_input.txt @@ -4,6 +4,7 @@ add track (0,15) -> (1,15) add track (1,1) -> (1,14) add switch (1,14) -> (0,14),(1,0) set switch 5 positio (1,0) +set switch 2 position (1,0) create engine diesel T3 Emma 1 false true add train 1 T3-Emma create coach passenger 1906 true true @@ -13,6 +14,8 @@ add train 1 W1 add train 1 W2 add train 1 W3 put train 1 at (0,0) in direction 0,-1 +delete track 2 +add switch (1,14) -> (0,14),(1,0) step -20 step 20 set switch 5 position (0,14) diff --git a/fuzz1_output.txt b/fuzz1_output.txt index 429140f..bed269d 100644 --- a/fuzz1_output.txt +++ b/fuzz1_output.txt @@ -4,6 +4,7 @@ Error, track is not connected to other tracks Error, track is not connected to other tracks 2 Error, invalid set switch argument syntax +OK T3-Emma diesel engine T3-Emma added to train 1 1 @@ -13,6 +14,8 @@ passenger coach W1 added to train 1 passenger coach W2 added to train 1 Error, could not add rolling stock to train Error, could not place train +OK +2 Error, rail tracks/switches not set up Error, rail tracks/switches not set up Error, could not set switch diff --git a/fuzz3_output.txt b/fuzz3_output.txt index 9b743b7..6441206 100644 --- a/fuzz3_output.txt +++ b/fuzz3_output.txt @@ -9,4 +9,4 @@ diesel engine T3-Emma added to train 1 freight coach W1 added to train 1 special coach W2 added to train 1 passenger coach W3 added to train 1 -Error, could not place train +Error, switches not set up diff --git a/src/edu/kit/informatik/model/ModelRailwaySimulation.java b/src/edu/kit/informatik/model/ModelRailwaySimulation.java index 487fd02..835d910 100644 --- a/src/edu/kit/informatik/model/ModelRailwaySimulation.java +++ b/src/edu/kit/informatik/model/ModelRailwaySimulation.java @@ -384,6 +384,8 @@ public class ModelRailwaySimulation { throw new InvalidInputException("train is already placed"); } else if (direction.getX() != 0 && direction.getY() != 0) { throw new InvalidInputException("invalid train direction"); + } else if (!railNetwork.isReadyForTrains()) { + throw new InvalidInputException("switches not set up"); } // attempt to place train boolean placed = train.placeOn(railNetwork, position, direction);