TheoryRunner { public void check(final Predicate<T> property) { final SearchResult<T> results = runSearch(property); if (results.isFalsified()) { reportFalsification(results); } else if (results.wasExhausted()) { this.strategy.reporter().valuesExhausted(results.getExecutedExamples()); } } TheoryRunner(final Strategy state, final Gen<P> source, Function<P, T> f,
      AsString<T> toString, LongSupplier clock); static TheoryRunner<P,T> runner(final Strategy state,
          final Gen<P> source, Function<P, T> f, AsString<T> toString); static TheoryRunner<T, T> runner(final Strategy state,
      final Gen<T> source); void check(final Predicate<T> property);  }
@Test public void shouldNotFalisifyTheTruth() { testee = makeTesteeFor(arbitrary().pick(1, 2, 3, 4, 5)); testee.check(i -> true); verify(reporter, never()).falsification(anyLong(), anyInt(), any(Object.class), anySmallerValues(), any()); }
@Test public void shouldFalisifyUniversalFalsehood() { testee = makeTesteeFor(arbitrary().pick(1, 2, 3, 4, 5)); testee.check(i -> false); verify(reporter, times(1)).falsification(anyLong(), anyInt(), any(Object.class), anySmallerValues(), any()); }
@Test public void shouldFalsifyPartialTruth() { testee = makeTesteeFor(arbitrary().pick(1, 2, 3, 4, 5)); testee.check(i -> i > 3); verify(reporter, times(1)).falsification(anyLong(), anyInt(), any(Object.class), anySmallerValues(), any()); }
@Test public void shouldFalsifyWhenPredicateThrowsException() { testee = makeTesteeFor(arbitrary().pick(1, 2, 3, 4, 5)); testee.check(i -> { if (i > 3) { throw new AssertionError(); } return true; }); verify(reporter, times(1)).falsification(anyLong(), anyInt(), any(Object.class), any(Throwable.class), anySmallerValues(), any()); }
@Test public void shouldReportSmallestFalsifyingValueFound() { testee = makeTesteeFor(arbitrary().pick(1, 2, 3, 4, 5)); testee.check(i -> i <= 3); verify(reporter, times(1)).falsification(anyLong(), anyInt(), eq(4), anySmallerValues(), any()); }
@Test public void shouldConstrainGeneratorsByAssumptions() { testee = makeTesteeFor(arbitrary().pick(1, 2, 3, 4, 5).assuming( i -> i != 4)); testee.check(i -> i <= 3); verify(reporter, times(1)).falsification(anyLong(), anyInt(), eq(5), anySmallerValues(), any()); }
@Test public void shouldReportInitialSeed() { long seed = 42; strategy = new Strategy(Configuration.defaultPRNG(seed), 10, 0, 10, 10, reporter, guidance); testee = makeTesteeFor(arbitrary().pick(1)); testee.check(i -> false); verify(reporter, times(1)).falsification(eq(seed), anyInt(), anyInt(), anySmallerValues(), any()); }
@Test public void shouldReportWhenValuesExhausted() { testee = makeTesteeFor(arbitrary().pick(1).assuming(i -> false)); testee.check(i -> true); verify(reporter, times(1)).valuesExhausted(anyInt()); }
@Test public void shouldReportNumberOfFoundExamplesWhenValuesExhausted() { int numberOfExamples = 3; strategy = new Strategy(Configuration.defaultPRNG(0), numberOfExamples, 0, 0, 10, reporter, guidance); testee = makeTesteeFor( arbitrary().pick(1, 2, 1, 1, 1).assuming( i -> i == 2)); testee.check(i -> true); verify(reporter, times(1)).valuesExhausted(0); }
@Test public void shouldReportNumberOfExamplesUsed() { testee = makeTesteeFor( arbitrary().pick(0, 1, 2, 3, 4, 5)); testee.check(i -> i != 4); verify(reporter, times(1)).falsification(anyLong(), eq(6), anyInt(), anySmallerValues(), any()); }