A curated collection of property tests for various data structures, algorithms, and properties. This repository aims to provide a comprehensive set of property-based tests across different programming languages, frameworks, and domains. Property testing is a powerful technique to help you ensure your code behaves correctly under a wide range of conditions by automatically generating input values and testing the properties of your code.
We welcome contributions to this repository! Please read the contribution guidelines first, and follow the steps writen there.
Property testing is a technique where you define general properties (invariants) about your program, and then the testing framework generates random inputs to check whether the properties hold true. Unlike traditional unit tests, which test specific scenarios, property tests explore a broader set of possible inputs, including edge cases, and often find bugs that you might not have considered.
For example, when testing a queue, a property might be that the size of the queue never goes negative after enqueue and dequeue operations, or that the first item dequeued is always the first one enqueued (FIFO).
- Automates Edge Case Discovery: Property tests generate a wide range of input values, which often uncovers edge cases that you wouldn't think of manually.
- Helps Prove Correctness: If a property test passes for all generated inputs, it helps give you confidence that your code behaves as expected across many scenarios.
- Improves Code Quality: Property testing encourages writing more general and robust code that handles a variety of situations, rather than specific predefined cases.
- Test if a queue is empty after a pop from an empty queue.
- Test if enqueue followed by dequeue returns the correct element.
- Test if the queue maintains the correct size after multiple enqueue and dequeue operations.
- Test for commutative property for queue reversals.
- Test if the queue's size is always non-negative.
See the full list of queue property tests
- Test if list reversal followed by another reversal results in the original list.
- Test if list concatenation is associative.
- Test if the length of a list remains the same after reversal.
- Test if adding elements to the front or back of the list gives the expected results.
See the full list of list property tests
- Test if string reversal followed by another reversal results in the original string.
- Test if string concatenation is associative.
- Test if concatenating an empty string with another string results in the original string.
See the full list of string property tests
- Test if addition is commutative.
- Test if multiplication is associative.
- Test if dividing by a non-zero number gives the correct result.
See the full list of number property tests
- We will continue to add tests for additional data structures and algorithms over time. Stay tuned for more!
Here are some popular property testing libraries that can help you get started in various programming languages:
- QuickCheck - Haskell
- Hypothesis - Python
- FsCheck - F#
- ScalaCheck - Scala
- fast-check - JavaScript
- Test.check - Clojure
Feel free to contribute any other libraries you use for property testing!