LCOV - code coverage report
Current view: top level - src/ket - Ket.test.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 12 12 100.0 %
Date: 2025-05-02 21:49:55 Functions: 5 5 100.0 %

          Line data    Source code
       1             : // SPDX-FileCopyrightText: 2024 Pairinteraction Developers
       2             : // SPDX-License-Identifier: LGPL-3.0-or-later
       3             : 
       4             : #include "pairinteraction/ket/Ket.hpp"
       5             : 
       6             : #include "pairinteraction/enums/Parity.hpp"
       7             : #include "pairinteraction/utils/hash.hpp"
       8             : 
       9             : #include <doctest/doctest.h>
      10             : #include <memory>
      11             : #include <sstream>
      12             : 
      13             : namespace pairinteraction {
      14           1 : DOCTEST_TEST_CASE("constructing a class derived from ket") {
      15             :     class KetDerivedCreator;
      16             : 
      17             :     class KetDerived : public Ket {
      18             :         friend class KetDerivedCreator;
      19             :         struct Private {};
      20             : 
      21             :     public:
      22           1 :         KetDerived(Private /*unused*/, double f, double m, Parity p) : Ket(0, f, m, p) {}
      23           2 :         std::string get_label() const override { return "my_label"; }
      24             :         std::shared_ptr<KetDerived>
      25             :         get_ket_for_different_quantum_number_m(double new_quantum_number_m) const {
      26             :             auto ket = *this;
      27             :             ket.quantum_number_m = new_quantum_number_m;
      28             :             return std::make_shared<KetDerived>(ket);
      29             :         }
      30             :     };
      31             : 
      32             :     class KetDerivedCreator {
      33             :     public:
      34           1 :         KetDerivedCreator(double f, double m, Parity p) : f(f), m(m), p(p) {}
      35           1 :         std::shared_ptr<const KetDerived> create() const {
      36           2 :             return std::make_shared<const KetDerived>(KetDerived::Private(), f, m, p);
      37             :         }
      38             : 
      39             :     private:
      40             :         double f;
      41             :         double m;
      42             :         Parity p;
      43             :     };
      44             : 
      45           1 :     auto ket = KetDerivedCreator(2.0F, 3.0F, Parity::EVEN).create();
      46             : 
      47             :     // Check that the label can be printed
      48           1 :     std::stringstream ss;
      49           1 :     ss << *ket;
      50           1 :     DOCTEST_CHECK(ss.str() == "my_label");
      51             : 
      52             :     // Output the label to the doctest log
      53           1 :     DOCTEST_MESSAGE("Ket: ", *ket);
      54           1 : }
      55             : } // namespace pairinteraction

Generated by: LCOV version 1.16