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
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ BUILDKIT_PROGRESS=plain
DOCKER_COMPOSE=docker compose

# TOOLS
COVERAGE_TOOL_OPTS=--root . --filter 'src/lib/*' --exclude "tests/*" --exclude 'build/*' --txt --txt-metric line --txt-metric branch --print-summary
COVERAGE_TOOL_OPTS = \
--root . \
--filter 'src/lib/*' \
--exclude-unreachable-branches \
--exclude-throw-branches \
--exclude-noncode-lines \
--exclude "tests/*" \
--exclude 'build/*' \
--txt \
--txt-metric line \
--txt-metric branch \
--print-summary

# C++ specific
SRC_DIR = src
Expand Down
2 changes: 0 additions & 2 deletions src/lib/exercises/src/hackerrank/projecteuler/euler003.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ 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 @@

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

Check warning on line 13 in src/lib/exercises/src/hackerrank/warmup/compare_triplets.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid explicitly specifying the template arguments by relying on the class template argument deduction.

See more on https://sonarcloud.io/project/issues?id=sir-gon_algorithm-exercises-cpp&issues=AaE4abpoM4M2kGYscT3X&open=AaE4abpoM4M2kGYscT3X&pullRequest=216

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

} // namespace hackerrank::warmup
12 changes: 3 additions & 9 deletions src/lib/exercises/src/hackerrank/warmup/mini_max_sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
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 @@ -31,17 +29,13 @@ std::string miniMaxSumCalculate(const std::vector<int> &arr) {
}

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

result << tsum - tmax << " " << tsum - tmin; // GCOVR_EXCL_BR_WITHOUT_HIT: 3/6

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

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

} // namespace hackerrank::warmup
15 changes: 7 additions & 8 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 @@

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

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

namespace hackerrank::warmup {
Expand All @@ -37,27 +37,26 @@
}
}

std::vector results = {
std::vector<double> 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())};

Check warning on line 43 in src/lib/exercises/src/hackerrank/warmup/plus_minus.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid explicitly specifying the template arguments by relying on the class template argument deduction.

See more on https://sonarcloud.io/project/issues?id=sir-gon_algorithm-exercises-cpp&issues=AaE4abnkM4M2kGYscT3W&open=AaE4abnkM4M2kGYscT3W&pullRequest=216

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

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

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; // GCOVR_EXCL_BR_WITHOUT_HIT: 2/4
std::cout << line << std::endl;
}
}
} // 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 = ""; // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
std::string line = "";

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

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; // GCOVR_EXCL_BR_WITHOUT_HIT: 2/4
std::cout << line << std::endl;
}
}
} // namespace hackerrank::warmup
12 changes: 3 additions & 9 deletions src/lib/exercises/src/hackerrank/warmup/time_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ 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 @@ -41,12 +40,9 @@ 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 @@ -57,25 +53,23 @@ 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]; // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
conversion += time[i];
if (i < tsize - 1) {
conversion += ":"; // GCOVR_EXCL_BR_WITHOUT_HIT: 1/2
conversion += ":";
}
}

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

} // namespace hackerrank::warmup
Loading