< Summary - calculator unit test code coverage (Linux)

Information
Class: /home/runner/work/cpp-cmake-ctest-template/cpp-cmake-ctest-template/src/utility/src/mathUtility.cpp
Assembly: Default
File(s): /home/runner/work/cpp-cmake-ctest-template/cpp-cmake-ctest-template/src/utility/src/mathUtility.cpp
Line coverage
100%
Covered lines: 35
Uncovered lines: 0
Coverable lines: 35
Total lines: 77
Line coverage: 100%
Branch coverage
88%
Covered branches: 16
Total branches: 18
Branch coverage: 88.8%
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:06:01 Line coverage: 100% (35/35) Branch coverage: 88.8% (16/18) Total lines: 77 09/30/2026 - 03:06:01 Line coverage: 100% (35/35) Branch coverage: 88.8% (16/18) Total lines: 77

File(s)

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

#LineLine coverage
 1/**
 2 * @file mathUtility.cpp
 3 *
 4 * @brief Provides functions for math. utilities
 5 */
 6
 7#include <cstring>
 8
 9#include "../header/mathUtility.h"
 10
 11using namespace Coruh::Utility;
 12
 13
 114double MathUtility::calculateMean(const double data[], int datalen) {
 115  double sum = 0.0;
 16
 617  for (int i = 0; i < datalen; ++i) {
 518    sum += data[i];
 19  }
 20
 121  return sum / datalen;
 22}
 23
 224double MathUtility::calculateMedian(const double data[], int datalen) {
 25
 26  //TODO: Move this memory allocation to control function
 227  double* sortedData = new double[datalen];
 228  double median = 0;
 29
 230  memcpy(sortedData, data, sizeof(double) * datalen);
 31
 232  qsort(sortedData, datalen, sizeof(double), compareDouble);
 33
 234  if (datalen % 2 == 0) {
 135    int index1 = datalen / 2 - 1;
 136    int index2 = datalen / 2;
 137    median = (sortedData[index1] + sortedData[index2]) / 2.0;
 38  }else {
 139    int index = datalen / 2;
 140    median = sortedData[index];
 41  }
 42
 243  delete[] sortedData;
 244  return median;
 45}
 46
 1247int MathUtility::compareDouble(const void* a, const void* b) {
 48
 1249  double val1 = *(const double*)a;
 1250  double val2 = *(const double*)b;
 51
 1252  if (val1 < val2) {
 1053    return -1;
 254  }else if (val1 > val2) {
 155    return 1;
 56  }else {
 157    return 0;
 58  }
 59}
 60
 261void MathUtility::calculateMinMax(const double data[], int datalen, double* min, double* max) {
 62
 263  *min = data[0];
 264  *max = data[0];
 65
 1066  for (int i = 1; i < datalen; ++i) {
 67
 868    if (data[i] < *min) {
 369      *min = data[i];
 70    }
 71
 872    if (data[i] > *max) {
 573      *max = data[i];
 74    }
 75  }
 276}
 77