Skip to content

Commit

Permalink
Add test for FingerTree#asList().subList().
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasMikula committed Apr 21, 2016
1 parent 46674f5 commit 740074a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions reactfx/src/test/java/org/reactfx/util/FingerTreeTest.java
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);
}
}

}

0 comments on commit 740074a

Please sign in to comment.