diff --git a/src/edu/kit/informatik/model/ModelRailwaySimulation.java b/src/edu/kit/informatik/model/ModelRailwaySimulation.java index 835d910..d9fb30f 100644 --- a/src/edu/kit/informatik/model/ModelRailwaySimulation.java +++ b/src/edu/kit/informatik/model/ModelRailwaySimulation.java @@ -479,7 +479,7 @@ public class ModelRailwaySimulation { } boolean anyIntersection = occupiedByOtherTrain.stream().anyMatch(occupiedByThisTrain::contains) || occupiedByOtherTrainPreviously.stream().anyMatch(occupiedByThisTrain::contains); - if (anyIntersection) { + if (anyIntersection || train.touches(otherTrain)) { train.removeFromRails(); otherTrain.removeFromRails(); // try to find/merge existing collisions diff --git a/src/edu/kit/informatik/model/Train.java b/src/edu/kit/informatik/model/Train.java index 571d5e8..bde42ed 100644 --- a/src/edu/kit/informatik/model/Train.java +++ b/src/edu/kit/informatik/model/Train.java @@ -357,7 +357,7 @@ public final class Train { * @return whether this train touches the other train */ public boolean touches(final Train other) { - return other.isOnAnyPosition(position); + return position != null && other.isOnAnyPosition(position); } /** @@ -373,7 +373,7 @@ public final class Train { * @return whether this train is on any of the specified positions */ public boolean isOnAnyPosition(final List positions) { - return position.stream().anyMatch(positions::contains); + return position != null && position.stream().anyMatch(positions::contains); } /** diff --git a/testcoverage_input.txt b/testcoverage_input.txt index 348ca84..9377910 100644 --- a/testcoverage_input.txt +++ b/testcoverage_input.txt @@ -170,3 +170,13 @@ create engine steam T5 Worsch 9 true true add train 8 T5-Worsch put train 8 at (0,0) in direction 0,-1 create engine electrical T5 Kühnlein 17 true true +add train 9 T5-Kühnlein +delete track 1 +delete track 2 +delete track 3 +delete track 4 +add track (-100,0) -> (0,0) +add track (0,0) -> (100,0) +put train 8 at (1,0) in direction -1,0 +put train 9 at (-1,0) in direction 1,0 +step 1 diff --git a/testcoverage_output.txt b/testcoverage_output.txt index f7c2ef1..1661274 100644 --- a/testcoverage_output.txt +++ b/testcoverage_output.txt @@ -194,3 +194,13 @@ T5-Worsch steam engine T5-Worsch added to train 8 Error, could not place train T5-Kühnlein +electrical engine T5-Kühnlein added to train 9 +OK +OK +OK +OK +1 +2 +OK +OK +Crash of train 8,9