-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Property-Based Testing in jserv/rbtree
The jserv/rbtree test suite leverages property-based testing (PBT) to verify the correctness, consistency, and robustness of its red-black tree implementation. PBT is achieved by encoding data structure invariants as executable specifications and systematically generating diverse test cases to check those invariants across a wide range of scenarios.
This document explains:
-
How properties are specified and checked
-
How test cases are generated
-
How the framework validates correctness and detects subtle bugs
1. Specification Definition
jserv/rbtree defines four property types, each with a dedicated mechanism to check correctness:
| Property Type | Goal | rbtree Example |
|---|---|---|
| Classical | Maintain internal invariants | 5 red-black properties always hold |
| Round-trip | Operations cancel out or restore state | insert+delete = no-op |
| Catastrophic | No crash under bad input | Delete non-existent keys won't segfault |
| Differential | Cross-check correctness | Cached tree vs. Standard tree |
1.1 Classical Properties
The 5 classical red-black tree invariants are explicitly tested in multiple locations:
- Root is black
- Red nodes have black children
- Every path to a leaf has the same number of black nodes
- Nodes are in in-order traversal order
- If a node N has exactly one child, the child must be red
The Classical Properties for binary search tree
- For every node, all values in its left subtree are less than the node's value, and all values in its right subtree are greater than the node's value
Metadata
Metadata
Assignees
Labels
No labels