Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/cpp-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ jobs:

- name: Install Tools
run: |
sudo apt-get update
sudo apt-get install lcov
pip install --only-binary :all: gcovr==8.6

- name: Check Tools
run: |
Expand All @@ -42,7 +41,7 @@ jobs:
echo "-----------"
vcpkg --version
echo "-----------"
lcov --version
gcovr --version

- name: Install dependencies
run: |
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/make-coverage-html.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ jobs:

- name: Install Tools
run: |
sudo apt-get update
sudo apt-get install lcov
pip install --only-binary :all: gcovr==8.6

- name: Check Tools
run: |
Expand All @@ -42,7 +41,7 @@ jobs:
echo "-----------"
vcpkg --version
echo "-----------"
lcov --version
gcovr --version
echo "-----------"

- name: Run coverage HTML target
Expand Down
13 changes: 3 additions & 10 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ jobs:
fetch-depth: 0
- name: Install Tools
run: |
sudo apt-get install lcov
sudo rm /usr/lib/python3.*/EXTERNALLY-MANAGED
pip install --only-binary :all: gcovr==8.6

- name: Check Tools
Expand All @@ -42,8 +40,6 @@ jobs:
echo "-----------"
vcpkg --version
echo "-----------"
lcov --version
echo "-----------"
gcovr --version

- name: Install dependencies
Expand All @@ -57,13 +53,10 @@ jobs:
run: |
export VCPKG_ROOT=/usr/local/share/vcpkg
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make build
- name: Run tests to generate coverage statistics
run: |
make coverage

- name: Collect coverage into one XML report
- name: Make coverage report
run: |
gcovr -e "src/tests/*" --sonarqube > coverage.xml
make coverage

- name: Analyze with SonarQube / SonarCloud
uses: SonarSource/sonarqube-scan-action@d209202bc7d53ff1cc128f7f907dac145c9d6ae9
Expand All @@ -73,4 +66,4 @@ jobs:
# Consult https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/scanners/sonarscanner/ for more information and options
args: >
--define sonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json
--define sonar.coverageReportPaths=coverage.xml
--define sonar.coverageReportPaths=coverage/coverage.xml
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ BUILDKIT_PROGRESS=plain
DOCKER_COMPOSE=docker compose

# TOOLS
COVERAGE_TOOL_OPTS=--config-file .lcovrc --ignore-errors empty --ignore-errors inconsistent
COVERAGE_TOOL_OPTS=--root . --filter 'src/lib/*' --exclude "tests/*" --exclude 'build/*' --txt --txt-metric line --txt-metric branch --print-summary

# C++ specific
SRC_DIR = src
Expand Down Expand Up @@ -125,14 +125,14 @@ test-no-deps:
cd build && make test

coverage: test
lcov ${COVERAGE_TOOL_OPTS} -o coverage/lcov.info \
--no-external --capture \
--exclude "build/vcpkg_installed" \
--exclude "tests/*" \
--directory .

coverage/html: coverage
genhtml ${COVERAGE_TOOL_OPTS} -o coverage/ --show-details --legend coverage/lcov.info
gcovr ${COVERAGE_TOOL_OPTS} \
--lcov coverage/coverage.lcov \
--sonarqube coverage/coverage.xml

coverage/html: test
gcovr ${COVERAGE_TOOL_OPTS} \
--html-details coverage/index.html

@if [ "$$(uname)" = "Darwin" ]; then \
open coverage/index.html; \
elif [ "$$(uname | tr '[:upper:]' '[:lower:]')" = "mingw32" ] || [ "$$(uname | tr '[:upper:]' '[:lower:]')" = "mingw64" ] || [ "$$(uname | tr '[:upper:]' '[:lower:]')" = "cygwin" ]; then \
Expand Down
2 changes: 2 additions & 0 deletions src/lib/exercises/src/hackerrank/projecteuler/euler003.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ namespace hackerrank::projecteuler {

long prime_factor(long n) {
if (n < 2) {
// GCOVR_EXCL_START
throw std::invalid_argument("n must be greater than 2");
// GCOVR_EXCL_STOP
}

long divisor = n;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/exercises/src/hackerrank/warmup/compare_triplets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace hackerrank::warmup {

std::vector<int> compareTriplets(const std::vector<int> &a,
const std::vector<int> &b) {
std::vector<int> awards = {0, 0};
std::vector awards = {0, 0};

int i = 0;
for (const int &value : a) {
Expand All @@ -24,6 +24,6 @@ std::vector<int> compareTriplets(const std::vector<int> &a,
i += 1;
}
return awards;
}
} // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2

} // namespace hackerrank::warmup
12 changes: 9 additions & 3 deletions src/lib/exercises/src/hackerrank/warmup/mini_max_sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
namespace hackerrank::warmup {
std::string miniMaxSumCalculate(const std::vector<int> &arr) {
if (arr.size() < 2) {
// GCOVR_EXCL_START
throw std::invalid_argument("List too short. Pass at least 2 elements.");
// GCOVR_EXCL_STOP
}

long long tsum = 0;
Expand All @@ -29,13 +31,17 @@ std::string miniMaxSumCalculate(const std::vector<int> &arr) {
}

std::stringstream result;
result << tsum - tmax << " " << tsum - tmin;

return result.str();
result << tsum - tmax << " " << tsum - tmin; // GCOVR_EXCL_BR_WITHOUT_HIT: 3/6

return result.str(); // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
}

void miniMaxSum(const std::vector<int> &arr) {
std::cout << miniMaxSumCalculate(arr) << std::endl;
const auto result = miniMaxSumCalculate(arr);
// GCOVR_EXCL_START
std::cout << result << std::endl;
// GCOVR_EXCL_STOP
}

} // namespace hackerrank::warmup
15 changes: 8 additions & 7 deletions src/lib/exercises/src/hackerrank/warmup/plus_minus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const int BUFFER_MAX_SIZE = 10;

std::string format_result(double number) {
std::string str;
str.reserve(BUFFER_MAX_SIZE);
str.reserve(BUFFER_MAX_SIZE); // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
char *buffer = str.data();

snprintf(buffer, BUFFER_MAX_SIZE, "%0.6lf", number);
return buffer;
return buffer; // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
}

namespace hackerrank::warmup {
Expand All @@ -37,26 +37,27 @@ std::vector<std::string> plusMinusCalculate(const std::vector<int> &arr) {
}
}

std::vector<double> results = {
std::vector results = {
static_cast<double>(positives) / static_cast<double>(arr.size()),
static_cast<double>(negatives) / static_cast<double>(arr.size()),
static_cast<double>(zeros) / static_cast<double>(arr.size())};

std::vector<std::string> answer = {};

for (double tmp : results) {
std::string formatted = format_result(tmp);
answer.emplace_back(formatted);
std::string formatted =
format_result(tmp); // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
answer.emplace_back(formatted); // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
}

return answer;
}
} // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2

void plusMinus(const std::vector<int> &arr) {
std::vector<std::string> output = plusMinusCalculate(arr);

for (const std::string &line : output) {
std::cout << line << std::endl;
std::cout << line << std::endl; // GCOVR_EXCL_BR_WITHOUT_HIT: 2/4
}
}
} // namespace hackerrank::warmup
12 changes: 6 additions & 6 deletions src/lib/exercises/src/hackerrank/warmup/staircase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ std::vector<std::string> staircaseCalculate(int n) {
std::vector<std::string> answer;

for (int i = 0; i < n; i++) {
std::string line = "";
std::string line = ""; // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2

for (int j = 0; j < n; j++) {
if (j < n - i - 1) {
line += " ";
line += " "; // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
} else {
line += "#";
line += "#"; // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
}
}
answer.emplace_back(line);
answer.emplace_back(line); // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
}

return answer;
}
} // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2

void staircase(int n) {
std::vector<std::string> output = staircaseCalculate(n);

for (const std::string &line : output) {
std::cout << line << std::endl;
std::cout << line << std::endl; // GCOVR_EXCL_BR_WITHOUT_HIT: 2/4
}
}
} // namespace hackerrank::warmup
12 changes: 9 additions & 3 deletions src/lib/exercises/src/hackerrank/warmup/time_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ std::string timeConversion(const std::string &s) {
char TIME_SEPARATOR = ':';
std::string meridian = lastN(s, 2);

// GCOVR_EXCL_START
auto time_str = std::stringstream(firstN(s, s.size() - 2));
std::string segment;
std::vector<std::string> time;
Expand All @@ -40,9 +41,12 @@ std::string timeConversion(const std::string &s) {

int hour;
hour_str >> hour;
// GCOVR_EXCL_STOP

if (hour < 0 || hour > 23) {
// GCOVR_EXCL_START
throw std::invalid_argument("Invalid hour value: " + std::to_string(hour));
// GCOVR_EXCL_STOP
}

if (hour >= 12) {
Expand All @@ -53,23 +57,25 @@ std::string timeConversion(const std::string &s) {
hour += 12;
}

// GCOVR_EXCL_START
hour_str.str("");
hour_str.clear();

hour_str << std::setfill('0') << std::setw(2) << (hour % 24);

time[0] = hour_str.str();
// GCOVR_EXCL_STOP

std::string conversion;
unsigned long tsize = time.size();
for (int i = 0; i < tsize; i++) {
conversion += time[i];
conversion += time[i]; // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
if (i < tsize - 1) {
conversion += ":";
conversion += ":"; // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
}
}

return conversion;
}
} // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2

} // namespace hackerrank::warmup
Loading