added calcRealAmpSum tests #609
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Example PR A
Sub PR 3
This PR demonstrates how to define unit tests for a new API function. Here, we test
calcRealAmpSum
as implemented in #607 and #608.It is essential to rigorously unit test every new QuEST function. Each function corresponds to a single Catch2
TEST_CASE
, defined in a file intests/unit/
. The test filename is identical to the filename inquest/src/api/
containing the API function.The unit tests re-create the behaviour of a QuEST function through direct, non-accelerated, naive linear algebra. They are ergo exceptionally slow, but perform precisely what the test operations are defined to do. For example, a Hadamard gate is tensored into a full-state matrix (with dimension
2^qubits
) and is multiplied onto a vector via matrix-vector multiplication. This is performed using the myriad of utility functions intests/utils/
. It is sometimes necessary, like in this PR, to define new utility functions.Beware that some unit tests are filled with boilerplate and complicated usages of macros and generic programming. This is to avoid code duplication between the tests of similar functions, while rigorously testing every aspect of QuEST's varied API functionality. The structure of the unit tests differ between the major groups of API functions. In order of increasing complexity, they are
types.cpp
environment.cpp
paulis.cpp
qureg.cpp
channels.cpp
initialisations.cpp
debug.cpp
matrices.cpp
decoherence.cpp
calculations.cpp
operations.cpp
This PR added a test to
calculations.cpp
which expands theTEST_ALL_QUREGS()
macro defined therein.These example PRs have so far implemented
calcRealAmpSum()
, returning a real number (qreal
). The natural companion functioncalcAmpSum()
, which returns a complex number (qcomp
), requires some additional steps as explained in #610.