Automatically verify your [Partial]Eq/Ord invariants

Overview

Reltester

Crates.io docs.rs GitHub Workflow Status Crates.io min-rustc

Relation tester is a small testing utility for automatically checking the correctness of PartialEq, PartialOrd, Eq, and Ord implementations. It's most useful when used in conjuction with quickcheck or some other property-based testing framework.

Go to the docs!

Rationale

Imagine a scenario where you have a type Foo with a custom implementation of either PartialEq, Eq, PartialOrd, or Ord. By "custom" we mean hand-written as opposed to derived. The Rust compiler alone cannot verify the correctness of these implementations and thus it is up to you, the programmer, to uphold certain invariants about the specific binary relation that you're implementing. For example, if you implement PartialEq for Foo, you must guarantee that foo1 == foo2 implies foo2 == foo1 (symmetry).

This is what reltester is for. Rather than learning all subtle details of PartialEq, Eq, PartialOrd, and Ord, you can write some tests that will automatically check these invariants for you.

How to use

  1. Write some tests that generate random values of the type you wish to test. You can do this by hand or using crates such as quickcheck and proptest.

  2. Based on the traits that your type implements, call the appropriate checker:

    • reltester::eq for Eq;
    • reltester::ord for Ord;
    • reltester::partial_eq for PartialEq;
    • reltester::partial_ord for PartialOrd.

    All of these functions take three arguments of the same type: a, b, and c. This is because it takes up to three values to test some invariants.

Please refer to the documentation for more advanced use cases.

A small example

use reltester;
use quickcheck_macros::quickcheck;

#[quickcheck]
fn test_f32(a: f32, b: f32, c: f32) -> bool {
    // Let's check if `f32` implements `PartialEq` and `PartialOrd` correctly
    // (spoiler: it does)
    reltester::partial_eq(&a, &b, &c).is_ok()
        && reltester::partial_ord(&a, &b, &c).is_ok()
}

Legal

Reltester is available under the terms of the MIT license.

You might also like...
Binary Ninja plugin written in Rust to automatically apply symbol information from split debug info on Linux.

Load Symbols Binary Ninja plugin written in Rust to automatically apply symbol information from split debug info on Linux. Requirements Last tested wi

This automatically patches the RoPro extension for you, allowing you to have pro_tier for free.

RoPro Patcher This automatically patches the RoPro extension for you, allowing you to have pro_tier for free. NOTE Chrome, Brave (and possibly other b

Middleware/ios shortcut to setup alarms automatically based on the first class

Webuntis alarm This is a small little "middleware" / web server intended to connect to a webuntis timetable used in german schools which i wrote when

Automatically commit all edits to a wip branch with GPT-3 commit messages

gwipt Automatic work-in-progress commits with descriptive commit messages generated by GPT-3 Codex Never again worry about the tension between "commit

Tracing layer that automatically creates and manages progress bars for active spans.
Tracing layer that automatically creates and manages progress bars for active spans.

tracing-indicatif A tracing layer that automatically creates and manages indicatif progress bars for active spans. Progress bars are a great way to ma

auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, utilizing procedural macros.
auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, utilizing procedural macros.

Auto Rust auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, util

Automatically dim windows in Hyprland when switching between them.

hyprdim hyprdim is a daemon that automatically dims windows in Hyprland when switching between them. Features Easily see which window has focus, even

TTAutoRecord is a tool to automatically download TikTok Livestreams of users you follow.
TTAutoRecord is a tool to automatically download TikTok Livestreams of users you follow.

TTAutoRecord: Automated TikTok Live Stream Recorder TTAutoRecord is a specialized utility designed to automate the recording of live streams on TikTok

Automatically replace Discord CDN links with local file links, by downloading the images to the public folder
Automatically replace Discord CDN links with local file links, by downloading the images to the public folder

Auto Undiscord Did you hear that Discord will be blocking external websites from using images hosted on their servers? Did you host every image on you

Owner
Filippo Neysofu Costa
Core dev @graphprotocol
Filippo Neysofu Costa
🦀️atos for linux by rust - A partial replacement for Apple's atos tool for converting addresses within a binary file to symbols.

atosl-rs ??️ atos for linux by rust - A partial replacement for Apple's atos tool for converting addresses within a binary file to symbols. tested on

everettjf 60 Dec 29, 2022
xcp is a (partial) clone of the Unix cp command. It is not intended as a full replacement

xcp is a (partial) clone of the Unix cp command. It is not intended as a full replacement, but as a companion utility with some more user-friendly feedback and some optimisations that make sense under certain tasks (see below).

Steve Smith 310 Jan 5, 2023
epNFTs, the first partial program-owned NFT Standard powered by Instruction Introspection and Transfer Hooks!

epNFT Standard: A Comprehensive Guide Introduction to epNFTs Welcome to the epNFT-standard repository, where we explore the first program-owned NFT st

epPlex 6 Mar 1, 2024
Pure Rust Fault Proof Program that runs the rollup state-transition to verify an L2 output from L1 inputs.

palmtop palmtop is a fault proof program that runs the rollup state transition to verify an L2 output from L1 inputs. The verifiable L2 output can the

Anton Systems 5 Sep 26, 2023
🪩 verify plonky3 proofs in plonky2

plonky2.5 verify plonky3 STARK proofs in a plonky2 SNARK Getting Started Generate plonky3 fibonacci(64) proof git clone -b fib-example https://github.

QED Protocol 14 Jun 14, 2024
A CLI tool which can help you automatically kill process of your choice. Useful for freeing up memory and CPU usage!

Quickiller There are always programs such as chrome that keep eating up your resources even when closed! The only way to prevent this is to kill all o

Codingsquirrel 1 Dec 8, 2021
Mac App/CLI that automatically adds project logos to your locally cloned GitHub repos

Download the app Automatically adds project logos to your locally cloned GitHub repos. Youtube Video This repository contains the source code for the

Sam Denty 365 Dec 25, 2022
STKLR is a tool to help you automatically link up named stuff in your rust docs!

_____ _______ _ ___ _____ / ____|__ __| |/ / | | __ \ | (___ | | | ' /| | | |__) | \___ \ | | | < | | | _ / ___

Jer 3 Oct 25, 2022
Plex webhook service to automatically update your Anilist watching list.

anifunnel Plex webhook service to automatically update your Anilist watching list. Description anifunnel is a web server that will consume incoming Pl

Hamuko 3 Dec 12, 2022
A command-line tool and Docker image to automatically backup Git repositories from GitHub or anywhere

A command-line tool and Docker image to automatically backup Git repositories from GitHub or anywhere

Jake Wharton 256 Dec 27, 2022