@Test public void shouldFlatMapArbitrary() { final Arbitrary<Integer> arbitraryInt = size -> Gen.choose(-size, size); final Arbitrary<BinaryTree<Integer>> arbitraryTree = arbitraryInt.flatMap(i -> new ArbitraryBinaryTree(-i, i)); assertThat(arbitraryTree.apply(0).apply(new Random())).isNotNull(); }

@Test(expected = RuntimeException.class) public void shouldThrowOnForEach() { Arbitrary.integer() .forEach( i -> { throw new RuntimeException("OK"); }); }

@Test public void shouldNotBeEmpty() { assertThat(Arbitrary.integer().isEmpty()).isFalse(); }

@Test public void shouldPeekArbitrary() { final int[] actual = new int[] {Integer.MIN_VALUE}; final int expected = Arbitrary.integer().peek(i -> actual[0] = i).apply(10).apply(new Random()); assertThat(actual[0]).isEqualTo(expected); }

@Test public void shouldThrowOnForAll() { Arbitrary.integer().forAll(i -> false); }

@Test public void shouldThrowOnExists() { Arbitrary.integer().exists(i -> true); }

@Test public void shouldFlatteningArbitraryIntegerUsingFunction() { final Arbitrary<Arbitrary<Integer>> testee = size -> random -> Arbitrary.integer(); assertThat(testee.flatten().apply(1).apply(new Random())).isNotNull(); }

@Test public void shouldFilterArbitrary() { final Arbitrary<Integer> ints = Arbitrary.integer(); final Arbitrary<Integer> evenInts = ints.filter(i -> i % 2 == 0); assertThat(evenInts.apply(10).apply(new Random())).isNotNull(); }

@Test public void shouldMapArbitrary() { final Arbitrary<Integer> arbitraryInt = size -> Gen.choose(-size, size); final Arbitrary<BinaryTree<Integer>> arbitraryTree = arbitraryInt.map(BinaryTree::leaf); assertThat(arbitraryTree.apply(0).apply(new Random())).isNotNull(); }

@Test public void shouldCreateArbitraryStream() { final Arbitrary<Stream<Integer>> arbitrary = Arbitrary.stream(Arbitrary.integer()); final Stream<Integer> actual = arbitrary.apply(10).apply(new Random()); assertThat(actual).isNotNull(); }

@Test public void shouldCreateArbitraryList() { final Arbitrary<List<Integer>> arbitrary = Arbitrary.list(Arbitrary.integer()); final List<Integer> actual = arbitrary.apply(10).apply(new Random()); assertThat(actual).isNotNull(); }

@Test public void shouldCreateArbitraryString() { final Arbitrary<String> arbitrary = Arbitrary.string(Gen.choose('a', 'z')); final String actual = arbitrary.apply(10).apply(new Random()); assertThat(actual).isNotNull(); }