Skip to content

Commit 7f092b4

Browse files
committed
Bugfix for test when human has same starting and destination floor
1 parent cab3b49 commit 7f092b4

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

Contest/Assignment/test/SanityTest.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,28 @@ private static void verifySnapshotSanity(SimulationSnapshot previousSnapshot,
104104
boolean exitedElevator =
105105
previousState != Human.State.ARRIVED && currentState == Human.State.ARRIVED;
106106
if (exitedElevator) {
107-
assertEquals(Human.State.TRAVELING_WITH_ELEVATOR, previousState,
108-
"When a human exits an elevator, their previous state must be traveling. But '%s' was in state %s.".formatted(
109-
human, previousState));
110-
111-
OptionalInt maybeElevatorId = previousHumanSnapshot.currentElevatorId();
112-
assertTrue(maybeElevatorId.isPresent(), ERROR_MESSAGE_PRE
113-
+ "When a human exits an elevator, they must have had a current elevator id previously. But '%s' does not.".formatted(
114-
human));
115107
assertTrue(currentHumanSnapshot.currentElevatorId().isEmpty(), ERROR_MESSAGE_PRE
116108
+ "When a human exits an elevator, they must not have a current elevator id anymore. But '%s' has.".formatted(
117109
human));
118110

119-
ElevatorSnapshot currentElevatorSnapshot =
120-
currentSnapshot.getElevatorSnapshot(maybeElevatorId.orElseThrow());
121-
assertEquals(human.getDestinationFloor(), currentElevatorSnapshot.currentFloor(),
122-
ERROR_MESSAGE_PRE
123-
+ "When a human exits an elevator, the elevator must be at the humans destination floor. But '%s' exited elevator with ID '%d' at a different floor.".formatted(
124-
human, maybeElevatorId.orElseThrow()));
111+
// Only if the human actually travelled around
112+
if (human.getStartingFloor() != human.getDestinationFloor()) {
113+
assertEquals(Human.State.TRAVELING_WITH_ELEVATOR, previousState,
114+
"When a human exits an elevator, their previous state must be traveling. But '%s' was in state %s.".formatted(
115+
human, previousState));
116+
117+
OptionalInt maybeElevatorId = previousHumanSnapshot.currentElevatorId();
118+
assertTrue(maybeElevatorId.isPresent(), ERROR_MESSAGE_PRE
119+
+ "When a human exits an elevator, they must have had a current elevator id previously. But '%s' does not.".formatted(
120+
human));
121+
122+
ElevatorSnapshot currentElevatorSnapshot =
123+
currentSnapshot.getElevatorSnapshot(maybeElevatorId.orElseThrow());
124+
assertEquals(human.getDestinationFloor(),
125+
currentElevatorSnapshot.currentFloor(), ERROR_MESSAGE_PRE
126+
+ "When a human exits an elevator, the elevator must be at the humans destination floor. But '%s' exited elevator with ID '%d' at a different floor.".formatted(
127+
human, maybeElevatorId.orElseThrow()));
128+
}
125129
}
126130

127131
for (Elevator elevator : simulation.getElevators()) {

0 commit comments

Comments
 (0)