From f756a8915377f8609d7cd1454132f7759aa6a381 Mon Sep 17 00:00:00 2001 From: jamesETsmith Date: Mon, 10 Jun 2024 16:11:45 -0400 Subject: [PATCH] [feature/CI_setup] more CI tinkering --- tests/test_pauli_op.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/test_pauli_op.cpp b/tests/test_pauli_op.cpp index 9903011..9eed22f 100644 --- a/tests/test_pauli_op.cpp +++ b/tests/test_pauli_op.cpp @@ -31,7 +31,8 @@ void __check_apply(PauliOp &pauli_op, size_t n_states) { // // Calculate the expected new states // - auto pop_dense = pauli_op.get_dense_repr(); + std::vector>> pop_dense = + pauli_op.get_dense_repr(); // pop_dense : d x d // states : n x d @@ -62,6 +63,10 @@ void __check_apply(PauliOp &pauli_op, size_t n_states) { // Tests // +// +// Constructors +// + TEST_CASE("test pauli op") { std::vector pauli_strings = {"IXYZ", "XIII", "XXYZ"}; std::vector> coeffs = {1i, 2., -1i}; @@ -84,6 +89,29 @@ TEST_CASE("test bad apply") { CHECK_THROWS(pauli_op.apply(state)); } +// +// Member functions +// + +TEST_CASE("test get_dense_repr") { + std::vector pauli_strings = {"III", "III", "III"}; + std::vector> coeffs = {1, 2., 1}; + PauliOp pauli_op(coeffs, pauli_strings); + auto pop_dense = pauli_op.get_dense_repr(); + + size_t const dim = pauli_op.dims(); + + for (size_t i = 0; i < dim; ++i) { + for (size_t j = 0; j < dim; ++j) { + if (i == j) { + CHECK(abs(pop_dense[i][j] - std::complex(4)) < 1e-6); + } else { + CHECK(abs(pop_dense[i][j]) < 1e-6); + } + } + } +} + // TODO add tests for multiple pauli strings TEST_CASE("test apply simple") { // Set up PauliOp