Skip to content

Curated set of property-based tests for common data structures and algorithms, promoting better test coverage and robustness

License

Notifications You must be signed in to change notification settings

Forward-Lang/awesome-property-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Awesome Property Testing Awesome

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.

Contents

Contributing

We welcome contributions to this repository! Please read the contribution guidelines first, and follow the steps writen there.

What is Property Testing

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).

Why Property Testing

  • 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.

Property Tests

Queues

  • 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

Lists

  • 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

Strings

  • 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

Numbers

  • 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

More Tests

  • We will continue to add tests for additional data structures and algorithms over time. Stay tuned for more!

See more tests here

Popular Property Testing Libraries

Here are some popular property testing libraries that can help you get started in various programming languages:

Feel free to contribute any other libraries you use for property testing!

About

Curated set of property-based tests for common data structures and algorithms, promoting better test coverage and robustness

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks