Types only some languages have
A record with a short, a char or a byte[] in it is ordinary Java, and until recently any(…)
refused it. Code that keeps an unsigned 64-bit counter in a long, as many wire formats send it,
has a bug at 2^63 that no long ever shows, because 2^64−1 reads as −1. Each language has types
the others don’t, and a test that only draws what all of them share misses those bugs.
proptastic names each type once and draws it where your language has it. Where it doesn’t, the contract every edition is checked against says so, with what to use instead, so no edition makes up a type its language lacks. This page shows what each edition draws, and how to test the Java cases that need a second thought.
What each edition draws
Section titled “What each edition draws”| Type | Java | Rust | Swift | Simplest |
|---|---|---|---|---|
| signed 8-bit integers | byte | i8 | Int8 | 0 |
| signed 16-bit integers | short | i16 | Int16 | 0 |
| signed 32-bit integers | int | i32 | Int32 | 0 |
| signed 64-bit integers | long | i64 | Int64 | 0 |
| signed 128-bit integers | none (J9) | i128 | Int128 (macOS 15, iOS 18) | 0 |
| unsigned 8-bit integers | none (J9) | u8 | UInt8 | 0 |
| unsigned 16-bit integers | none (J9) | u16 | UInt16 | 0 |
| unsigned 32-bit integers | none (J9) | u32 | UInt32 | 0 |
| unsigned 64-bit integers | none (J9) | u64 | UInt64 | 0 |
| unsigned 128-bit integers | none (J9) | u128 | UInt128 (macOS 15, iOS 18) | 0 |
| signed integers of the platform's width, drawn through 64 bits | none (J9) | isize | Int | 0 |
| unsigned integers of the platform's width, drawn through 64 bits | none (J9) | usize | UInt | 0 |
| 32-bit floating point | float | f32 | Float | 0.0 |
| 64-bit floating point | double | f64 | Double | 0.0 |
| one character, as strings draw it (E26) | char | char | Character | a |
| arbitrary-precision integers | java.math.BigInteger | num_bigint::BigInt | none (S4) | 0 |
| exact decimals | java.math.BigDecimal | rust_decimal::Decimal | Decimal | 0 |
What an edition lacks, and what to use instead
| Id | Lacks | Use instead |
|---|---|---|
J9 | unsigned, 128-bit and platform-width integers | bigIntegers().atLeast(BigInteger.ZERO).atMost(…) for an unsigned or a 128-bit value; longs() only for a 64-bit pattern the code already reads as unsigned, such as with Long.toUnsignedString. |
S4 | arbitrary-precision integers | integers(Int128.self), the range an unbounded bigIntegers() draws elsewhere. |
Unsigned values in Java
Section titled “Unsigned values in Java”Java has no unsigned 64-bit type, so code keeps one in a long and treats it as unsigned. Draw it
as what it means, a number from 0 to 2^64−1, with bigIntegers(), not as a long: a long would
shrink toward the wrong zero and never reach the values past 2^63 as large numbers.
static final BigInteger TWO_TO_64 = BigInteger.ONE.shiftLeft(64);
/** Every unsigned 64-bit value, drawn as itself, not as signed bits. */static Domain<BigInteger> unsigned64() { return bigIntegers().atLeast(BigInteger.ZERO).lessThan(TWO_TO_64);}Here’s a comparison that forgets the values are unsigned:
/** Whether counter {@code a} is past {@code b}, both unsigned. */static boolean isPast(long a, long b) { return a > b;}@Testvoid aLargerCounterIsPast() { forAll(unsigned64(), unsigned64()) .check( (later, earlier) -> { long laterBits = later.longValue(); long earlierBits = earlier.longValue(); boolean past = Counters.isPast(laterBits, earlierBits); assertEquals(later.compareTo(earlier) > 0, past); });}expected: <false> but was: <true>
aLargerCounterIsPast failed after 1 try (seed 0x5eed) shrunk counterexample: later = 0, earlier = 9223372036854775808 pin it: .example( /* later */ new BigInteger("0"), /* earlier */ new BigInteger("9223372036854775808")) rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'TypesTest.aLargerCounterIsPast'The counterexample is a number past 2^63, printed as itself. Long.compareUnsigned(a, b) > 0 is
the fix. A value past 64 bits is still drawn from ordinary choices, several of them, so it saves,
replays and shrinks like any other.
Bytes, shorts and results
Section titled “Bytes, shorts and results”any(…) draws every primitive, so a record with a byte or a short component needs nothing
more. On its own, a byte is a bounded integer, and the same values, edges and shrinks come from
one line:
static Domain<Byte> flags() { var range = integers().atLeast(Byte.MIN_VALUE).atMost(Byte.MAX_VALUE); return range.map(number -> (byte) (int) number);}Java has no result type. A sealed interface of two records is one, and oneOf draws it, the
success first, so a counterexample shrinks to a success where it can:
sealed interface Parsed permits Parsed.Ok, Parsed.Err { record Ok(int value) implements Parsed {}
record Err(String message) implements Parsed {}}
static Domain<Parsed> results() { return oneOf(integers().map(Parsed.Ok::new), strings().map(Parsed.Err::new));}Rust’s Result and Swift’s Result are drawn by type, the same way round.
In the other languages
Section titled “In the other languages”- Rust draws every integer width,
i8toi128andu8tou128, withintegers::<u64>(), and owned values only:String, never&str. - Swift draws
Int128andUInt128on macOS 15 and iOS 18 or later, andFloat16where it compiles. Its.ofLength(5)counts Unicode scalars, as every edition counts code points, so a string with a combining accent can have acountof 4:#expect(s.count == 5)would be a property about Unicode, not about your code. - Half floats are on nightly Rust and in a Java incubator only: build them from the 16-bit
integer that holds their bits, with a crate such as Rust’s
half.
Formats covers base64, hex and the formats that stay recipes.