com.pholser.junit.quickcheck.generator.InRange Java Examples
The following examples show how to use
com.pholser.junit.quickcheck.generator.InRange.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultDateRangeLimiterPropertyTest.java From MaterialDateTimePicker with Apache License 2.0 | 6 votes |
@Property public void setToNearestShouldNeverBeAboveMaxDate( @InRange(min = "01/01/1800", max = "12/31/2099", format = "MM/dd/yyyy") Date date, @InRange(min = "01/01/1800", max = "12/31/2099", format = "MM/dd/yyyy") Date maxDate ) { DefaultDateRangeLimiter limiter = new DefaultDateRangeLimiter(); Calendar day = Calendar.getInstance(); day.setTime(date); Calendar minDay = Calendar.getInstance(); minDay.set(Calendar.YEAR, 1800); minDay.set(Calendar.MONTH, Calendar.JANUARY); minDay.set(Calendar.DAY_OF_MONTH, 1); Utils.trimToMidnight(minDay); Calendar maxDay = Calendar.getInstance(); maxDay.setTime(maxDate); limiter.setMinDate(minDay); limiter.setMaxDate(maxDay); Assert.assertTrue(Utils.trimToMidnight(maxDay).getTimeInMillis() >= limiter.setToNearestDate(day).getTimeInMillis()); }
Example #2
Source File: DefaultDateRangeLimiterPropertyTest.java From MaterialDateTimePicker with Apache License 2.0 | 6 votes |
@Property public void setToNearestShouldNeverBeBelowMinDate( @InRange(min = "01/01/1900", max = "12/31/2099", format = "MM/dd/yyyy") Date date, @InRange(min = "01/01/1900", max = "12/31/2099", format = "MM/dd/yyyy") Date minDate ) { DefaultDateRangeLimiter limiter = new DefaultDateRangeLimiter(); Calendar day = Calendar.getInstance(); day.setTime(date); Calendar minDay = Calendar.getInstance(); minDay.setTime(minDate); limiter.setMinDate(minDay); Assert.assertTrue(Utils.trimToMidnight(minDay).getTimeInMillis() <= limiter.setToNearestDate(day).getTimeInMillis()); }
Example #3
Source File: DefaultDateRangeLimiterPropertyTest.java From MaterialDateTimePicker with Apache License 2.0 | 6 votes |
@Property public void setToNearestShouldBeInSelectableDays( @InRange(min = "01/01/1900", max = "12/31/2099", format = "MM/dd/yyyy") Date date, @InRange(min = "01/01/1900", max = "12/31/2099", format = "MM/dd/yyyy") Date[] dates ) { DefaultDateRangeLimiter limiter = new DefaultDateRangeLimiter(); Calendar day = Calendar.getInstance(); day.setTime(date); Calendar[] selectables = datesToCalendars(dates); limiter.setSelectableDays(selectables); // selectableDays are manipulated a bit by the limiter selectables = limiter.getSelectableDays(); // selectables == null when the input is empty if (selectables == null) Assert.assertEquals( day.getTimeInMillis(), limiter.setToNearestDate(day).getTimeInMillis() ); else Assert.assertTrue(Arrays.asList(selectables).contains(limiter.setToNearestDate(day))); }
Example #4
Source File: NonZeroCachingCountersTest.java From JQF with BSD 2-Clause "Simplified" License | 6 votes |
@Property public void setAtIndexWorks(@InRange(minInt=0, maxInt=COUNTER_SIZE-1) int index, int value) { Counter counter = new NonZeroCachingCounter(COUNTER_SIZE); counter.setAtIndex(index, value); assertEquals(value, counter.getAtIndex(index)); int nonZeroSize = counter.getNonZeroSize(); Collection<Integer> nonZeroIndices = counter.getNonZeroIndices(); Collection<Integer> nonZeroValues = counter.getNonZeroValues(); if (value == 0) { assertThat(nonZeroSize, is(0)); assertThat(nonZeroIndices, iterableWithSize(0)); assertThat(nonZeroValues, iterableWithSize(0)); } else { assertThat(nonZeroSize, is(1)); assertThat(nonZeroIndices, iterableWithSize(1)); assertThat(nonZeroValues, iterableWithSize(1)); } }
Example #5
Source File: DateFormatterTest.java From JQF with BSD 2-Clause "Simplified" License | 6 votes |
@Fuzz public void testLocalDateTimeSerialization(@InRange(minInt=0) int year, @InRange(minInt=1, maxInt=12) int month, @InRange(minInt=1, maxInt=31) int dayOfMonth, @InRange(minInt=0, maxInt=23) int hour, @InRange(minInt=0, maxInt=59) int minute, @InRange(minInt=0, maxInt=59) int second) { LocalDateTime ldt1 = null, ldt2; String s1, s2; try { ldt1 = LocalDateTime.of(year, month, dayOfMonth, hour, minute, second); } catch (DateTimeException e) { Assume.assumeNoException(e); } s1 = ldt1.format(DateTimeFormatter.ISO_DATE_TIME); ldt2 = LocalDateTime.parse(s1); s2 = ldt2.format(DateTimeFormatter.ISO_DATE_TIME); Assert.assertEquals(s1, s2); }
Example #6
Source File: NonZeroCachingCountersTest.java From JQF with BSD 2-Clause "Simplified" License | 6 votes |
@Property public void incrementDeltaWorks(int key, int delta, @InRange(minInt=2, maxInt=42) int times) { Counter counter = new NonZeroCachingCounter(COUNTER_SIZE); // Check local state for (int j = 0; j < times; j++) { int before = counter.get(key); int after = counter.increment(key, delta); assertEquals(before+delta, after); } // Check global state int sum = 0; for (int i = 0; i < COUNTER_SIZE; i++) { sum += counter.get(i); } assertEquals(delta*times, sum); }
Example #7
Source File: CountersTest.java From JQF with BSD 2-Clause "Simplified" License | 6 votes |
@Property public void setAtIndexWorks(@InRange(minInt=0, maxInt=COUNTER_SIZE-1) int index, int value) { Counter counter = new Counter(COUNTER_SIZE); counter.setAtIndex(index, value); assertEquals(value, counter.getAtIndex(index)); int nonZeroSize = counter.getNonZeroSize(); Collection<Integer> nonZeroIndices = counter.getNonZeroIndices(); Collection<Integer> nonZeroValues = counter.getNonZeroValues(); if (value == 0) { assertThat(nonZeroSize, is(0)); assertThat(nonZeroIndices, iterableWithSize(0)); assertThat(nonZeroValues, iterableWithSize(0)); } else { assertThat(nonZeroSize, is(1)); assertThat(nonZeroIndices, iterableWithSize(1)); assertThat(nonZeroValues, iterableWithSize(1)); } }
Example #8
Source File: CountersTest.java From JQF with BSD 2-Clause "Simplified" License | 6 votes |
@Property public void incrementDeltaWorks(int key, int delta, @InRange(minInt=2, maxInt=42) int times) { Counter counter = new Counter(COUNTER_SIZE); // Check local state for (int j = 0; j < times; j++) { int before = counter.get(key); int after = counter.increment(key, delta); assertEquals(before+delta, after); } // Check global state int sum = 0; for (int i = 0; i < COUNTER_SIZE; i++) { sum += counter.get(i); } assertEquals(delta*times, sum); }
Example #9
Source File: ExecutionIndexingTest.java From JQF with BSD 2-Clause "Simplified" License | 5 votes |
@Property public void hasOwnPrefixAndSuffix(@InRange(minInt=1, maxInt=32) int @Size(min=4, max=20)[] v) { assumeTrue(v.length % 2 == 0); ExecutionIndex e = new ExecutionIndex(v); ExecutionIndex.Suffix selfCommonSuffix = e.getCommonSuffix(e); ExecutionIndex.Prefix suffixMinusPrefix = e.getPrefixOfSuffix(selfCommonSuffix); assertEquals(v.length/2, selfCommonSuffix.size()); assertEquals(0, suffixMinusPrefix.size()); assertEquals(true, e.hasPrefix(suffixMinusPrefix)); }
Example #10
Source File: ColumnStatsTest.java From crate with Apache License 2.0 | 5 votes |
@Property public void test_null_fraction_is_between_incl_0_and_incl_1(ArrayList<Integer> numbers, @InRange(minInt = 0) int nullCount, long totalRowCount) { assumeThat(totalRowCount, greaterThanOrEqualTo((long) nullCount)); assumeThat((long) numbers.size() + nullCount, lessThanOrEqualTo(totalRowCount)); ColumnStats<Integer> stats = ColumnStats.fromSortedValues(numbers, DataTypes.INTEGER, nullCount, totalRowCount); assertThat(stats.nullFraction(), greaterThanOrEqualTo(0.0)); assertThat(stats.nullFraction(), lessThanOrEqualTo(1.0)); }
Example #11
Source File: DefaultDateRangeLimiterPropertyTest.java From MaterialDateTimePicker with Apache License 2.0 | 5 votes |
@Property public void setToNearestShouldNeverBeInDisabledDays( @InRange(min = "01/01/1900", max = "12/31/2099", format = "MM/dd/yyyy") Date date, @InRange(min = "01/01/1900", max = "12/31/2099", format = "MM/dd/yyyy") Date[] dates ) { DefaultDateRangeLimiter limiter = new DefaultDateRangeLimiter(); Calendar day = Calendar.getInstance(); day.setTime(date); Calendar[] disableds = datesToCalendars(dates); limiter.setDisabledDays(disableds); Assert.assertFalse(Arrays.asList(disableds).contains(limiter.setToNearestDate(day))); }
Example #12
Source File: RedundancyTest.java From JQF with BSD 2-Clause "Simplified" License | 5 votes |
@Property public void testRedundancyScore(@Size(min=1, max = 5) List<@InRange(minInt=1, maxInt=10) Integer> counts) { // Let's make the sum of counts a perfect square int sumCounts = sum(counts); int squareSum = nextPerfectSquare(sumCounts); int deficit = squareSum - sumCounts; if (deficit > 0) { counts.add(deficit); } Assert.assertTrue(sum(counts) == squareSum && isPerfectSquare(squareSum)); int root = (int)(Math.round(Math.sqrt(squareSum))); Assert.assertTrue(root*root == squareSum); List<Integer> redundantCounts = new ArrayList<>(root); for (int i = 0; i < root; i++) { redundantCounts.add(root); } Assert.assertTrue(sum(redundantCounts) == squareSum); // Compute redundancy score for some memory accesses double score = PerfFuzzGuidance.computeRedundancyScore(counts); // Ensure that scores are in [0, 1) Assert.assertTrue(score >= 0 && score < 1); // Ensure that it is not more than the max possible double maxScore = PerfFuzzGuidance.computeRedundancyScore(redundantCounts); Assert.assertTrue(maxScore >= score); }
Example #13
Source File: RedundancyTest.java From JQF with BSD 2-Clause "Simplified" License | 5 votes |
@Property public void testDiscretization(@InRange(minDouble=0.0, maxDouble=1.0) Double score) { // Discretize a redundancy score int discrete = PerfFuzzGuidance.discretizeScore(score); // Ensure that the discretization is within the byte range Assert.assertTrue(discrete >= 0 && discrete <= Integer.MAX_VALUE); }
Example #14
Source File: ExecutionIndexingTest.java From JQF with BSD 2-Clause "Simplified" License | 5 votes |
@Property public void splitsAndJoinsPrefixSuffix(@InRange(minInt=1, maxInt=32) int @Size(min=20, max=20)[] v, @InRange(minInt=0, maxInt=10) int offset) { assumeTrue(v.length % 2 == 0); ExecutionIndex e = new ExecutionIndex(v); ExecutionIndex.Prefix prefix = new ExecutionIndex.Prefix(e, offset); ExecutionIndex.Suffix suffix = e.getSuffixOfPrefix(prefix); assertEquals(e, new ExecutionIndex(prefix, suffix)); }
Example #15
Source File: ExecutionIndexingTest.java From JQF with BSD 2-Clause "Simplified" License | 5 votes |
@Property public void comparesLength(@InRange(minInt=1, maxInt=32) int @Size(min=4, max=20)[] v1) { assumeTrue(v1.length % 2 == 0); int[] v2 = Arrays.copyOf(v1, v1.length-2); // v2 is smaller ExecutionIndex e1 = new ExecutionIndex(v1); ExecutionIndex e2 = new ExecutionIndex(v2); assertThat(e1.compareTo(e2), greaterThan(0)); assertThat(e2.compareTo(e1), lessThan(0)); }
Example #16
Source File: ExecutionIndexingTest.java From JQF with BSD 2-Clause "Simplified" License | 5 votes |
@Property public void comparesLexicographically(@InRange(minInt=1, maxInt=32) int @Size(min=1, max=20)[] v1) { assumeTrue(v1.length % 2 == 0); int[] v2 = Arrays.copyOf(v1, v1.length); v2[v1.length/2]--; // Make v2 less than v1 ExecutionIndex e1 = new ExecutionIndex(v1); ExecutionIndex e2 = new ExecutionIndex(v2); assertThat(e1.compareTo(e2), greaterThan(0)); assertThat(e2.compareTo(e1), lessThan(0)); }
Example #17
Source File: MoveTest.java From JQF with BSD 2-Clause "Simplified" License | 5 votes |
@Fuzz public void tryMoves(@InRange(minInt=0) int @Size(min=1, max=20)[] choices) { Situation state = initial; Move lastMove = null; for (int i = 0; i < choices.length; i++) { IndexedSeq<Move> moves = state.moves().values().flatten((x) -> x).toIndexedSeq(); int k = choices[i] % moves.size(); lastMove = moves.apply(k); state = lastMove.situationAfter(); //System.out.print(Dumper.apply(lastMove)); //System.out.print(" "); } //System.out.println(); }
Example #18
Source File: BinaryTreeTest.java From JQF with BSD 2-Clause "Simplified" License | 5 votes |
@Fuzz public void contains(@Size(max=100) Set<@InRange(minInt=0, maxInt=100) Integer> elements, @InRange(minInt=0, maxInt=100) int @Size(max=10) [] queries) { BinaryTree b = new BinaryTree(); for (Integer e : elements) { b.insert(e); } for (int q : queries) { Assert.assertEquals(elements.contains(q), b.contains(q)); } }
Example #19
Source File: RedBlackBSTTest.java From JQF with BSD 2-Clause "Simplified" License | 5 votes |
@Fuzz public void testGen( @InRange(minInt=5, maxInt = 64) @From(RedBlackBSTGenerator.class) RedBlackBST<Integer, Integer> tree) { Assume.assumeTrue(tree.check()); tree.min(); tree.max(); tree.rank(tree.floor(17)); tree.rank(tree.ceiling(17)); tree.put(17, 17); tree.get(17); }
Example #20
Source File: VertxVaadinResponseUT.java From vertx-vaadin with MIT License | 4 votes |
@Property(trials = TRIALS) public void shouldDelegateSetStatus(@InRange(minInt = 100, maxInt = 599) int status) throws Exception { vaadinResponse.setStatus(status); verify(httpServerResponse).setStatusCode(status); }
Example #21
Source File: CacheEvictionTest.java From JQF with BSD 2-Clause "Simplified" License | 4 votes |
@Fuzz public void testWeighting(@InRange(minInt=0, maxInt=1024) int @Size(max = MAX_SIZE) [] elements) { testWeightingInternal(elements); }
Example #22
Source File: CacheRequestsGenerator.java From JQF with BSD 2-Clause "Simplified" License | 4 votes |
public void configure(InRange range) { this.range = range; }
Example #23
Source File: VertxVaadinRequestUT.java From vertx-vaadin with MIT License | 4 votes |
@Property(trials = TRIALS) public void shouldDelegateGetContentLengthToHttpServerRequest(@InRange(minInt = 0, maxInt = 5000) int length) { when(routingContext.getBody()).thenReturn(Buffer.buffer(new byte[length])); assertThat(vaadinRequest.getContentLength()).isEqualTo(length); }
Example #24
Source File: VertxVaadinResponseUT.java From vertx-vaadin with MIT License | 4 votes |
@Property(trials = TRIALS) public void shouldDelegateSetStatus(@InRange(minInt = 100, maxInt = 599) int status) throws Exception { vaadinResponse.setStatus(status); verify(httpServerResponse).setStatusCode(status); }
Example #25
Source File: VertxVaadinRequestUT.java From vertx-vaadin with MIT License | 4 votes |
@Property(trials = TRIALS) public void shouldDelegateGetContentLengthToHttpServerRequest(@InRange(minInt = 0, maxInt = 5000) int length) { when(routingContext.getBody()).thenReturn(Buffer.buffer(new byte[length])); assertThat(vaadinRequest.getContentLength()).isEqualTo(length); }
Example #26
Source File: RedBlackBSTGenerator.java From JQF with BSD 2-Clause "Simplified" License | 2 votes |
/** * Tells this generator to produce values within a specified minimum and/or * maximum, inclusive, with uniform distribution. * * {@link InRange#min} and {@link InRange#max} take precedence over * {@link InRange#minInt()} and {@link InRange#maxInt()}, if non-empty. * * @param range annotation that gives the range's constraints */ public void configure(InRange range) { min = range.min().isEmpty() ? range.minInt() : Integer.parseInt(range.min()); max = range.max().isEmpty() ? range.maxInt() : Integer.parseInt(range.max()); }