Search in sources :

Example 1 with Constraint

use of org.quicktheories.impl.Constraint in project cassandra by apache.

the class WarningsSnapshotTest method counter.

private static Gen<Counter> counter() {
    Gen<Boolean> empty = SourceDSL.booleans().all();
    Constraint maxValue = Constraint.between(1, Long.MAX_VALUE);
    Gen<ImmutableSet<InetAddressAndPort>> instances = SourceDSL.arbitrary().pick(ImmutableSet.of(HOME), ImmutableSet.of(VACATION_HOME), ImmutableSet.of(HOME, VACATION_HOME));
    Gen<Counter> gen = rs -> empty.generate(rs) ? Counter.empty() : new Counter(instances.generate(rs), rs.next(maxValue));
    return gen.describedAs(Counter::toString);
}
Also used : InetAddress(java.net.InetAddress) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Gen(org.quicktheories.core.Gen) ImmutableSet(com.google.common.collect.ImmutableSet) Constraint(org.quicktheories.impl.Constraint) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WarningsSnapshot(org.apache.cassandra.service.reads.trackwarnings.WarningsSnapshot) Test(org.junit.Test) SourceDSL(org.quicktheories.generators.SourceDSL) QuickTheory.qt(org.quicktheories.QuickTheory.qt) UnknownHostException(java.net.UnknownHostException) ImmutableSet(com.google.common.collect.ImmutableSet) Constraint(org.quicktheories.impl.Constraint)

Example 2 with Constraint

use of org.quicktheories.impl.Constraint in project cassandra by apache.

the class Generators method charArray.

public static Gen<char[]> charArray(Gen<Integer> sizes, char[] domain) {
    Constraint constraints = Constraint.between(0, domain.length - 1).withNoShrinkPoint();
    Gen<char[]> gen = td -> {
        int size = sizes.generate(td);
        char[] is = new char[size];
        for (int i = 0; i != size; i++) {
            int idx = (int) td.next(constraints);
            is[i] = domain[idx];
        }
        return is;
    };
    gen.describedAs(String::new);
    return gen;
}
Also used : Logger(org.slf4j.Logger) Date(java.util.Date) Predicate(java.util.function.Predicate) Timestamp(java.sql.Timestamp) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) ArrayUtils(org.apache.commons.lang3.ArrayUtils) SourceDSL(org.quicktheories.generators.SourceDSL) UUID(java.util.UUID) UnknownHostException(java.net.UnknownHostException) ByteBuffer(java.nio.ByteBuffer) StandardCharsets(java.nio.charset.StandardCharsets) InetAddress(java.net.InetAddress) TimeUnit(java.util.concurrent.TimeUnit) Gen(org.quicktheories.core.Gen) Constraint(org.quicktheories.impl.Constraint) RandomnessSource(org.quicktheories.core.RandomnessSource) ZoneOffset(java.time.ZoneOffset) Constraint(org.quicktheories.impl.Constraint)

Aggregations

InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 Gen (org.quicktheories.core.Gen)2 SourceDSL (org.quicktheories.generators.SourceDSL)2 Constraint (org.quicktheories.impl.Constraint)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ByteBuffer (java.nio.ByteBuffer)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Timestamp (java.sql.Timestamp)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1 Date (java.util.Date)1 Random (java.util.Random)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 Predicate (java.util.function.Predicate)1 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)1 WarningsSnapshot (org.apache.cassandra.service.reads.trackwarnings.WarningsSnapshot)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1