LCOV - code coverage report
Current view: top level - test - ioTests.cpp (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 37 37 100.0 %
Date: 2020-12-14 08:13:14 Functions: 6 6 100.0 %

          Line data    Source code
       1             : #include <gmock/gmock.h>
       2             : #include <gtest/gtest.h>
       3             : 
       4             : #include <exception>
       5             : #include <filesystem>
       6             : #include <fstream>
       7             : #include <iostream>
       8             : #include <string>
       9             : #include <vector>
      10             : 
      11             : #include "io.hpp"
      12             : 
      13             : #define DOUBLE_NEAR(x) DoubleNear((x), 4.0 * DBL_EPSILON)
      14             : 
      15             : using namespace testing;
      16             : using namespace std;
      17             : 
      18             : class TestThatIO : public Test
      19             : {
      20             : };
      21             : 
      22           2 : TEST_F(TestThatIO, FindsROCSubdirectoryInCurrentWorkingDirectory)
      23             : {
      24           1 :   string roc{"roc"};
      25           1 :   ASSERT_NO_THROW(cwd_path_to(roc));
      26             : }
      27             : 
      28           2 : TEST_F(
      29             :     TestThatIO,
      30             :     ThrowsExceptionWhenItDoesNotFindGivenSubdirectoryInCurrentWorkingDirectory)
      31             : {
      32           1 :   string roc{"foo"};
      33           2 :   ASSERT_THROW(cwd_path_to(roc), std::exception);
      34             : }
      35             : 
      36           2 : TEST_F(TestThatIO, ReadsData)
      37             : {
      38           2 :   filesystem::path dn;
      39             :   // try
      40             :   //{
      41           2 :   string roc{"roc"};
      42           1 :   dn = cwd_path_to(roc);
      43             :   //}
      44             :   // catch (const std::exception& e)
      45             :   //{
      46             :   //  cout << e.what() << '\n';
      47             :   //}
      48             : 
      49           3 :   string filename{dn / "test" / "coeff.txt"};
      50             :   // cout << filename << "\n";
      51           2 :   EXPECT_THAT(filename, EndsWith(string("roc/test/coeff.txt")));
      52             : 
      53           2 :   ifstream input{filename};
      54             :   // if (!input)
      55             :   //{
      56             :   //  perror("Error opening input file");
      57             :   //  // return -1;
      58             :   //}
      59             : 
      60           2 :   vector<double> coeffs;
      61           1 :   double time{0};
      62           1 :   double scale{0};
      63           2 :   string s;
      64           1 :   cout.precision(16);
      65           1 :   cout << scientific;
      66           1 :   int i{0};
      67        2674 :   while (getline(input, s))
      68             :   {
      69        2673 :     coeffs = read_numbers(s);
      70             : 
      71        2673 :     time = coeffs.back();
      72        2673 :     coeffs.pop_back();
      73             : 
      74        2673 :     scale = coeffs.back();
      75        2673 :     coeffs.pop_back();
      76             : 
      77             :     // For testing exercise output operator << on first line read
      78        2673 :     if (i == 0)
      79             :     {
      80           1 :       cout << coeffs;
      81           1 :       cout << "T     = " << time << '\n';
      82           1 :       cout << "Scale = " << scale << '\n';
      83           1 :       cout << "Size  = " << coeffs.size() << '\n';
      84           1 :       i++;
      85             :     }
      86        2673 :     EXPECT_THAT(time, Ge(0.0));
      87        2673 :     EXPECT_THAT(scale, Gt(0.0));
      88        2673 :     EXPECT_THAT(coeffs.size(), Eq(31));
      89             :   }
      90           1 :   input.close();
      91           1 : }

Generated by: LCOV version 1.14