@Test public void testGetSum() { int n = 2000; long[] A = randomArray(n); FenwickTree fw = fenwickTree(A); for (int i = 0, cumul = 0; i < A.length; i++) { cumul += A[i]; assertEquals(cumul, fw.getSum(i + 1)); } }
@Test public void testFindHigherValueIndex() { int n = 500; long[] A = randomArray(n); FenwickTree fw = fenwickTree(A); for (int i = 0; i < A.length; i++) { long sum = fw.getSum(i + 1); assertEquals(findHigherSumIndex(A, sum) + 1, fw.findHigherSumIndex(sum)); } long sum = 10000000; assertEquals(findHigherSumIndex(A, sum) + 1, fw.findHigherSumIndex(sum)); sum = -10000000; assertEquals(findHigherSumIndex(A, sum) + 1, fw.findHigherSumIndex(sum)); }