< Summary - calculator library documentation coverage (Windows)

Information
Class: D:\a\cpp-cmake-ctest-template\cpp-cmake-ctest-template\src\utility\src\mathUtility.cpp
Assembly: Default
File(s): D:\a\cpp-cmake-ctest-template\cpp-cmake-ctest-template\src\utility\src\mathUtility.cpp
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 77
Line coverage: 100%
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 9/30/2026 - 3:07:40 AM Line coverage: 100% (1/1) Total lines: 77

File(s)

D:\a\cpp-cmake-ctest-template\cpp-cmake-ctest-template\src\utility\src\mathUtility.cpp

#LineLine coverage
 11/**
 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
 14double MathUtility::calculateMean(const double data[], int datalen) {
 15  double sum = 0.0;
 16
 17  for (int i = 0; i < datalen; ++i) {
 18    sum += data[i];
 19  }
 20
 21  return sum / datalen;
 22}
 23
 24double MathUtility::calculateMedian(const double data[], int datalen) {
 25
 26  //TODO: Move this memory allocation to control function
 27  double* sortedData = new double[datalen];
 28  double median = 0;
 29
 30  memcpy(sortedData, data, sizeof(double) * datalen);
 31
 32  qsort(sortedData, datalen, sizeof(double), compareDouble);
 33
 34  if (datalen % 2 == 0) {
 35    int index1 = datalen / 2 - 1;
 36    int index2 = datalen / 2;
 37    median = (sortedData[index1] + sortedData[index2]) / 2.0;
 38  }else {
 39    int index = datalen / 2;
 40    median = sortedData[index];
 41  }
 42
 43  delete[] sortedData;
 44  return median;
 45}
 46
 47int MathUtility::compareDouble(const void* a, const void* b) {
 48
 49  double val1 = *(const double*)a;
 50  double val2 = *(const double*)b;
 51
 52  if (val1 < val2) {
 53    return -1;
 54  }else if (val1 > val2) {
 55    return 1;
 56  }else {
 57    return 0;
 58  }
 59}
 60
 61void MathUtility::calculateMinMax(const double data[], int datalen, double* min, double* max) {
 62
 63  *min = data[0];
 64  *max = data[0];
 65
 66  for (int i = 1; i < datalen; ++i) {
 67
 68    if (data[i] < *min) {
 69      *min = data[i];
 70    }
 71
 72    if (data[i] > *max) {
 73      *max = data[i];
 74    }
 75  }
 76}
 77

Methods/Properties