From 740074ad699960767d4950c90f622b255036b7f7 Mon Sep 17 00:00:00 2001 From: Tomas Mikula Date: Thu, 21 Apr 2016 14:25:55 -0400 Subject: [PATCH] Add test for FingerTree#asList().subList(). --- .../java/org/reactfx/util/FingerTreeTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 reactfx/src/test/java/org/reactfx/util/FingerTreeTest.java 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); + } + } + +}