< Summary - calculator test documentation coverage (Linux)

Information
Class: /home/runner/work/cpp-cmake-ctest-template/cpp-cmake-ctest-template/src/tests/utility/utility_test.cpp
Assembly: Default
File(s): /home/runner/work/cpp-cmake-ctest-template/cpp-cmake-ctest-template/src/tests/utility/utility_test.cpp
Line coverage
6%
Covered lines: 1
Uncovered lines: 14
Coverable lines: 15
Total lines: 133
Line coverage: 6.6%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 09/30/2026 - 03:05:56 Line coverage: 6.6% (1/15) Total lines: 133

File(s)

/home/runner/work/cpp-cmake-ctest-template/cpp-cmake-ctest-template/src/tests/utility/utility_test.cpp

#LineLine coverage
 01//#define ENABLE_UTILITY_TEST
 2
 3#include "gtest/gtest.h"
 4#include "../../utility/header/commonTypes.h"
 5#include "../../utility/header/mathUtility.h"
 6
 7#include <fstream>
 8#include <sys/stat.h>
 9#include <cstdio>
 10#ifdef _WIN32
 11  #include <direct.h>
 12#elif __linux__
 13  #include <unistd.h>
 14#endif
 15
 16
 017using namespace Coruh::Utility;
 18
 019class MathUtilityTest : public ::testing::Test {
 20 public:
 021  int a;
 22 protected:
 023  void SetUp() override {
 24    //Setup test data
 25  }
 26
 027  void TearDown() override {
 28    // Clean up test data
 29  }
 30};
 31
 32
 33
 034TEST_F(MathUtilityTest, CalculateMean) {
 35  // Test data
 36  const double data[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
 37  const int datalen = sizeof(data) / sizeof(data[0]);
 38  // Perform the calculation
 39  double result = MathUtility::calculateMean(data, datalen);
 40  // Check the result
 41  EXPECT_DOUBLE_EQ(result, 3.0);
 42}
 43
 44
 045TEST_F(MathUtilityTest, CalculateMedianOdd) {
 46  // Test data
 47  const double data[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
 48  const int datalen = sizeof(data) / sizeof(data[0]);
 49  // Perform the calculation
 50  double result = MathUtility::calculateMedian(data, datalen);
 51  // Check the result
 52  EXPECT_DOUBLE_EQ(result, 3.0);
 53}
 54
 055TEST_F(MathUtilityTest, CalculateMedianEven) {
 56  // Test data
 57  const double data[] = { 1.0, 2.0, 3.0, 4.0 };
 58  const int datalen = sizeof(data) / sizeof(data[0]);
 59  // Perform the calculation
 60  double result = MathUtility::calculateMedian(data, datalen);
 61  // Check the result
 62  EXPECT_DOUBLE_EQ(result, 2.5);
 63}
 64
 065TEST_F(MathUtilityTest, CompareDoubleLessTest) {
 66  // Test data
 67  const double val1 = 2.0;
 68  const double val2 = 4.0;
 69  // Perform the comparison
 70  int result = MathUtility::compareDouble(&val1, &val2);
 71  // Check the result
 72  EXPECT_EQ(result, -1);
 73}
 74
 075TEST_F(MathUtilityTest, CompareDoubleGreaterTest) {
 76  // Test data
 77  const double val1 = 4.0;
 78  const double val2 = 2.0;
 79  // Perform the comparison
 80  int result = MathUtility::compareDouble(&val1, &val2);
 81  // Check the result
 82  EXPECT_EQ(result, 1);
 83}
 84
 085TEST_F(MathUtilityTest, CompareDoubleEqualTest) {
 86  // Test data
 87  const double val1 = 3.0;
 88  const double val2 = 3.0;
 89  // Perform the comparison
 90  int result = MathUtility::compareDouble(&val1, &val2);
 91  // Check the result
 92  EXPECT_EQ(result, 0);
 93}
 94
 095TEST_F(MathUtilityTest, CalculateMinMaxTest_1) {
 96  // Test data
 97  const double data[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
 98  const int datalen = sizeof(data) / sizeof(data[0]);
 99  double min, max;
 100  // Perform the calculation
 101  MathUtility::calculateMinMax(data, datalen, &min, &max);
 102  // Check the result
 103  EXPECT_DOUBLE_EQ(min, 1.0);
 104  EXPECT_DOUBLE_EQ(max, 5.0);
 105}
 106
 0107TEST_F(MathUtilityTest, CalculateMinMaxTest_2) {
 108  double data[] = { 3.14, 1.0, -2.5, 7.2, -5.0 };
 109  double min, max;
 110  MathUtility::calculateMinMax(data, sizeof(data) / sizeof(data[0]), &min, &max);
 111  EXPECT_DOUBLE_EQ(min, -5.0);
 112  EXPECT_DOUBLE_EQ(max, 7.2);
 113}
 114
 115
 116
 117
 118
 119/**
 120 * @brief The main function of the test program.
 121 *
 122 * @param argc The number of command-line arguments.
 123 * @param argv An array of command-line argument strings.
 124 * @return int The exit status of the program.
 125 */
 1126int main(int argc, char **argv) {
 127#ifdef ENABLE_UTILITY_TEST
 128  ::testing::InitGoogleTest(&argc, argv);
 129  return RUN_ALL_TESTS();
 130#else
 131  return 0;
 132#endif
 133}

Methods/Properties