@Test public void associativityUninitialised(){ int a = 10; LazyImmutable<Integer> m = new LazyImmutable<Integer>(); Function<Integer,LazyImmutable<Integer> >f = i->LazyImmutable.of(i+10); Function<Integer,LazyImmutable<Integer> >g = i->LazyImmutable.of(i*10); assertThat(m.<Integer>flatMap(f).<Integer>flatMap(g), equalTo( m.<Integer>flatMap(x -> f.apply(x).flatMap(g)))); } }
@Test public void associativity(){ int a = 10; LazyImmutable<Integer> m = LazyImmutable.of(a); Function<Integer,LazyImmutable<Integer> >f = i->LazyImmutable.of(i+10); Function<Integer,LazyImmutable<Integer> >g = i->LazyImmutable.of(i*10); assertThat(m.flatMap(f).flatMap(g).get(), equalTo( m.flatMap(x -> f.apply(x).flatMap(g)).get())); }
@Test public void testRightIdentityUninitialised(){ LazyImmutable<Integer> m = new LazyImmutable<Integer>(); assertThat(m.<Integer>flatMap(LazyImmutable::of), equalTo( m)); } @Test
@Test public void testFlatMapUninitialised(){ LazyImmutable<Integer> value = new LazyImmutable<Integer>(); LazyImmutable<? extends Integer> value2 = value.flatMap(i -> LazyImmutable.of(i + 10)); assertThat(value,equalTo(value2)); } @Test
@Test public void testLeftIdentity(){ int a = 10; Function<Integer,LazyImmutable<Integer> >f = i->LazyImmutable.of(i+10); assertThat(LazyImmutable.of(a).flatMap(f).get(), equalTo( f.apply(10).get())); } @Test
@Test public void testRightIdentity(){ int a = 10; LazyImmutable<Integer> m = LazyImmutable.of(a); assertThat(m.flatMap(LazyImmutable::of).get(), equalTo( m.get())); } @Test
@Test public void testFlatMap2(){ LazyImmutable<Integer> value = new LazyImmutable<Integer>(); value.setOnce(10); LazyImmutable<? extends Integer> value2 = value.flatMap(i -> LazyImmutable.of(i + 10)); assertThat(value2.get(),equalTo(20)); } @Test