A set of macros to dynamically assert certain algebraic properties of regular C functions.
[ examples/demo.c
] [ Playground >> ]
#include <assert_algebraic.h>
#include <stdbool.h>
static bool eq(int x, int y) { return x == y; }
static bool lesser(int x, int y) { return x < y; }
static bool lesser_eq(int x, int y) { return x <= y; }
static int add(int x, int y) { return x + y; }
static int mul(int x, int y) { return x * y; }
static int neg(int x) { return -x; }
static int id(int x) { return x; }
int main(void) {
ASSERT_IMPLICATION(true && false, false);
ASSERT_BIDIRECTIONAL_IMPLICATION(true, true);
ASSERT_REFLEXIVE(eq, 3);
ASSERT_SYMMETRIC(eq, 4, 5);
ASSERT_TRANSITIVE(eq, 6, 7, 8);
ASSERT_EQUIVALENCE(eq, 1, 1, 3);
ASSERT_BIJECTIVE(id, id, eq, 123);
ASSERT_INVOLUTIVE(neg, eq, 123);
ASSERT_COMMUTATIVE(add, eq, 1, 2);
ASSERT_ASSOCIATIVE(add, eq, 1, 2, 3);
ASSERT_DISTRIBUTIVE(mul, add, eq, 1, 2, 3);
ASSERT_IDEMPOTENT(mul, eq, 1);
ASSERT_IDENTITY(add, eq, 0, 123);
ASSERT_ZERO(mul, eq, 0, 123);
ASSERT_PREORDER(lesser_eq, 1, 2, 3);
ASSERT_PARTIAL_ORDER(lesser_eq, eq, 1, 2, 3);
ASSERT_STRICT_PARTIAL_ORDER(lesser, 1, 1, 3);
ASSERT_TOTAL_ORDER(lesser_eq, eq, 1, 1, 3);
ASSERT_STRICT_TOTAL_ORDER(lesser, eq, 1, 1, 3);
}
To install assert-algebraic, just copy assert_algebraic.h
to your code base (or use Git submodules) and then #include <assert_algebraic.h>
where necessary.
The goal is to implement property-based testing in pure C. (Though this library is not intended as a complete property-based testing framework: test cases generation is not planned, for example.)
- Logical implication
- Logical equivalence
- Reflexivity
- Irreflexivity
- Symmetricity
- Antisymmetricity
- Asymmetricity
- Transitivity
- Antitransitivity
- Equivalence
- Connexity
- Semiconnexity
- Bijectivity
- Involutivity
ImpotenceIdempotence- Commutativity
- Associativity
- Distributivity
- Identity element
- Zero element
- Preorder
- Partial order (strict and non-strict)
- Total order (strict and non-strict)
- Hirrolot/slice99 -- Array slicing for C99.
- Update the
PROJECT_NUMBER
field inDoxyfile
. - Run
doxygen
to generate the newest docs. - Update
CHANGELOG.md
. - Release the project in GitHub Releases.