mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-24 01:15:05 +00:00
Correctly derail
This commit is contained in:
parent
0cf7368997
commit
9191028934
10
fuzz8_input.txt
Normal file
10
fuzz8_input.txt
Normal file
@ -0,0 +1,10 @@
|
||||
add track (0,0) -> (0,14)
|
||||
create engine diesel T3 Sabine 1 false true
|
||||
add train 1 T3-Sabine
|
||||
put train 1 at (0,0) in direction 0,-1
|
||||
step -20
|
||||
create coach passenger 1 true false
|
||||
add train 1 W1
|
||||
put train 1 at (0,0) in direction 0,-1
|
||||
step -20
|
||||
exit
|
9
fuzz8_output.txt
Normal file
9
fuzz8_output.txt
Normal file
@ -0,0 +1,9 @@
|
||||
1
|
||||
T3-Sabine
|
||||
diesel engine T3-Sabine added to train 1
|
||||
OK
|
||||
Crash of train 1
|
||||
1
|
||||
passenger coach W1 added to train 1
|
||||
OK
|
||||
Crash of train 1
|
@ -68,6 +68,11 @@ class MainTest {
|
||||
cmpInOut("fuzz7_input.txt", "fuzz7_output.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fuzz8() throws IOException {
|
||||
cmpInOut("fuzz8_input.txt", "fuzz8_output.txt");
|
||||
}
|
||||
|
||||
private void cmpInOut(String in, String out) throws IOException {
|
||||
System.setIn(new ByteArrayInputStream(readFile(in)));
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
|
@ -301,8 +301,11 @@ public final class Train {
|
||||
} else if (getLength() == 1) {
|
||||
// we evidently just moved into another rail
|
||||
Rail[] nextTouchingRails = railNetwork.findTouchingRails(nextPosition);
|
||||
Rail[] alreadyTouchingRails = railNetwork.findTouchingRails(position.get(position.size() - 1));
|
||||
if (nextTouchingRails[0] == alreadyTouchingRails[0]) {
|
||||
Rail[] alreadyTouchingRails = railNetwork.findTouchingRails(secondToLastPosition);
|
||||
if (alreadyTouchingRails.length == 0) {
|
||||
// we evidently just derailed, be we should still crash with trains entering our last rail
|
||||
assert !occupiedRails.isEmpty();
|
||||
} else if (nextTouchingRails[0] == alreadyTouchingRails[0]) {
|
||||
occupiedRails.add(nextTouchingRails[0]);
|
||||
} else if (nextTouchingRails.length == 2) {
|
||||
if (nextTouchingRails[1] == alreadyTouchingRails[0]) {
|
||||
|
Loading…
Reference in New Issue
Block a user