LCOV - code coverage report
Current view: top level - JCmeasure/test - MeasureEntropy_test.cpp (source / functions) Hit Total Coverage
Test: runTests_coverage.info.cleaned Lines: 48 49 98.0 %
Date: 2020-08-02 02:02:29 Functions: 30 30 100.0 %
Branches: 97 258 37.6 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * MeasureEntropy_test.cpp
       3                 :            :  *
       4                 :            :  *  Created on: 20.02.2019
       5                 :            :  *      Author: kai
       6                 :            :  */
       7                 :            : 
       8                 :            : #include "spdlog/spdlog.h"
       9                 :            : #include "../MeasureEntropy.h"
      10                 :            : #include <gtest/gtest.h>
      11                 :            : 
      12                 :            : extern std::string pathData;
      13                 :            : 
      14                 :            : namespace jastacry {
      15                 :            : 
      16 [ +  - ][ +  - ]:          8 : TEST(MeasureEntropyTest, Construct) {
                 [ +  - ]
      17         [ +  - ]:          2 :         std::string sPath = pathData;
      18         [ +  - ]:          1 :         sPath = sPath + "/test1.dat";
      19                 :            : 
      20 [ +  - ][ +  - ]:          2 :         jastacry::MeasureEntropy m(sPath);
      21         [ +  - ]:          1 :         double r = m.getResult();
      22 [ +  - ][ -  + ]:          1 :         ASSERT_DOUBLE_EQ(r, 0.0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
      23                 :            : }
      24                 :            : 
      25 [ +  - ][ +  - ]:          8 : TEST(MeasureEntropyTest, NoFile) {
                 [ +  - ]
      26         [ +  - ]:          2 :         std::string sPath = pathData;
      27         [ +  - ]:          1 :         sPath = sPath + "/notexist.dat";
      28 [ +  - ][ +  - ]:          2 :         EXPECT_THROW({
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
           [ -  +  #  #  
          #  #  #  #  #  
              # ][ +  - ]
                 [ #  # ]
      29                 :            :                 try {
      30                 :            :                         jastacry::MeasureEntropy m(sPath);
      31                 :            :                 } catch(std::invalid_argument const& e) {
      32                 :            :                         EXPECT_EQ(e.what(), std::string(sPath));
      33                 :            :                         throw;
      34                 :            :                 }
      35                 :          0 :         }, std::invalid_argument);
      36         [ -  + ]:          2 : }
      37                 :            : 
      38 [ +  - ][ +  - ]:          8 : TEST(MeasureEntropyTest, ConstructCopy) {
                 [ +  - ]
      39         [ +  - ]:          2 :         std::string sPath = pathData;
      40         [ +  - ]:          1 :         sPath = sPath + "/test1.dat";
      41                 :            : 
      42 [ +  - ][ +  - ]:          2 :         jastacry::MeasureEntropy m1(sPath);
      43 [ +  - ][ +  - ]:          2 :         jastacry::MeasureEntropy m2(m1);
      44         [ +  - ]:          1 :         double r = m2.getResult();
      45 [ +  - ][ -  + ]:          1 :         ASSERT_DOUBLE_EQ(r, 0.0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
      46                 :            : }
      47                 :            : 
      48 [ +  - ][ +  - ]:          8 : TEST(MeasureEntropyTest, ConstructCopyOp) {
                 [ +  - ]
      49         [ +  - ]:          2 :         std::string sPath = pathData;
      50         [ +  - ]:          1 :         sPath = sPath + "/test1.dat";
      51                 :            : 
      52 [ +  - ][ +  - ]:          2 :         jastacry::MeasureEntropy m1(sPath);
      53 [ +  - ][ +  - ]:          2 :         jastacry::MeasureEntropy m2 = m1;
      54         [ +  - ]:          1 :         double r = m2.getResult();
      55 [ +  - ][ -  + ]:          1 :         ASSERT_DOUBLE_EQ(r, 0.0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
      56                 :            : }
      57                 :            : 
      58 [ +  - ][ +  - ]:          8 : TEST(MeasureEntropyTest, Calculate) {
                 [ +  - ]
      59         [ +  - ]:          2 :         std::string sPath = pathData;
      60         [ +  - ]:          1 :         sPath = sPath + "/test1.dat";
      61                 :            : 
      62 [ +  - ][ +  - ]:          2 :         jastacry::MeasureEntropy m(sPath);
      63         [ +  - ]:          1 :         m.measure();
      64         [ +  - ]:          1 :         double r = m.getResult();
      65 [ +  - ][ -  + ]:          1 :         ASSERT_NEAR(r, 2.9, 0.1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ +  - ]
      66                 :            : 
      67 [ +  - ][ +  - ]:          1 :         m.printResult();
      68                 :            : }
      69                 :            : 
      70 [ +  - ][ +  - ]:          8 : TEST(MeasureEntropyTest, CalculateZeroes) {
                 [ +  - ]
      71         [ +  - ]:          2 :         std::string sPath = pathData;
      72         [ +  - ]:          1 :         sPath = sPath + "/zeroes.dat";
      73                 :            : 
      74 [ +  - ][ +  - ]:          2 :         jastacry::MeasureEntropy m(sPath);
      75         [ +  - ]:          1 :         m.measure();
      76         [ +  - ]:          1 :         double r = m.getResult();
      77 [ +  - ][ -  + ]:          1 :         ASSERT_DOUBLE_EQ(r, 0.0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
      78                 :            : }
      79                 :            : 
      80 [ +  - ][ +  - ]:          8 : TEST(MeasureEntropyTest, CalculateRandom) {
                 [ +  - ]
      81         [ +  - ]:          2 :         std::string sPath = pathData;
      82         [ +  - ]:          1 :         sPath = sPath + "/random.dat";
      83                 :            : 
      84 [ +  - ][ +  - ]:          2 :         jastacry::MeasureEntropy m(sPath);
      85         [ +  - ]:          1 :         m.measure();
      86         [ +  - ]:          1 :         double r = m.getResult();
      87 [ +  - ][ -  + ]:          1 :         ASSERT_NEAR(r, 7.8, 0.2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
      88                 :            : }
      89                 :            : 
      90 [ +  - ][ +  - ]:          4 : } /* namespace jastacry */

Generated by: LCOV version 1.13