From d828122d72e18be24d4a107f42a3bfb2526b8569 Mon Sep 17 00:00:00 2001 From: Eugene Rublenko <16805621+stand-by@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:33:07 -0500 Subject: [PATCH] Draft for new test file --- fast_pauli/cpp/tests/test_nb_helpers.cpp | 52 ++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 fast_pauli/cpp/tests/test_nb_helpers.cpp diff --git a/fast_pauli/cpp/tests/test_nb_helpers.cpp b/fast_pauli/cpp/tests/test_nb_helpers.cpp new file mode 100644 index 0000000..0428a73 --- /dev/null +++ b/fast_pauli/cpp/tests/test_nb_helpers.cpp @@ -0,0 +1,52 @@ +/** + * This code is part of Fast Pauli. + * + * (C) Copyright Qognitive Inc 2024. + * + * This code is licensed under the BSD 2-Clause License. You may + * obtain a copy of this license in the LICENSE.txt file in the root directory + * of this source tree. + * + * Any modifications or derivative works of this code must retain this + * copyright notice, and modified files need to carry a notice indicating + * that they have been altered from the originals. + */ + +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN + +#include + +#include "__nb_helpers.hpp" +#include "fast_pauli.hpp" + +namespace fp = fast_pauli; +namespace fp_det = fast_pauli::__detail; + +TEST_CASE("owning_ndarray_from_mdspan") +{ + SUBCASE("single item") + { + std::vector storage; + auto view = fp::zeros(storage, {1}); + auto ndarray = fp_det::owning_ndarray_from_mdspan(view); + + CHECK(ndarray.size() == 1); + CHECK(ndarray.ndim() == 1); + CHECK(ndarray.shape(0) == 1); + } + + SUBCASE("rank 2") + { + using complex_t = std::complex; + + std::vector storage; + std::mdspan view = fast_pauli::empty(storage, {3, 3}); + std::iota(storage.begin(), storage.end(), 1); + auto ndarray = fp_det::owning_ndarray_from_mdspan(view); + + CHECK(ndarray.size() == 9); + CHECK(ndarray.shape(0) == 3); + CHECK(ndarray.shape(1) == 3); + CHECK(std::equal(storage.begin(), storage.end(), ndarray.data())); + } +}