mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-24 01:15:05 +00:00
Fix NPE
This commit is contained in:
parent
4ffb3a5665
commit
fdedb5e001
16
fuzz7_input.txt
Normal file
16
fuzz7_input.txt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# create three rails
|
||||||
|
add track (0,2) -> (0,0)
|
||||||
|
add track (0,0) -> (0,-2)
|
||||||
|
add track (65535,-128) -> (0,-4)
|
||||||
|
delete track 2
|
||||||
|
delete track 1
|
||||||
|
delete track 2
|
||||||
|
delete track 3
|
||||||
|
# try to delete track under train
|
||||||
|
add track (-5,0) -> (0,0)
|
||||||
|
add track (0,0) -> (5,0)
|
||||||
|
create engine diesel ABC DEF 1 true true
|
||||||
|
add train 1 ABC-DEF
|
||||||
|
put train 255 at (0,0) in direction 1,0
|
||||||
|
delete track 1
|
||||||
|
exit
|
13
fuzz7_output.txt
Normal file
13
fuzz7_output.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
1
|
||||||
|
2
|
||||||
|
Error, invalid track segment: not a straight line
|
||||||
|
OK
|
||||||
|
OK
|
||||||
|
Error, could not delete rail segment
|
||||||
|
Error, could not delete rail segment
|
||||||
|
1
|
||||||
|
2
|
||||||
|
ABC-DEF
|
||||||
|
diesel engine ABC-DEF added to train 1
|
||||||
|
Error, could not place train
|
||||||
|
OK
|
@ -63,6 +63,11 @@ class MainTest {
|
|||||||
cmpInOut("fuzz6_input.txt", "fuzz6_output.txt");
|
cmpInOut("fuzz6_input.txt", "fuzz6_output.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void fuzz7() throws IOException {
|
||||||
|
cmpInOut("fuzz7_input.txt", "fuzz7_output.txt");
|
||||||
|
}
|
||||||
|
|
||||||
private void cmpInOut(String in, String out) throws IOException {
|
private void cmpInOut(String in, String out) throws IOException {
|
||||||
System.setIn(new ByteArrayInputStream(readFile(in)));
|
System.setIn(new ByteArrayInputStream(readFile(in)));
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
|
@ -41,7 +41,7 @@ public class ModelRailwaySimulation {
|
|||||||
*/
|
*/
|
||||||
public boolean removeRail(final int id) {
|
public boolean removeRail(final int id) {
|
||||||
// check whether any trains are on this rail
|
// check whether any trains are on this rail
|
||||||
if (trains.stream().anyMatch(train -> train.isOnRail(id))) {
|
if (trains.stream().anyMatch(train -> train.isPlaced() && train.isOnRail(id))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return railNetwork.removeRail(id);
|
return railNetwork.removeRail(id);
|
||||||
|
@ -107,7 +107,7 @@ public final class Train {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean isOnRail(final int id) {
|
public boolean isOnRail(final int id) {
|
||||||
return occupiedRails.stream().anyMatch(rail -> rail.getIdentifier() == id);
|
return occupiedRails != null && occupiedRails.stream().anyMatch(rail -> rail.getIdentifier() == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user