Skip to content

Commit

Permalink
Also check for overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Nov 16, 2023
1 parent 099d65e commit d63c58c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public List<Edge> getEdges() {
}

public Optional<RaptorTransfer> asRaptorTransfer(StreetSearchRequest request) {
return toRaptor(request).filter(s -> s.generalizedCost() < MAX_TRANSFER_RAPTOR_COST);
return toRaptor(request).filter(s -> s.generalizedCost() < MAX_TRANSFER_RAPTOR_COST && s.generalizedCost() >=0);
}

private Optional<RaptorTransfer> toRaptor(StreetSearchRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ void allowLowCost() {
@Nested
class WithoutEdges {

@Test
void overflow() {
var veryLongTransfer = new Transfer(0, Integer.MAX_VALUE);
assertTrue(veryLongTransfer.asRaptorTransfer(StreetSearchRequest.of().build()).isEmpty());
}

@Test
void negativeCost() {
var veryLongTransfer = new Transfer(0, -5);
assertTrue(veryLongTransfer.asRaptorTransfer(StreetSearchRequest.of().build()).isEmpty());
}

@Test
void limitMaxCost() {
var veryLongTransfer = new Transfer(0, 800_000);
Expand Down

0 comments on commit d63c58c

Please sign in to comment.