Example #1
1
  @Test
  public void split() {
    // do the split
    int pivot = 4;
    int max = 5;
    List<Integer> l = List.range(1, max + 1);
    TreeMap<Integer, String> m2 = TreeMap.treeMap(Ord.intOrd, l.zip(l.map(i -> i.toString())));
    P3<Set<String>, Option<String>, Set<String>> p = m2.split(Ord.stringOrd, pivot);

    // print debug info
    Show<TreeMap<Integer, String>> st = Show.treeMapShow(Show.intShow, Show.stringShow);
    Show<Set<String>> ss = Show.setShow(Show.stringShow);
    Show<Option<String>> so = Show.optionShow(Show.stringShow);
    Show<P3<Set<String>, Option<String>, Set<String>>> sp3 = Show.p3Show(ss, so, ss);
    if (true) {
      st.println(m2);
      sp3.println(p);
    }

    // assert equals
    Equal<Set<String>> seq = Equal.setEqual(Equal.stringEqual);
    Set<String> left = toSetString(List.range(1, pivot));
    Set<String> right = toSetString(List.range(pivot + 1, max + 1));
    P3<Set<String>, Option<String>, Set<String>> expected =
        p(left, some(Integer.toString(pivot)), right);
    assertTrue(Equal.p3Equal(seq, Equal.optionEqual(Equal.stringEqual), seq).eq(p, expected));
  }