mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-08 18:00:38 +00:00
Change silly edge case behaviour
This commit is contained in:
parent
0970bfb978
commit
68b28f3c37
@ -19,7 +19,7 @@ add train 1 T1-Alpha
|
||||
add train 2 T1-Beta
|
||||
put train 1 at (0,5) in direction 0,1
|
||||
put train 2 at (0,0) in direction 1,0
|
||||
step 1
|
||||
step 6
|
||||
put train 1 at (0,0) in direction 0,-1
|
||||
set switch 3 position (0,0)
|
||||
put train 1 at (0,0) in direction 0,-1
|
||||
|
@ -23,7 +23,8 @@ steam engine T1-Alpha added to train 1
|
||||
electrical engine T1-Beta added to train 2
|
||||
OK
|
||||
OK
|
||||
Crash of train 1,2
|
||||
Crash of train 1
|
||||
Crash of train 2
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
|
@ -93,6 +93,11 @@ class MainTest {
|
||||
cmpInOut("testcoverage_input.txt", "testcoverage_output.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneLengthDerailEdgecase() throws IOException {
|
||||
cmpInOut("train_one_length_input.txt", "train_one_length_output.txt");
|
||||
}
|
||||
|
||||
private void cmpInOut(String in, String out) throws IOException {
|
||||
System.setIn(new ByteArrayInputStream(readFile(in)));
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
|
@ -236,7 +236,12 @@ public final class TrainManager {
|
||||
|| train.isOnPosition(nextPosition) && !train.getRearPosition().equals(train.getFrontPosition())) {
|
||||
collisions.add(new HashSet<>(Arrays.asList(train)));
|
||||
train.removeFromRails();
|
||||
nextOccupiedRails.put(train, occupiedRails.get(train));
|
||||
// see https://ilias.studium.kit.edu/goto.php?target=frm_996924_138875&client_id=produktiv
|
||||
if (train.getLength() > 1) {
|
||||
nextOccupiedRails.put(train, occupiedRails.get(train));
|
||||
} else {
|
||||
nextOccupiedRails.put(train, null);
|
||||
}
|
||||
} else {
|
||||
train.moveTo(railNetwork, nextPosition);
|
||||
train.setDirection(direction);
|
||||
@ -266,7 +271,12 @@ public final class TrainManager {
|
||||
|| train.isOnPosition(nextPosition) && !train.getRearPosition().equals(train.getFrontPosition())) {
|
||||
collisions.add(new HashSet<>(Arrays.asList(train)));
|
||||
train.removeFromRails();
|
||||
nextOccupiedRails.put(train, occupiedRails.get(train));
|
||||
// see https://ilias.studium.kit.edu/goto.php?target=frm_996924_138875&client_id=produktiv
|
||||
if (train.getLength() > 1) {
|
||||
nextOccupiedRails.put(train, occupiedRails.get(train));
|
||||
} else {
|
||||
nextOccupiedRails.put(train, null);
|
||||
}
|
||||
} else {
|
||||
train.moveBackTo(railNetwork, nextPosition);
|
||||
train.setDirection(front.subtract(train.getFrontPosition()));
|
||||
@ -297,7 +307,7 @@ public final class TrainManager {
|
||||
trains.values().stream().filter(x -> x != train).forEach(otherTrain -> {
|
||||
Set<Rail> occupiedByOtherTrainPreviously = occupiedRails.get(otherTrain);
|
||||
Set<Rail> occupiedByOtherTrain = nextOccupiedRails.get(otherTrain);
|
||||
// if train did not occupy any rails (it is not placed)
|
||||
// if train did not occupy any rails (it is not placed, or just derailed with length 1)
|
||||
if (occupiedByOtherTrain == null) {
|
||||
// skip
|
||||
return;
|
||||
|
13
train_one_length_input.txt
Normal file
13
train_one_length_input.txt
Normal file
@ -0,0 +1,13 @@
|
||||
add track (0,0) -> (5,0)
|
||||
add track (5,0) -> (10,0)
|
||||
create engine diesel T6 Lux 1 true true
|
||||
create engine diesel T6 Lumen 2 false false
|
||||
add train 1 T6-Lux
|
||||
add train 2 T6-Lumen
|
||||
put train 2 at (10,0) in direction 1,0
|
||||
put train 1 at (5,0) in direction 1,0
|
||||
step 1
|
||||
put train 2 at (5,0) in direction 1,0
|
||||
put train 1 at (10,0) in direction 1,0
|
||||
step 1
|
||||
exit
|
13
train_one_length_output.txt
Normal file
13
train_one_length_output.txt
Normal file
@ -0,0 +1,13 @@
|
||||
1
|
||||
2
|
||||
T6-Lux
|
||||
T6-Lumen
|
||||
diesel engine T6-Lux added to train 1
|
||||
diesel engine T6-Lumen added to train 2
|
||||
OK
|
||||
OK
|
||||
Crash of train 1,2
|
||||
OK
|
||||
OK
|
||||
Crash of train 1
|
||||
Train 2 at (6,0)
|
Loading…
Reference in New Issue
Block a user