Unit Tests

The galois library uses pytest for unit testing.

Install

First, pytest needs to be installed on your system. Easily install it by installing the development dependencies.

$ python3 -m pip install -r requirements-dev.txt

Run from the command line

Execute all of the unit tests manually from the command line.

$ python3 -m pytest tests/

Or only run a specific test file.

$ python3 -m pytest tests/test_math.py

Or only run a specific unit test.

$ python3 -m pytest tests/test_math.py::test_gcd

Run from VS Code

Included is a VS Code configuration file .vscode/settings.json. This instructs VS Code about how to invoke pytest. VS Code’s integrated test infrastructure will locate the tests and allow you to run or debug any test.

Test vectors

Test vectors are generated by third-party tools and stored in .pkl files. Most test vectors are stored in these folders:

  • tests/data/

  • tests/fields/data/GF(*)/

  • tests/polys/data/GF(*)/

The scripts that generate the test vectors are:

  • scripts/generate_int_test_vectors.py

  • scripts/generate_field_test_vectors.py

The two primary third-party tools are Sage and SymPy.

Install Sage

$ sudo apt install sagemath

Install SymPy

$ python3 -m pip install sympy

Generate test vectors

To re-generate the test vectors locally, run:

$ python3 scripts/generate_int_test_vectors.py
$ python3 scripts/generate_field_test_vectors.py

The scripts use random number generator seeds to generate reproducible test vectors. To generate different test vectors, modify the seeds. It’s also easy to increase the number of test cases for any individual test.


Last update: Dec 06, 2021