Mentions légales du service

Skip to content

Add proper unit tests for 'Vector' and its subclasses

ANDREY Paul requested to merge vector-unit-tests into develop

This MR is about adding a proper unit tests suite for declearn.model.api.Vector and its subclasses.

Vector is a fundamental building brick of declearn, but has long been wrongfully considered as not really requiring tests, due to the apparent simplicity of the operations at work. However, some issues have been encountered throughout time, due to math and/or logic errors that have seemingly emerged during the early stages of the Vector class's development, that was not as linear as it ought due to its specification having been defined on-the-way while developing the entire declearn-2 core code.

Some unit tests were added a while ago (see MR !22 (merged)), which helped identify and fix a couple of issues, but these remained somewhat superficial in that they did not cover all of the backend code nor go through the tedious-but-expected detailed inspection of each and every basic operation (going instead for a more involved everything-at-a-time computation that, in fact, did not cover everything).

This MR is about replacing that limited test suite with a more involved one, that involves:

  • Defining a common test suite to be implemented for each and every 'Vector' subclass, that:
    • Tests "in-place" operations (creation, (de)serialization, shapes and dtypes access, sum and sign operations...)
    • Tests all math operations with scalar values, both on the left and right side (when applicable).
    • Tests all math operations with another same-spec vector.
  • Adding some tests for subclasses that are compatible with another one; namely, adding (tensorflow|torch|jax-numpy) / numpy vectors operations (both on left and right side).
  • Adding some "generic" tests that rely on a mock scalar-float-values-packing Vector subclass.
    • These are about testing that some exceptions are properly raised.
    • They also provide with a minimal case for verifying that some base operations work properly.

At the moment, and with as little use of 'no cover' statements as possible, the tests offer a 100% coverage on all 'Vector'-defining code files.

On the side, a couple of actions were taken:

  • Revise and harmonize the type-annotation of 'Vector.minimum' and 'Vector.maximum'.
  • Deprecate 'axis' and 'keepdims' kwargs to 'Vector.sum', which are defined by subclasses but not by the ABC and are unused.
Edited by ANDREY Paul

Merge request reports