LCOV - code coverage report
Current view: top level - estd/examples - ratio.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 27 27 100.0 %
Date: 2025-01-20 13:53:09 Functions: 8 12 66.7 %

          Line data    Source code
       1             : // Copyright 2024 Accenture.
       2             : 
       3             : #include <estd/ratio.h>
       4             : 
       5             : #include <gtest/gtest.h>
       6             : 
       7           3 : TEST(RatioExample, basic_functionality)
       8             : {
       9             :     // [EXAMPLE_RATIO_BASIC_FUNCTIONALITY_START]
      10             :     // num is used to get the numerator of a ratio.
      11           1 :     static_assert((3 == ::estd::ratio<3, 5>::num), "");
      12             : 
      13             :     // den is used to get the denominator of a ratio.
      14           1 :     static_assert((5 == ::estd::ratio<3, 5>::den), "");
      15             : 
      16           1 :     static_assert(std::is_same<::estd::ratio<1, 5>::type, ::estd::ratio<1, 5>>::value, "");
      17             : 
      18           1 :     static_assert(std::is_same<::estd::ratio<10, 50>::type, ::estd::ratio<1, 5>>::value, "");
      19             : 
      20           1 :     static_assert(std::is_same<::estd::ratio<-1, -5>::type, ::estd::ratio<1, 5>>::value, "");
      21             : 
      22           1 :     static_assert(std::is_same<::estd::ratio<-10, 50>::type, ::estd::ratio<-1, 5>>::value, "");
      23             : 
      24             :     // [EXAMPLE_RATIO_BASIC_FUNCTIONALITY_END]
      25           1 : }
      26             : 
      27           3 : TEST(RatioExample, comparison_operators)
      28             : {
      29             :     // [EXAMPLE_RATIO_COMPARISON_OPERATORS_START]
      30           1 :     static_assert(::estd::ratio_equal<::estd::ratio<1, 5>, ::estd::ratio<2, 10>>::value, "");
      31             : 
      32           1 :     static_assert(!::estd::ratio_not_equal<::estd::ratio<1, 5>, ::estd::ratio<2, 10>>::value, "");
      33             : 
      34           1 :     static_assert(!::estd::ratio_less<::estd::ratio<1, 5>, ::estd::ratio<2, 10>>::value, "");
      35             : 
      36           1 :     static_assert(!::estd::ratio_greater<::estd::ratio<1, 5>, ::estd::ratio<2, 10>>::value, "");
      37             : 
      38           1 :     static_assert(::estd::ratio_less_equal<::estd::ratio<1, 5>, ::estd::ratio<2, 10>>::value, "");
      39             : 
      40           1 :     static_assert(
      41             :         ::estd::ratio_greater_equal<::estd::ratio<1, 5>, ::estd::ratio<2, 10>>::value, "");
      42             :     // [EXAMPLE_RATIO_COMPARISON_OPERATORS_END]
      43           1 : }
      44             : 
      45           3 : TEST(RatioExample, arithmetic_operators)
      46             : {
      47             :     // [EXAMPLE_RATIO_ARITHMETIC_OPERATORS_START]
      48           1 :     {
      49           1 :         static_assert(
      50             :             std::is_same<
      51             :                 ::estd::ratio<11, 30>,
      52             :                 ::estd::ratio_add<::estd::ratio<1, 5>, ::estd::ratio<1, 6>>::type>::value,
      53             :             "");
      54             : 
      55           1 :         static_assert(
      56             :             std::is_same<
      57             :                 ::estd::ratio<1, 30>,
      58             :                 ::estd::ratio_subtract<::estd::ratio<1, 5>, ::estd::ratio<1, 6>>::type>::value,
      59             :             "");
      60             : 
      61           1 :         static_assert(
      62             :             std::is_same<
      63             :                 ::estd::ratio<7, 15>,
      64             :                 ::estd::ratio_multiply<::estd::ratio<2, 5>, ::estd::ratio<7, 6>>::type>::value,
      65             :             "");
      66             : 
      67           1 :         static_assert(
      68             :             std::is_same<
      69             :                 ::estd::ratio<4, 3>,
      70             :                 ::estd::ratio_divide<::estd::ratio<2, 4>, ::estd::ratio<3, 8>>::type>::value,
      71             :             "");
      72             :     }
      73             :     // [EXAMPLE_RATIO_ARITHMETIC_OPERATORS_END]
      74           1 : }
      75             : 
      76           3 : TEST(RatioExample, predefined_types)
      77             : {
      78             :     // [EXAMPLE_RATIO_PREDEFINED_TYPES_START]
      79           1 :     static_assert(std::is_same<::estd::ratio<1000000000000000000, 1>, ::estd::exa>::value, "");
      80             : 
      81           1 :     static_assert(std::is_same<::estd::ratio<1000000000000000, 1>, ::estd::peta>::value, "");
      82             : 
      83             :     // [EXAMPLE_RATIO_PREDEFINED_TYPES_END]
      84           1 : }

Generated by: LCOV version 1.14