Пример #1
0
 @Test
 public void testPOLZBSA() {
   int[] answers = {9, 8, 7, 7, 7, 4, 4, 4, 1, 1};
   for (int i = 0, j = 9; i < 10; i++, j--) {
     int result = Util.positionOfLowestZeroBitStartingAt(109L, i);
     //      System.out.printf ("%d %d\n", i, result);
     assert (answers[j] == result);
   }
 }
Пример #2
0
  // a couple of basic unit tests for the histogram construction helper functions.
  @Test
  public void testQuadraticTimeIncrementHistogramCounters() {
    double[] samples = {0.1, 0.2, 0.3, 0.4, 0.5};
    {
      double[] splitPoints = {0.25, 0.4};
      long counters[] = {0, 0, 0};
      long answers[] = {200, 100, 200};
      Util.bilinearTimeIncrementHistogramCounters(samples, 0, 5, 100, splitPoints, counters);
      for (int j = 0; j < counters.length; j++) {
        assert counters[j] == answers[j];
        // System.out.printf ("counter[%d] = %d\n", j, counters[j]);
      }
      // System.out.printf ("\n");
    }

    {
      double[] splitPoints = {0.01, 0.02};
      long counters[] = {0, 0, 0};
      long answers[] = {0, 0, 500};
      Util.bilinearTimeIncrementHistogramCounters(samples, 0, 5, 100, splitPoints, counters);
      for (int j = 0; j < counters.length; j++) {
        assert counters[j] == answers[j];
        // System.out.printf ("counter[%d] = %d\n", j, counters[j]);
      }
      // System.out.printf ("\n");
    }

    {
      double[] splitPoints = {0.8, 0.9};
      long counters[] = {0, 0, 0};
      long answers[] = {500, 0, 0};
      Util.bilinearTimeIncrementHistogramCounters(samples, 0, 5, 100, splitPoints, counters);
      for (int j = 0; j < counters.length; j++) {
        assert counters[j] == answers[j];
        // System.out.printf ("counter[%d] = %d\n", j, counters[j]);
      }
      // System.out.printf ("\n");
    }
  }
Пример #3
0
 /**
  * @param numTries number of tries
  * @param maxArrLen maximum length of array size
  */
 private static void testBlockyTandemMergeSort(int numTries, int maxArrLen) {
   for (int arrLen = 0; arrLen <= maxArrLen; arrLen++) {
     for (int blkSize = 1; blkSize <= arrLen + 100; blkSize++) {
       for (int tryno = 1; tryno <= numTries; tryno++) {
         double[] arr = makeMergeTestInput(arrLen, blkSize);
         long[] brr = makeTheTandemArray(arr);
         assertMergeTestPrecondition(arr, brr, arrLen, blkSize);
         Util.blockyTandemMergeSort(arr, brr, arrLen, blkSize);
         assertMergeTestPostcondition(arr, brr, arrLen);
       }
     }
   }
   // System.out.printf ("Passed: testBlockyTandemMergeSort\n");
 }
Пример #4
0
 @SuppressWarnings("unused")
 private static void exhaustiveMain(String[] args) {
   assert (args.length == 1);
   int numTries = Integer.parseInt(args[0]);
   System.out.printf("Testing blockyTandemMergeSort\n");
   for (int arrLen = 0; true; arrLen++) {
     for (int blkSize = 1; blkSize <= arrLen + 100; blkSize++) {
       System.out.printf(
           "Testing %d times with arrLen = %d and blkSize = %d\n", numTries, arrLen, blkSize);
       for (int tryno = 1; tryno <= numTries; tryno++) {
         double[] arr = makeMergeTestInput(arrLen, blkSize);
         long[] brr = makeTheTandemArray(arr);
         assertMergeTestPrecondition(arr, brr, arrLen, blkSize);
         Util.blockyTandemMergeSort(arr, brr, arrLen, blkSize);
         assertMergeTestPostcondition(arr, brr, arrLen);
       }
     }
   }
 }
Пример #5
0
 @Test
 public void checkNumValidLevels() {
   long v = (1L << 32) - 1L;
   int ones = Util.numValidLevels(v);
   assertEquals(ones, 32);
 }