コード例 #1
0
 @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));
   }
 }
コード例 #2
0
 @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));
 }