Skip to content

Commit

Permalink
Add in-contract for better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
klasbo committed Mar 27, 2022
1 parent fe925b5 commit 4b5fc21
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cost_fns/hall_request_assigner/optimal_hall_requests.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ import std.stdio;
bool[][][string] optimalHallRequests(
bool[2][] hallReqs,
LocalElevatorState[string] elevatorStates,
){
)
in {
auto numFloors = hallReqs.length;
assert(elevatorStates.length,
"No elevator states provided");
assert(elevatorStates.values.map!(a => a.cabRequests.length == numFloors).all,
"Hall and cab requests do not all have the same length");
bool isInBounds(int f){ return f >= 0 && f < numFloors; }
assert(elevatorStates.values.map!(a => isInBounds(a.floor)).all,
"Some elevator is at an invalid floor");
assert(elevatorStates.values.map!(a => isInBounds(a.floor + a.direction)).all,
"Some elevator is moving away from an end floor");
}
do {
auto reqs = hallReqs.toReq;
auto states = initialStates(elevatorStates);

Expand Down

0 comments on commit 4b5fc21

Please sign in to comment.