tiny.hypothesis.ConjectureData
Defined in conjecture.
API (30)
Actions
Public operations.
beginSpandeinitdrawBooleandrawBytesdrawFloatdrawIntegerendSpanforceIntegerinitinitReplaymarkInterestingmarkInvalidresetresetReplaytargettargetDefault
Fields and members
Public fields and members.
allocatorbyte_blockschoicesmax_choicesmax_input_bytesprngreplay_byte_blocksreplay_byte_offsetreplay_choicesreplay_indexspan_depthspansstatustargets
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;Complete caller list for ConjectureData.deinit
38 direct callers.
lib.hypothesis.src.auto.test_auto_bool_draws_both_values[function] — test source atlib/hypothesis/src/auto.zig:118in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_enum_picks_every_variant[function] — test source atlib/hypothesis/src/auto.zig:172in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_f64_draws_in_default_range[function] — test source atlib/hypothesis/src/auto.zig:159in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_i32_draws_in_signed_range[function] — test source atlib/hypothesis/src/auto.zig:145in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_optional_yields_both_null_and_present[function] — test source atlib/hypothesis/src/auto.zig:206in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_slice_yields_varied_lengths_within_default_bound[function] — test source atlib/hypothesis/src/auto.zig:247in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_struct_draws_every_field[function] — test source atlib/hypothesis/src/auto.zig:194in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_tagged_union_picks_every_variant[function] — test source atlib/hypothesis/src/auto.zig:227in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_u8_draws_in_full_range[function] — test source atlib/hypothesis/src/auto.zig:133in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.composites.test_asciiStrings_draws_printable_ASCII[function] — test source atlib/hypothesis/src/composites.zig:406in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_filter_strategy_filters_values[function] — test source atlib/hypothesis/src/composites.zig:567in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_lists_strategy_draws_lists[function] — test source atlib/hypothesis/src/composites.zig:369in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_map_strategy_transforms_values[function] — test source atlib/hypothesis/src/composites.zig:552in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_oneOf_strategy_selects_from_alternatives[function] — test source atlib/hypothesis/src/composites.zig:521in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_optionals_strategy_draws_optionals[function] — test source atlib/hypothesis/src/composites.zig:505in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_permutations_strategy_draws_permutations[function] — test source atlib/hypothesis/src/composites.zig:446in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_shuffle_strategy_returns_shuffled_copies[function] — test source atlib/hypothesis/src/composites.zig:472in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_splitPoints_strategy_draws_sorted_indices[function] — test source atlib/hypothesis/src/composites.zig:424in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_string_strategy_draws_strings_in_charset[function] — test source atlib/hypothesis/src/composites.zig:387in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.conjecture.test_drawBoolean_produces_booleans[function] — test source atlib/hypothesis/src/conjecture.zig:351in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_drawBytes_produces_bytes_in_size_range[function] — test source atlib/hypothesis/src/conjecture.zig:452in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_drawBytes_rejects_cumulative_max_input_plus_one_without_growing_bytes[function] — test source atlib/hypothesis/src/conjecture.zig:463in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_drawFloat_produces_values_in_range[function] — test source atlib/hypothesis/src/conjecture.zig:441in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_drawInteger_produces_values_in_range[function] — test source atlib/hypothesis/src/conjecture.zig:340in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_overrun_on_too_many_choices[function] — test source atlib/hypothesis/src/conjecture.zig:406in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_replay_reproduces_values[function] — test source atlib/hypothesis/src/conjecture.zig:390in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_span_tracking[function] — test source atlib/hypothesis/src/conjecture.zig:419in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_target_records_finite_labeled_observations[function] — test source atlib/hypothesis/src/conjecture.zig:365in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_target_rejects_duplicate_labels_and_non-finite_observations[function] — test source atlib/hypothesis/src/conjecture.zig:380in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.engine.ReusableExampleRunner.deinit[method] — private source atlib/hypothesis/src/engine.zig:508in nearest public ownertiny.hypothesis.enginelib.hypothesis.src.strategy.test_BooleanStrategy_draws_booleans[function] — test source atlib/hypothesis/src/strategy.zig:178in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.strategy.test_BytesStrategy_draws_in_size_range[function] — test source atlib/hypothesis/src/strategy.zig:258in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.strategy.test_FloatStrategy_draws_in_range[function] — test source atlib/hypothesis/src/strategy.zig:246in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.strategy.test_IntegerStrategy_draws_in_range[function] — test source atlib/hypothesis/src/strategy.zig:166in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.strategy.test_IntegerStrategy_spans_signed_range_without_clamp_collapse[function] — test source atlib/hypothesis/src/strategy.zig:229in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.strategy.test_IntegerStrategy_u8_draws_in_range[function] — test source atlib/hypothesis/src/strategy.zig:193in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.strategy.test_drawCharFromCharset_draws_from_charset[function] — test source atlib/hypothesis/src/strategy.zig:270in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.swarm.test_swarm:_one_run_reuses_one_deterministic_action_distribution[function] — test source atlib/hypothesis/src/swarm.zig:112in nearest public ownertiny.hypothesis.swarm
Complete caller list for ConjectureData.init
39 direct callers.
lib.hypothesis.src.auto.test_auto_bool_draws_both_values[function] — test source atlib/hypothesis/src/auto.zig:118in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_enum_picks_every_variant[function] — test source atlib/hypothesis/src/auto.zig:172in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_f64_draws_in_default_range[function] — test source atlib/hypothesis/src/auto.zig:159in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_i32_draws_in_signed_range[function] — test source atlib/hypothesis/src/auto.zig:145in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_optional_yields_both_null_and_present[function] — test source atlib/hypothesis/src/auto.zig:206in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_slice_yields_varied_lengths_within_default_bound[function] — test source atlib/hypothesis/src/auto.zig:247in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_struct_draws_every_field[function] — test source atlib/hypothesis/src/auto.zig:194in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_tagged_union_picks_every_variant[function] — test source atlib/hypothesis/src/auto.zig:227in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.auto.test_auto_u8_draws_in_full_range[function] — test source atlib/hypothesis/src/auto.zig:133in nearest public ownertiny.hypothesis.autoderivelib.hypothesis.src.composites.test_asciiStrings_draws_printable_ASCII[function] — test source atlib/hypothesis/src/composites.zig:406in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_filter_strategy_filters_values[function] — test source atlib/hypothesis/src/composites.zig:567in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_lists_strategy_draws_lists[function] — test source atlib/hypothesis/src/composites.zig:369in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_map_strategy_transforms_values[function] — test source atlib/hypothesis/src/composites.zig:552in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_oneOf_strategy_selects_from_alternatives[function] — test source atlib/hypothesis/src/composites.zig:521in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_optionals_strategy_draws_optionals[function] — test source atlib/hypothesis/src/composites.zig:505in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_permutations_strategy_draws_permutations[function] — test source atlib/hypothesis/src/composites.zig:446in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_shuffle_strategy_returns_shuffled_copies[function] — test source atlib/hypothesis/src/composites.zig:472in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_splitPoints_strategy_draws_sorted_indices[function] — test source atlib/hypothesis/src/composites.zig:424in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.composites.test_string_strategy_draws_strings_in_charset[function] — test source atlib/hypothesis/src/composites.zig:387in nearest public ownertiny.hypothesis.compositeslib.hypothesis.src.conjecture.test_drawBoolean_produces_booleans[function] — test source atlib/hypothesis/src/conjecture.zig:351in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_drawBytes_produces_bytes_in_size_range[function] — test source atlib/hypothesis/src/conjecture.zig:452in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_drawBytes_rejects_cumulative_max_input_plus_one_without_growing_bytes[function] — test source atlib/hypothesis/src/conjecture.zig:463in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_drawFloat_produces_values_in_range[function] — test source atlib/hypothesis/src/conjecture.zig:441in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_drawInteger_produces_values_in_range[function] — test source atlib/hypothesis/src/conjecture.zig:340in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_overrun_on_too_many_choices[function] — test source atlib/hypothesis/src/conjecture.zig:406in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_replay_reproduces_values[function] — test source atlib/hypothesis/src/conjecture.zig:390in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_span_tracking[function] — test source atlib/hypothesis/src/conjecture.zig:419in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_target_records_finite_labeled_observations[function] — test source atlib/hypothesis/src/conjecture.zig:365in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.conjecture.test_target_rejects_duplicate_labels_and_non-finite_observations[function] — test source atlib/hypothesis/src/conjecture.zig:380in nearest public ownertiny.hypothesis.conjecturelib.hypothesis.src.engine.ReusableExampleRunner.init[function] — private source atlib/hypothesis/src/engine.zig:490in nearest public ownertiny.hypothesis.enginelib.hypothesis.src.engine.initExampleData[function] — private source atlib/hypothesis/src/engine.zig:622in nearest public ownertiny.hypothesis.enginelib.hypothesis.src.strategy.test_BooleanStrategy_draws_booleans[function] — test source atlib/hypothesis/src/strategy.zig:178in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.strategy.test_BytesStrategy_draws_in_size_range[function] — test source atlib/hypothesis/src/strategy.zig:258in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.strategy.test_FloatStrategy_draws_in_range[function] — test source atlib/hypothesis/src/strategy.zig:246in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.strategy.test_IntegerStrategy_draws_in_range[function] — test source atlib/hypothesis/src/strategy.zig:166in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.strategy.test_IntegerStrategy_spans_signed_range_without_clamp_collapse[function] — test source atlib/hypothesis/src/strategy.zig:229in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.strategy.test_IntegerStrategy_u8_draws_in_range[function] — test source atlib/hypothesis/src/strategy.zig:193in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.strategy.test_drawCharFromCharset_draws_from_charset[function] — test source atlib/hypothesis/src/strategy.zig:270in nearest public ownertiny.hypothesis.strategieslib.hypothesis.src.swarm.test_swarm:_one_run_reuses_one_deterministic_action_distribution[function] — test source atlib/hypothesis/src/swarm.zig:112in nearest public ownertiny.hypothesis.swarm
Audit
| Definitions | 17 |
|---|---|
| Public names | 34 |
| Members | 14 |
| Version | 26.7.0 |
| Revision | daab053ee433 |