Skip to content

Commit

Permalink
Ensure initialization x is in bounds
Browse files Browse the repository at this point in the history
for x1, we provide an optimistic value based on the computation of x0. It is possible that this x1 is out of bounds but nextValueAt was not checking this property.
  • Loading branch information
adrienmaillard committed Jun 24, 2024
1 parent 5bb1dc1 commit 5f248de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private IteratingResult nextValueAt(
int i = 0;
do {
//we should not come back to previously visited values
if (!history.alreadyVisited(cur)) {
if (!history.alreadyVisited(cur) && cur.between(min, max)) {
i++;
try {
final var value = function.valueAt(cur, history);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public Duration valueAt(
Duration.of(-2, Duration.SECONDS),
twoSecond,
100);
assertEquals(29, solution.history().getHistory().size());
assertEquals(30, solution.history().getHistory().size());
assertEquals(new EquationSolvingAlgorithms.FunctionCoordinate<>(Duration.of(0, Duration.MICROSECONDS), Duration.of(0, Duration.MICROSECONDS)), solution.functionCoordinate());
}

Expand Down Expand Up @@ -164,7 +164,7 @@ public Duration valueAt(
Duration.of(-2, Duration.SECONDS),
twoSecond,
100);
assertEquals(2, solution.history().getHistory().size());
assertEquals(new EquationSolvingAlgorithms.FunctionCoordinate<>(Duration.of(0, Duration.MICROSECONDS), Duration.of(0, Duration.MICROSECONDS)), solution.functionCoordinate());
assertEquals(1, solution.history().getHistory().size());
assertEquals(new EquationSolvingAlgorithms.FunctionCoordinate<>(Duration.of(-860925, Duration.MICROSECONDS), Duration.of(0, Duration.MICROSECONDS)), solution.functionCoordinate());
}
}

0 comments on commit 5f248de

Please sign in to comment.