-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for FingerTree#asList().subList().
- Loading branch information
1 parent
46674f5
commit 740074a
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
reactfx/src/test/java/org/reactfx/util/FingerTreeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.reactfx.util; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
import org.junit.Test; | ||
|
||
public class FingerTreeTest { | ||
|
||
/** | ||
* Returns a random int, with higher probability for larger numbers. | ||
*/ | ||
private static int progressiveInt(Random rnd, int bound) { | ||
double d = rnd.nextDouble(); | ||
d = d*d*d; | ||
int i = (int) Math.floor(d * bound); | ||
return bound - 1 - i; | ||
} | ||
|
||
@Test | ||
public void testSubList() { | ||
final int n = 50000; | ||
|
||
Integer[] arr = new Integer[n]; | ||
for(int i=0; i<n; ++i) arr[i] = i; | ||
|
||
List<Integer> list = Arrays.asList(arr); | ||
List<Integer> treeList = FingerTree.mkTree(list).asList(); | ||
assertEquals(list, treeList); | ||
|
||
Random rnd = new Random(12345); | ||
while(list.size() > 0) { | ||
int len = progressiveInt(rnd, list.size() + 1); | ||
int offset = rnd.nextInt(list.size() - len + 1); | ||
list = list.subList(offset, offset + len); | ||
treeList = treeList.subList(offset, offset + len); | ||
assertEquals(list, treeList); | ||
} | ||
} | ||
|
||
} |