@Test
 public void valuesToArray() {
   HazelcastClient hClient = getHazelcastClient();
   IMap map = hClient.getMap("valuesToArray");
   assertEquals(0, map.size());
   map.put("a", "1");
   map.put("b", "2");
   map.put("c", "3");
   assertEquals(3, map.size());
   {
     final Object[] values = map.values().toArray();
     Arrays.sort(values);
     assertArrayEquals(new Object[] {"1", "2", "3"}, values);
   }
   {
     final String[] values = (String[]) map.values().toArray(new String[3]);
     Arrays.sort(values);
     assertArrayEquals(new String[] {"1", "2", "3"}, values);
   }
   {
     final String[] values = (String[]) map.values().toArray(new String[2]);
     Arrays.sort(values);
     assertArrayEquals(new String[] {"1", "2", "3"}, values);
   }
   {
     final String[] values = (String[]) map.values().toArray(new String[5]);
     Arrays.sort(values, 0, 3);
     assertArrayEquals(new String[] {"1", "2", "3", null, null}, values);
   }
 }
 @Test
 public void testNnclean() throws Exception {
   double[] y = HET_DEL_5X_5N;
   double[] nonnoise =
       new double[] {260.0736, 197.4272, 194.8618, 1217.8588, 1228.2190, 1151.7017};
   double[] result = scorer.nnclean(y, scorer.cleanYIndices(y, 30, 2, 5));
   Arrays.sort(result);
   Arrays.sort(nonnoise);
   assertArrayEquals(nonnoise, result, 0.000001);
 }
  @Test(timeout = TIMEOUT)
  public void testRadixSort() {
    int[] arrZero = new int[0];
    arrZero = Sorting.radixSort(arrZero);
    assertEquals(0, arrZero.length);
    int[] arrOne = new int[1];
    arrOne[0] = 4;
    arrOne = Sorting.radixSort(arrOne);
    assertEquals(1, arrOne.length);
    assertEquals(4, arrOne[0]);

    Random rand = new Random();
    for (int i = 0; i < 50; i++) {
      int arrlen = rand.nextInt(1000) + 2;
      int[] arrMany = new int[arrlen];
      int[] arrManySorted = new int[arrlen];
      for (int j = 0; j < arrlen; j++) {
        arrMany[j] = rand.nextInt(200) - 90;
      }
      System.arraycopy(arrMany, 0, arrManySorted, 0, arrlen);
      Arrays.sort(arrManySorted);
      arrMany = Sorting.radixSort(arrMany);
      assertArrayEquals(arrManySorted, arrMany);
    }
  }
  @Test(timeout = TIMEOUT)
  public void testQuickSort() {
    DValue[] arrZero = new DValue[0];
    Sorting.quickSort(arrZero, new BasicComparator(), new Random());
    assertEquals(0, arrZero.length);
    DValue[] arrOne = new DValue[1];
    arrOne[0] = new DValue(4, 0);
    Sorting.quickSort(arrOne, new BasicComparator(), new Random());
    assertEquals(1, arrOne.length);
    assertEquals(4, arrOne[0].val.intValue());

    Random rand = new Random();
    HashMap<Integer, Integer> values = new HashMap<Integer, Integer>();
    for (int i = 0; i < 50; i++) {
      int arrlen = rand.nextInt(1000) + 2;
      DValue[] arrMany = new DValue[arrlen];
      DValue[] arrManySorted = new DValue[arrlen];
      for (int j = 0; j < arrlen; j++) {
        arrMany[j] = new DValue(rand.nextInt(200) - 90, 0);
        if (values.containsKey(arrMany[j].val)) {
          arrMany[j].count = values.get(arrMany[j].val) + 1;
          values.put(arrMany[j].val, arrMany[j].count);
        } else {
          values.put(arrMany[j].val, 0);
        }
      }
      System.arraycopy(arrMany, 0, arrManySorted, 0, arrlen);
      Arrays.sort(arrManySorted);
      Sorting.quickSort(arrMany, new BasicComparator(), new Random());
      assertArrayEquals(arrManySorted, arrMany);
    }
  }
예제 #5
0
파일: SourceTest.java 프로젝트: hochgi/akka
  @SuppressWarnings("unchecked")
  @Test
  public void mustBeAbleToUseGroupBy() throws Exception {
    final Iterable<String> input = Arrays.asList("Aaa", "Abb", "Bcc", "Cdd", "Cee");
    final Source<List<String>, NotUsed> source =
        Source.from(input)
            .groupBy(
                3,
                new Function<String, String>() {
                  public String apply(String elem) {
                    return elem.substring(0, 1);
                  }
                })
            .grouped(10)
            .mergeSubstreams();

    final CompletionStage<List<List<String>>> future =
        source.grouped(10).runWith(Sink.<List<List<String>>>head(), materializer);
    final Object[] result = future.toCompletableFuture().get(1, TimeUnit.SECONDS).toArray();
    Arrays.sort(
        result,
        (Comparator<Object>)
            (Object)
                new Comparator<List<String>>() {
                  @Override
                  public int compare(List<String> o1, List<String> o2) {
                    return o1.get(0).charAt(0) - o2.get(0).charAt(0);
                  }
                });

    assertArrayEquals(
        new Object[] {
          Arrays.asList("Aaa", "Abb"), Arrays.asList("Bcc"), Arrays.asList("Cdd", "Cee")
        },
        result);
  }