LCOV - code coverage report
Current view: top level - src/math - ternary.cpp Hit Total Coverage
Test: Malbolge Unit Test Code Coverage Lines: 14 14 100.0 %
Date: 2021-02-03 17:18:54
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Cam Mannett 2020
       2             :  *
       3             :  * See LICENSE file
       4             :  */
       5             : 
       6             : #include "malbolge/math/ternary.hpp"
       7             : 
       8             : using namespace malbolge;
       9             : 
      10             : namespace
      11             : {
      12             : constexpr auto op_cipher = std::array{
      13             :     std::array<std::uint8_t, math::trit::base>{1u, 1u, 2u},
      14             :     std::array<std::uint8_t, math::trit::base>{0u, 0u, 2u},
      15             :     std::array<std::uint8_t, math::trit::base>{0u, 2u, 1u},
      16             : };
      17             : }
      18             : 
      19         124 : math::ternary& math::ternary::rotate(std::size_t i) noexcept
      20             : {
      21         124 :     v_ = to_tritset().rotate(i).to_base10();
      22         124 :     return *this;
      23             : }
      24             : 
      25     2476834 : math::ternary math::ternary::op(const math::ternary& other) const noexcept
      26             : {
      27     2476834 :     const auto a = to_tritset();
      28     2476834 :     const auto b = other.to_tritset();
      29             : 
      30     2476834 :     auto result = tritset_type{};
      31    27245174 :     for (auto i = 0u; i < tritset_type::width; ++i) {
      32    24768340 :         result.set(i, op_cipher[a[i]][b[i]]);
      33             :     }
      34             : 
      35     2476834 :     return result.to_base10();
      36             : }
      37             : 
      38           4 : std::ostream& std::operator<<(std::ostream& stream,
      39             :                               const std::optional<malbolge::math::ternary>& t)
      40             : {
      41           4 :     if (!t) {
      42           1 :         return stream << "{}";
      43             :     }
      44           3 :     return stream << *t;
      45             : }

Generated by: LCOV version 1.14