Skip to content

Commit

Permalink
fixed overflow issue in Set.removal tests and cleaned up usage of str…
Browse files Browse the repository at this point in the history
…eams
  • Loading branch information
jurgenvinju committed Sep 12, 2023
1 parent f8363ca commit 4b3a800
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISourceLocation;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.ValueProvider;

public class SetTests {
Expand All @@ -34,12 +35,12 @@ public void insertion( @ExpectedType("set[real]") ISet set, IInteger i) {
}

@ParameterizedTest @ArgumentsSource(ValueProvider.class)
public void removal( @ExpectedType("set[int]") ISet set, IInteger i) {
public void removal(Random rnd, IValueFactory vf, @ExpectedType("set[int]") ISet set) {
if (set.isEmpty()) {
return;
}

IValue elem = StreamSupport.stream(set.spliterator(), false).skip(Math.abs(i.intValue() % set.size())).findFirst().get();
int index = rnd.nextInt(set.size());
IValue elem = set.stream().skip(index).findFirst().get();
ISet smaller = set.delete(elem);
assertEquals(smaller.size() + 1, set.size());
assertTrue(!smaller.contains(elem));
Expand All @@ -51,7 +52,8 @@ public void removalLocations(Random rnd, @ExpectedType("set[loc]") ISet set, ISo
return;
}

IValue elem = StreamSupport.stream(set.spliterator(), false).skip(rnd.nextInt(set.size())).findFirst().get();
int index = rnd.nextInt(set.size());
IValue elem = set.stream().skip(index).findFirst().get();
ISet smaller = set.delete(elem);
assertEquals(smaller.size() + 1, set.size());
assertTrue(!smaller.contains(elem));
Expand Down

0 comments on commit 4b3a800

Please sign in to comment.