Skip to documentation
SLOP

tiny.hypothesis.ConjectureData

Reference tiny.hypothesis ConjectureData

Defined in conjecture.

API (30)

Actions

Public operations.

Fields and members

Public fields and members.

No direct callersNo direct callsconjectureConjectureData
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/hypothesis/src/conjecture.zig:52

zig
pub const ConjectureData = struct {    choices: std.ArrayListUnmanaged(ChoiceNode) = .empty,    spans: std.ArrayListUnmanaged(Span) = .empty,    byte_blocks: std.ArrayListUnmanaged(u8) = .empty,    targets: std.ArrayListUnmanaged(TargetObservation) = .empty,    span_depth: usize = 0,    status: Status = .valid,    max_choices: usize = 4096,    max_input_bytes: usize = default_max_input_bytes,    prng: std.Random.DefaultPrng,    replay_choices: ?[]const ChoiceNode = null,    replay_byte_blocks: ?[]const u8 = null,    replay_index: usize = 0,    replay_byte_offset: usize = 0,    allocator: Allocator,    pub fn init(allocator: Allocator, seed: u64) ConjectureData {        return .{            .prng = std.Random.DefaultPrng.init(seed),            .allocator = allocator,        };    }    pub fn initReplay(        allocator: Allocator,        replay_choices: []const ChoiceNode,        replay_byte_blocks: ?[]const u8,    ) ConjectureData {        return .{            .prng = std.Random.DefaultPrng.init(0),            .replay_choices = replay_choices,            .replay_byte_blocks = replay_byte_blocks,            .allocator = allocator,        };    }    pub fn deinit(self: *ConjectureData) void {        self.clearTargets();        self.choices.deinit(self.allocator);        self.spans.deinit(self.allocator);        self.byte_blocks.deinit(self.allocator);        self.targets.deinit(self.allocator);    }    pub fn beginSpan(self: *ConjectureData, label: []const u8) !void {        try self.spans.append(self.allocator, .{            .label = label,            .start = self.choices.items.len,            .end = 0,            .depth = self.span_depth,        });        self.span_depth += 1;    }    pub fn endSpan(self: *ConjectureData) void {        std.debug.assert(self.span_depth > 0);        self.span_depth -= 1;        var i = self.spans.items.len;        while (i > 0) {            i -= 1;            if (self.spans.items[i].depth == self.span_depth and                self.spans.items[i].end == 0)            {                self.spans.items[i].end = self.choices.items.len;                return;            }        }    }    pub fn drawInteger(        self: *ConjectureData,        min: u64,        max: u64,        shrink_towards: u64,    ) DrawError!u64 {        if (self.choices.items.len >= self.max_choices) {            self.status = .overrun;            return DrawError.Overrun;        }        const value = if (self.replay_choices) |replay| blk: {            if (self.replay_index >= replay.len) {                self.status = .overrun;                return DrawError.Overrun;            }            const node = replay[self.replay_index];            self.replay_index += 1;            break :blk node.value;        } else blk: {            if (min == max) break :blk min;            const range = max -% min;            break :blk min +% self.prng.random().intRangeAtMost(u64, 0, range);        };        const clamped = @min(@max(value, min), max);        try self.choices.append(self.allocator, .{            .kind = .integer,            .value = clamped,            .min = min,            .max = max,            .shrink_towards = shrink_towards,        });        return clamped;    }    pub fn drawBoolean(self: *ConjectureData) DrawError!bool {        const value = try self.drawInteger(0, 1, 0);        return value != 0;    }    pub fn drawFloat(        self: *ConjectureData,        min: f64,        max: f64,    ) DrawError!f64 {        if (self.choices.items.len >= self.max_choices) {            self.status = .overrun;            return DrawError.Overrun;        }        const value = if (self.replay_choices) |replay| blk: {            if (self.replay_index >= replay.len) {                self.status = .overrun;                return DrawError.Overrun;            }            const node = replay[self.replay_index];            self.replay_index += 1;            break :blk @as(f64, @bitCast(node.value));        } else blk: {            const r = self.prng.random();            const unit: f64 = @as(f64, @floatFromInt(r.int(u52))) /                @as(f64, @floatFromInt(@as(u52, std.math.maxInt(u52))));            break :blk min + unit * (max - min);        };        const clamped = @min(@max(value, min), max);        try self.choices.append(self.allocator, .{            .kind = .float,            .value = @bitCast(clamped),            .min = @bitCast(min),            .max = @bitCast(max),            .shrink_towards = @bitCast(@as(f64, 0.0)),        });        return clamped;    }    pub fn drawBytes(        self: *ConjectureData,        min_size: usize,        max_size: usize,    ) DrawError![]const u8 {        const len = try self.drawInteger(            @intCast(min_size),            @intCast(max_size),            @intCast(min_size),        );        const start = self.byte_blocks.items.len;        const size: usize = @intCast(len);        std.debug.assert(start <= self.max_input_bytes);        if (size > self.max_input_bytes - start) {            self.status = .overrun;            return DrawError.Overrun;        }        if (self.replay_byte_blocks) |replay_bytes| {            if (self.replay_byte_offset + size > replay_bytes.len) {                self.status = .overrun;                return DrawError.Overrun;            }            try self.byte_blocks.appendSlice(                self.allocator,                replay_bytes[self.replay_byte_offset..][0..size],            );            self.replay_byte_offset += size;        } else {            try self.byte_blocks.ensureUnusedCapacity(self.allocator, size);            for (0..size) |_| {                self.byte_blocks.appendAssumeCapacity(                    self.prng.random().int(u8),                );            }        }        return self.byte_blocks.items[start..][0..size];    }    pub fn forceInteger(self: *ConjectureData, value: u64) DrawError!void {        if (self.choices.items.len >= self.max_choices) {            self.status = .overrun;            return DrawError.Overrun;        }        try self.choices.append(self.allocator, .{            .kind = .integer,            .value = value,            .min = value,            .max = value,            .shrink_towards = value,            .was_forced = true,        });    }    pub fn target(self: *ConjectureData, observation: anytype, label: []const u8) TargetError!void {        const value = targetValue(@TypeOf(observation), observation);        if (!std.math.isFinite(value)) return TargetError.NonFiniteTarget;        for (self.targets.items) |existing| {            if (std.mem.eql(u8, existing.label, label)) {                return TargetError.DuplicateTargetLabel;            }        }        const owned_label = try self.allocator.dupe(u8, label);        errdefer self.allocator.free(owned_label);        try self.targets.append(self.allocator, .{            .label = owned_label,            .value = value,        });    }    pub fn targetDefault(self: *ConjectureData, observation: anytype) TargetError!void {        return self.target(observation, "");    }    pub fn markInteresting(self: *ConjectureData) void {        self.status = .interesting;    }    pub fn markInvalid(self: *ConjectureData) void {        self.status = .invalid;    }    pub fn reset(self: *ConjectureData, seed: u64) void {        self.clearTargets();        self.choices.clearRetainingCapacity();        self.spans.clearRetainingCapacity();        self.byte_blocks.clearRetainingCapacity();        self.span_depth = 0;        self.status = .valid;        self.prng = std.Random.DefaultPrng.init(seed);        self.replay_choices = null;        self.replay_byte_blocks = null;        self.replay_index = 0;        self.replay_byte_offset = 0;    }    pub fn resetReplay(        self: *ConjectureData,        replay_choices: []const ChoiceNode,        replay_byte_blocks: ?[]const u8,    ) void {        self.clearTargets();        self.choices.clearRetainingCapacity();        self.spans.clearRetainingCapacity();        self.byte_blocks.clearRetainingCapacity();        self.span_depth = 0;        self.status = .valid;        self.replay_choices = replay_choices;        self.replay_byte_blocks = replay_byte_blocks;        self.replay_index = 0;        self.replay_byte_offset = 0;    }    fn clearTargets(self: *ConjectureData) void {        for (self.targets.items) |target_observation| {            self.allocator.free(target_observation.label);        }        self.targets.clearRetainingCapacity();    }};

Source: lib/hypothesis/src/root.zig:44

zig
pub const ConjectureData = conjecture.ConjectureData;
Called byCallsNo direct callstest sourcelib.hypothesis.src.conjecturetest: span trackingConjectureDatabeginSpan
Static calls · unresolved targets: 1 · external targets: 0.
Called byCallstest sourcelib.hypothesis.src.autotest: auto bool draws both valuestest sourcelib.hypothesis.src.autotest: auto enum picks every varianttest sourcelib.hypothesis.src.autotest: auto f64 draws in default rangetest sourcelib.hypothesis.src.autotest: auto i32 draws in signed rangetest sourcelib.hypothesis.src.autotest: auto optional yields both null ...+33 moreprivate sourcelib.hypothesis.src.conjecture.ConjectureDataclearTargetsConjectureDatadeinit
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallstest sourcelib.hypothesis.src.conjecturetest: drawBoolean produces booleanstest sourcelib.hypothesis.src.conjecturetest: replay reproduces valuesConjectureDatadrawIntegerConjectureDatadrawBoolean
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.hypothesis.src.conjecturetest: drawBytes produces bytes in siz...test sourcelib.hypothesis.src.conjecturetest: drawBytes rejects cumulative ma...ConjectureDatadrawIntegerConjectureDatadrawBytes
Static calls · unresolved targets: 0 · external targets: 4.
Called byCallsNo direct callstest sourcelib.hypothesis.src.conjecturetest: drawFloat produces values in ra...ConjectureDatadrawFloat
Static calls · unresolved targets: 1 · external targets: 2.
Called byCallsNo direct callsConjectureDatadrawBooleanConjectureDatadrawBytestest sourcelib.hypothesis.src.conjecturetest: drawInteger produces values in ...test sourcelib.hypothesis.src.conjecturetest: overrun on too many choicestest sourcelib.hypothesis.src.conjecturetest: replay reproduces valuestest sourcelib.hypothesis.src.conjecturetest: span trackingConjectureDatadrawInteger
Static calls · unresolved targets: 1 · external targets: 1.
Called byCallsNo direct callstest sourcelib.hypothesis.src.conjecturetest: span trackingConjectureDataendSpan
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.hypothesis.src.autotest: auto bool draws both valuestest sourcelib.hypothesis.src.autotest: auto enum picks every varianttest sourcelib.hypothesis.src.autotest: auto f64 draws in default rangetest sourcelib.hypothesis.src.autotest: auto i32 draws in signed rangetest sourcelib.hypothesis.src.autotest: auto optional yields both null ...+34 moreConjectureDatainit
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.hypothesis.src.conjecturetest: replay reproduces valuesTestResultinitFailureReplayprivate sourcelib.hypothesis.src.engineinitExampleDatatest sourcelib.hypothesis.src.swarmtest: swarm: an active subset focuses...ConjectureDatainitReplay
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsprivate sourcelib.hypothesis.src.engine.ReusableExampleRunnerexecuteprivate sourcelib.hypothesis.src.conjecture.ConjectureDataclearTargetsConjectureDatareset
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsprivate sourcelib.hypothesis.src.engine.ReusableExampleRunnerexecuteprivate sourcelib.hypothesis.src.conjecture.ConjectureDataclearTargetsConjectureDataresetReplay
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsConjectureDatatargetDefaulttest sourcelib.hypothesis.src.conjecturetest: target records finite labeled o...test sourcelib.hypothesis.src.conjecturetest: target rejects duplicate labels...private sourcelib.hypothesis.src.conjecturetargetValueConjectureDatatarget
Static calls · unresolved targets: 3 · external targets: 0.
Called byCallsNo direct callersConjectureDatatargetConjectureDatatargetDefault
Static calls · unresolved targets: 0 · external targets: 0.

Complete caller list for ConjectureData.deinit

38 direct callers.

Complete caller list for ConjectureData.init

39 direct callers.

Audit

Definitions17
Public names34
Members14
Version26.7.0
Revisiondaab053ee433