예제 #1
0
  @Theory
  public void unitLaw(Integer x) {
    Integer left = sumMonoid.multiply(0, x);
    Integer right = sumMonoid.multiply(x, 0);

    assertThat(left, is(x));
    assertThat(right, is(x));
  }
예제 #2
0
 /**
  * Folds this tree using the given monoid.
  *
  * @param f A transformation from this tree's elements, to the monoid.
  * @param m The monoid to fold this tree with.
  * @return The result of folding the tree with the given monoid.
  */
 public <B> B foldMap(final F<A, B> f, final Monoid<B> m) {
   return m.sum(f.f(root()), m.sumRight(subForest()._1().map(foldMap_(f, m)).toList()));
 }
예제 #3
0
 @Theory
 public void sumBinOp(Integer x, Integer y) {
   Integer actual = sumMonoid.multiply(x, y);
   assertThat(actual, is(x + y));
 }
예제 #4
-1
 @Test
 public void sumUnitIsZero() {
   assertThat(sumMonoid.unit(), is(0));
 }