Exemplo n.º 1
0
  @Test
  public void test_construction_permutations() {
    for (int a = 0; a < 6; a++) {
      compare_order(newSet(a), setOf(a));
      for (int b = 0; b < 6; b++) {
        compare_order(newSet(a, b), setOf(a, b));
        for (int c = 0; c < 6; c++) {
          compare_order(newSet(a, b, c), setOf(a, b, c));
          for (int d = 0; d < 6; d++) {
            compare_order(newSet(a, b, c, d), setOf(a, b, c, d));
            for (int e = 0; e < 6; e++) {
              compare_order(newSet(a, b, c, d, e), setOf(a, b, c, d, e));
              for (int f = 0; f < 6; f++) {
                Integer[] elements = new Integer[] {a, b, c, d, e, f};
                Set<Integer> expected = newSet(elements);
                Collection<Integer> collection = Arrays.asList(elements);

                // setOf
                compare_order(expected, setOf(a, b, c, d, e, f));
                // asSet(array)
                compare_order(expected, asSet(elements));
                // asSet(collection)
                compare_order(expected, asSet(collection));
                // asSet(iterator)
                compare_order(expected, asSet(collection.iterator()));
              }
            }
          }
        }
      }
    }
  }
Exemplo n.º 2
0
  @Test
  public void test_asSet_collection() {
    assertSame(emptySet(), asSet(Arrays.asList()));
    compare_sets(newSet(1), asSet(Arrays.asList(1)));
    compare_sets(newSet(1, 2), asSet(Arrays.asList(1, 2)));
    compare_sets(newSet(1, 2, 3), asSet(Arrays.asList(1, 2, 3)));
    compare_sets(newSet(1, 2, 3, 4), asSet(Arrays.asList(1, 2, 3, 4)));
    compare_sets(newSet(1, 2, 3, 4, 5), asSet(Arrays.asList(1, 2, 3, 4, 5)));
    compare_sets(newSet(1, 2, 3, 4, 5, 6), asSet(Arrays.asList(1, 2, 3, 4, 5, 6)));

    // ConstSet should just be returned as-is.
    ConstSet<Integer> set;
    set = setOf(1);
    assertSame(set, asSet(set));
    set = setOf(1, 2);
    assertSame(set, asSet(set));
    set = setOf(1, 2, 3);
    assertSame(set, asSet(set));
    set = setOf(1, 2, 3, 4, 5, 6, 7, 8, 9);
    assertSame(set, asSet(set));

    // However, ConstSortedSet should be converted to a regular ConstSet.
    set = sortedSetOf(null, 1);
    assertNotSame(set, asSet(set));
  }
Exemplo n.º 3
0
 @Test
 public void test_asSet_collection_types() {
   assertEquals(BasicSet1.class, asSet(Arrays.asList(1)).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2)).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3)).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4)).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4, 5)).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4, 5, 6)).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7)).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8)).getClass());
 }
Exemplo n.º 4
0
 @Test
 public void test_asSet_iterator_types() {
   assertEquals(BasicSet1.class, asSet(Arrays.asList(1).iterator()).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2).iterator()).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3).iterator()).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4).iterator()).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4, 5).iterator()).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4, 5, 6).iterator()).getClass());
   assertEquals(BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7).iterator()).getClass());
   assertEquals(
       BasicSetN.class, asSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8).iterator()).getClass());
 }
Exemplo n.º 5
0
 @Test
 public void test_asSet_iterator() {
   assertSame(emptySet(), asSet(Arrays.asList().iterator()));
   compare_sets(newSet(1), asSet(Arrays.asList(1).iterator()));
   compare_sets(newSet(1, 2), asSet(Arrays.asList(1, 2).iterator()));
   compare_sets(newSet(1, 2, 3), asSet(Arrays.asList(1, 2, 3).iterator()));
   compare_sets(newSet(1, 2, 3, 4), asSet(Arrays.asList(1, 2, 3, 4).iterator()));
   compare_sets(newSet(1, 2, 3, 4, 5), asSet(Arrays.asList(1, 2, 3, 4, 5).iterator()));
   compare_sets(newSet(1, 2, 3, 4, 5, 6), asSet(Arrays.asList(1, 2, 3, 4, 5, 6).iterator()));
 }