Skip to content

Commit 36fbc29

Browse files
committed
Fix #1030 (related to #982)
1 parent 1a03a95 commit 36fbc29

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

solver/src/main/java/org/chocosolver/util/objects/setDataStructures/iterable/IntIterableSetUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,11 @@ public static void union(IntIterableRangeSet setr, IntIterableRangeSet set1, Int
425425
int s2 = set2.SIZE >> 1;
426426
if(s1 == 0){
427427
setr.addAll(set2);
428+
return;
428429
}
429430
if (s2 == 0) {
430431
setr.addAll(set1);
432+
return;
431433
}
432434
if (s1 > 0 && s2 > 0) {
433435
setr.grow(set1.SIZE);
@@ -494,7 +496,10 @@ public static boolean unionOf(IntIterableRangeSet set1, IntIterableRangeSet set2
494496
if(s1 == 0){
495497
return set1.addAll(set2);
496498
}
497-
if (s1 > 0 && s2 >= 0) {
499+
if(s2 == 0){
500+
return false;
501+
}
502+
if (s1 > 0 && s2 > 0) {
498503
int i = 0, j = 0;
499504
int s = 0, c = 0;
500505
int[] e = new int[set1.SIZE];

solver/src/test/java/org/chocosolver/util/objects/setDataStructures/iterable/IntIterableRangeSetTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,15 @@ public void testUnion5() {
704704
Assert.assertEquals(set.size(), 1);
705705
}
706706

707+
@Test(groups = "1s", timeOut = 60000)
708+
public void testUnion6() {
709+
IntIterableRangeSet set = new IntIterableRangeSet(1, 2);
710+
IntIterableSetUtils.unionOf(set, new IntIterableRangeSet());
711+
Assert.assertEquals(set.size(), 2);
712+
}
713+
714+
715+
707716
@Test(groups = "1s", timeOut = 60000)
708717
public void testIncludedIn1() {
709718
Assert.assertTrue(IntIterableSetUtils.includedIn(new IntIterableRangeSet(), new IntIterableRangeSet(0)));

0 commit comments

Comments
 (0)