diff --git a/reactfx/src/test/java/org/reactfx/util/FingerTreeTest.java b/reactfx/src/test/java/org/reactfx/util/FingerTreeTest.java new file mode 100644 index 0000000..ce9e61b --- /dev/null +++ b/reactfx/src/test/java/org/reactfx/util/FingerTreeTest.java @@ -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 list = Arrays.asList(arr); + List 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); + } + } + +}