---
title: "Swarm Testing Data Structures"
description: "Zig's comptime reflection (std.meta.DeclEnum) can turn a data structure's public API into an enum that drives a model-based property test, so adding a new public method triggers a compile error from the non-exhaustive switch until the test covers it."
url: "https://swe.quest/articles/swarm-testing-data-structures-dcd11950dc8316b7"
canonical: "https://tigerbeetle.com/blog/2025-04-23-swarm-testing-data-structures"
source: "TigerBeetle"
published: "2025-04-23"
difficulty: "medium"
kind: "How-to"
reading_minutes: 5
tags: ["testing","zig","data-structures"]
---

# Swarm Testing Data Structures

A post on [TigerBeetle](https://swe.quest/sources/tigerbeetle.md), published 2025-04-23, 5 min read, How-to. Original: [https://tigerbeetle.com/blog/2025-04-23-swarm-testing-data-structures](https://tigerbeetle.com/blog/2025-04-23-swarm-testing-data-structures)

## Summary

Zig's comptime reflection (std.meta.DeclEnum) can turn a data structure's public API into an enum that drives a model-based property test, so adding a new public method triggers a compile error from the non-exhaustive switch until the test covers it. TigerBeetle tests its intrusive queue against a ring-buffer model and adds swarm testing: rather than picking operations uniformly, each run randomly chooses a subset of operations and random weights for them, so runs reach states like long queues that uniform push/pop never produces. Code is included for weighted enum sampling, random weight generation and an allocation-free k-combination helper.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)
- [Zig](https://swe.quest/tags/zig.md) (Languages)
- [Data structures](https://swe.quest/tags/data-structures.md) (Architecture & design)

## Prerequisites

- property-based testing ([easy posts on Testing](https://swe.quest/tags/testing.md?difficulty=easy))
- Zig comptime basics ([easy posts on Zig](https://swe.quest/tags/zig.md?difficulty=easy))

## Keywords

TigerBeetle, Zig, swarm testing, comptime, std.meta.DeclEnum, intrusive queue

## Related posts

- [Random Fuzzy Thoughts](https://swe.quest/articles/random-fuzzy-thoughts-74b3f2f1b21a2499.md): TigerBeetle · 2023-03-28 · Medium · 9 min read · Testing, Formal methods, Distributed systems, Zig
  Treating a fuzzer's byte slice as a finite PRNG unifies coverage-guided fuzzing with structured property-based testing: the entropy length measures input complexity, gives test-case minimization almost for free, and tells interactive simulations when to stop injecting faults.
- [Index, Count, Offset, Size](https://swe.quest/articles/index-count-offset-size-8c9106813a691acc.md): TigerBeetle · 2026-02-16 · Medium · 3 min read · Zig, Debugging, Type systems
  TigerBeetle uses a strict naming convention to catch off-by-one and index-space bugs that types don't easily prevent: \`count\` is a number of items, \`index\` points at an item (invariant \`index \< count\`), \`size\` is a byte count (\`size = @sizeOf(T) \* count\`), and \`offset\` is the bytewise counterpart of index. \`length\` is banned because it is ambiguous, for example Rust's byte-size \`str::len\` versus Python's code-point \`len\`.
- [Enum of Arrays](https://swe.quest/articles/enum-of-arrays-39cf1c2fe738e424.md): TigerBeetle · 2024-12-19 · Medium · 3 min read · Performance engineering, Data structures, Zig, Hardware
  Struct-of-Arrays has a dual for tagged unions: an Enum of Arrays, where one tag covers a whole batch of homogeneous payloads instead of each element carrying its own tag.
- [A Descent Into the Vörtex](https://swe.quest/articles/a-descent-into-the-vortex-6dcd52020263ac13.md): TigerBeetle · 2025-02-13 · Medium · 3 min read · Testing, Chaos engineering, Distributed databases, Zig
  TigerBeetle has added Vortex, a non-deterministic, generative full-system test harness that complements its Deterministic Simulation Testing by exercising real production binaries and client libraries from the outside in.
- [What the interns have wrought, 2022 edition](https://swe.quest/articles/what-the-interns-have-wrought-2022-edition-0f4dcf7e53f3e8d4.md): Jane Street Tech Blog · 2022-08-25 · Medium · 8 min read · Functional programming, Testing, Performance engineering, Developer tools, Engineering culture
  Three Jane Street intern projects from 2022 show substantial tooling work in OCaml. magic-trace gained a sampling mode that can cover 20 seconds to 20 minutes on Intel or AMD hardware, plus multi-process tracing, CPU-frequency transition reporting and a perf dlfilter backend that speeds trace decoding by 10–50%.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
