Skip to content

Commit 390959b

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] Code style fixes.
1 parent f18dad4 commit 390959b

18 files changed

+137
-136
lines changed

src/lib/exercises/include/exercises/foo.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#include <cstdint>
44

55
namespace foo {
6-
uint64_t add(uint64_t a, uint64_t b);
6+
uint64_t add(uint64_t a, uint64_t b);
77
};

src/lib/exercises/include/exercises/hackerrank/warmup/a_very_big_sum.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#pragma once
44

55
namespace hackerrank::warmup {
6-
long aVeryBigSum(const std::vector<long>& ar);
6+
long aVeryBigSum(const std::vector<long> &ar);
77
}

src/lib/exercises/include/exercises/hackerrank/warmup/birthday_cake_candles.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#pragma once
44

55
namespace hackerrank::warmup {
6-
int birthdayCakeCandles(const std::vector<int>& candles);
6+
int birthdayCakeCandles(const std::vector<int> &candles);
77
}

src/lib/exercises/include/exercises/hackerrank/warmup/compare_triplets.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
#pragma once
44

55
namespace hackerrank::warmup {
6-
std::vector<int> compareTriplets(const std::vector<int>& a, const std::vector<int>& b);
6+
std::vector<int> compareTriplets(const std::vector<int> &a,
7+
const std::vector<int> &b);
78
}

src/lib/exercises/include/exercises/hackerrank/warmup/diagonal_difference.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#pragma once
44

55
namespace hackerrank::warmup {
6-
int diagonalDifference(const std::vector<std::vector<int>>& arr);
6+
int diagonalDifference(const std::vector<std::vector<int>> &arr);
77
}

src/lib/exercises/include/exercises/hackerrank/warmup/simple_array_sum.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#pragma once
44

55
namespace hackerrank::warmup {
6-
int simpleArraySum(const std::vector<int>& ar);
6+
int simpleArraySum(const std::vector<int> &ar);
77
}

src/lib/exercises/src/foo.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
#include <exercises/foo.hpp>
22

3-
uint64_t foo::add(uint64_t a, uint64_t b) {
4-
return a + b;
5-
}
3+
uint64_t foo::add(uint64_t a, uint64_t b) { return a + b; }

src/lib/exercises/src/hackerrank/warmup/a_very_big_sum.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
namespace hackerrank::warmup {
1111

12-
long aVeryBigSum(const std::vector<long>& ar) {
13-
const long INIT_VALUE = 0L;
14-
return std::accumulate(ar.begin(), ar.end(), INIT_VALUE);
15-
}
16-
12+
long aVeryBigSum(const std::vector<long> &ar) {
13+
const long INIT_VALUE = 0L;
14+
return std::accumulate(ar.begin(), ar.end(), INIT_VALUE);
1715
}
16+
17+
} // namespace hackerrank::warmup

src/lib/exercises/src/hackerrank/warmup/birthday_cake_candles.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
#include <vector>
88

99
namespace hackerrank::warmup {
10-
int birthdayCakeCandles(const std::vector<int>& candles) {
11-
int counter = 0;
12-
int maximum = candles[0];
10+
int birthdayCakeCandles(const std::vector<int> &candles) {
11+
int counter = 0;
12+
int maximum = candles[0];
1313

14-
for (const int& element : candles) {
15-
if (element == maximum) {
16-
counter += 1;
17-
}
18-
if (element > maximum) {
19-
maximum = element;
20-
counter = 1;
21-
}
22-
}
23-
24-
return counter;
14+
for (const int &element : candles) {
15+
if (element == maximum) {
16+
counter += 1;
17+
}
18+
if (element > maximum) {
19+
maximum = element;
20+
counter = 1;
2521
}
22+
}
23+
24+
return counter;
2625
}
26+
} // namespace hackerrank::warmup

src/lib/exercises/src/hackerrank/warmup/compare_triplets.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@
88

99
namespace hackerrank::warmup {
1010

11-
std::vector<int> compareTriplets(const std::vector<int>& a, const std::vector<int>& b) {
12-
std::vector<int> awards = {0, 0};
11+
std::vector<int> compareTriplets(const std::vector<int> &a,
12+
const std::vector<int> &b) {
13+
std::vector<int> awards = {0, 0};
1314

14-
int i = 0;
15-
for (const int& value : a) {
16-
if (value > b[i]) {
17-
awards[0] = awards[0] + 1;
18-
}
19-
if (value < b[i]) {
20-
awards[1] = awards[1] + 1;
21-
}
22-
23-
i += 1;
24-
}
25-
return awards;
15+
int i = 0;
16+
for (const int &value : a) {
17+
if (value > b[i]) {
18+
awards[0] = awards[0] + 1;
19+
}
20+
if (value < b[i]) {
21+
awards[1] = awards[1] + 1;
2622
}
2723

24+
i += 1;
25+
}
26+
return awards;
2827
}
28+
29+
} // namespace hackerrank::warmup

src/lib/exercises/src/hackerrank/warmup/diagonal_difference.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
* @link Problem definition [[docs/hackerrank/warmup/diagonal_difference.md]]
55
*/
66

7-
#include <numeric>
8-
#include <vector>
97
#include <cstddef>
108
#include <cstdlib>
9+
#include <numeric>
10+
#include <vector>
1111

1212
namespace hackerrank::warmup {
13-
int diagonalDifference(const std::vector<std::vector<int>>& arr) {
14-
int diag1 = 0;
15-
int diag2 = 0;
16-
size_t last = arr.size() - 1L;
13+
int diagonalDifference(const std::vector<std::vector<int>> &arr) {
14+
int diag1 = 0;
15+
int diag2 = 0;
16+
size_t last = arr.size() - 1L;
1717

18-
for (int i = 0; i < arr.size(); i++) {
19-
for (int j = 0; j < arr[i].size(); j++) {
20-
if (i == j) {
21-
diag1 += arr[i][j];
22-
diag2 += arr[last - i][j];
23-
}
24-
}
25-
}
26-
return abs(diag1 - diag2);
18+
for (int i = 0; i < arr.size(); i++) {
19+
for (int j = 0; j < arr[i].size(); j++) {
20+
if (i == j) {
21+
diag1 += arr[i][j];
22+
diag2 += arr[last - i][j];
23+
}
2724
}
25+
}
26+
return abs(diag1 - diag2);
2827
}
28+
} // namespace hackerrank::warmup

src/lib/exercises/src/hackerrank/warmup/simple_array_sum.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
namespace hackerrank::warmup {
1111

12-
int simpleArraySum(const std::vector<int>& ar) {
13-
const int INIT_VALUE = 0;
14-
return std::accumulate(ar.begin(), ar.end(), INIT_VALUE);
15-
}
16-
12+
int simpleArraySum(const std::vector<int> &ar) {
13+
const int INIT_VALUE = 0;
14+
return std::accumulate(ar.begin(), ar.end(), INIT_VALUE);
1715
}
16+
17+
} // namespace hackerrank::warmup

src/tests/unit/lib/foo.test.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
#include <exercises/foo.hpp>
44

5-
TEST_CASE("adding numbers work", "[foo]")
6-
{
7-
CHECK(foo::add(0, 0) == 0);
8-
CHECK(foo::add(0, 7) == 7);
9-
CHECK(foo::add(7, 0) == 7);
10-
CHECK(foo::add(7, 7) == 14);
5+
TEST_CASE("adding numbers work", "[foo]") {
6+
CHECK(foo::add(0, 0) == 0);
7+
CHECK(foo::add(0, 7) == 7);
8+
CHECK(foo::add(7, 0) == 7);
9+
CHECK(foo::add(7, 7) == 14);
1110
}

src/tests/unit/lib/hackerrank/warmup/a_very_big_sum.test.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
#include <nlohmann/json.hpp>
1010
using json = nlohmann::json;
1111

12-
TEST_CASE("aVeryBigSum JSON Test Cases", "[warmup]")
13-
{
14-
std::filesystem::path cwd = std::filesystem::current_path();
15-
std::string path = cwd.string() + "/unit/lib/hackerrank/warmup/a_very_big_sum.testcases.json";
12+
TEST_CASE("aVeryBigSum JSON Test Cases", "[warmup]") {
13+
std::filesystem::path cwd = std::filesystem::current_path();
14+
std::string path =
15+
cwd.string() +
16+
"/unit/lib/hackerrank/warmup/a_very_big_sum.testcases.json";
1617

17-
INFO("aVeryBigSum JSON test cases FILE: " << path);
18+
INFO("aVeryBigSum JSON test cases FILE: " << path);
1819

19-
std::ifstream f(path);
20-
json data = json::parse(f);
20+
std::ifstream f(path);
21+
json data = json::parse(f);
2122

22-
for (auto testcase : data) {
23-
long result = hackerrank::warmup::aVeryBigSum(testcase["input"]);
24-
CHECK(result == testcase["expected"]);
25-
}
23+
for (auto testcase : data) {
24+
long result = hackerrank::warmup::aVeryBigSum(testcase["input"]);
25+
CHECK(result == testcase["expected"]);
26+
}
2627
}

src/tests/unit/lib/hackerrank/warmup/birthday_cake_candles.test.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
#include <nlohmann/json.hpp>
1010
using json = nlohmann::json;
1111

12-
TEST_CASE("birthdayCakeCandles JSON Test Cases", "[warmup]")
13-
{
14-
std::filesystem::path cwd = std::filesystem::current_path();
15-
std::string path = cwd.string() + "/unit/lib/hackerrank/warmup/birthday_cake_candles.testcases.json";
12+
TEST_CASE("birthdayCakeCandles JSON Test Cases", "[warmup]") {
13+
std::filesystem::path cwd = std::filesystem::current_path();
14+
std::string path =
15+
cwd.string() +
16+
"/unit/lib/hackerrank/warmup/birthday_cake_candles.testcases.json";
1617

17-
INFO("birthdayCakeCandles JSON test cases FILE: " << path);
18+
INFO("birthdayCakeCandles JSON test cases FILE: " << path);
1819

19-
std::ifstream f(path);
20-
json data = json::parse(f);
20+
std::ifstream f(path);
21+
json data = json::parse(f);
2122

22-
for (auto testcase : data) {
23-
long result = hackerrank::warmup::birthdayCakeCandles(testcase["input"]);
24-
CHECK(result == testcase["expected"]);
25-
}
23+
for (auto testcase : data) {
24+
long result = hackerrank::warmup::birthdayCakeCandles(testcase["input"]);
25+
CHECK(result == testcase["expected"]);
26+
}
2627
}

src/tests/unit/lib/hackerrank/warmup/compare_triplets.test.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,29 @@
99
#include <nlohmann/json.hpp>
1010
using json = nlohmann::json;
1111

12-
TEST_CASE("compareTriplets JSON Test Cases", "[warmup]")
13-
{
14-
std::filesystem::path cwd = std::filesystem::current_path();
15-
std::string path = cwd.string() + "/unit/lib/hackerrank/warmup/compare_triplets.testcases.json";
16-
17-
INFO("compareTriplets JSON test cases FILE: " << path);
18-
19-
std::ifstream f(path);
20-
json data = json::parse(f);
21-
22-
for (auto testcase : data) {
23-
std::vector<int> result = hackerrank::warmup::compareTriplets(testcase["a"], testcase["b"]);
24-
CHECK(result == testcase["expected"]);
25-
}
12+
TEST_CASE("compareTriplets JSON Test Cases", "[warmup]") {
13+
std::filesystem::path cwd = std::filesystem::current_path();
14+
std::string path =
15+
cwd.string() +
16+
"/unit/lib/hackerrank/warmup/compare_triplets.testcases.json";
17+
18+
INFO("compareTriplets JSON test cases FILE: " << path);
19+
20+
std::ifstream f(path);
21+
json data = json::parse(f);
22+
23+
for (auto testcase : data) {
24+
std::vector<int> result =
25+
hackerrank::warmup::compareTriplets(testcase["a"], testcase["b"]);
26+
CHECK(result == testcase["expected"]);
27+
}
2628
}
2729

28-
TEST_CASE("compareTriplets EDGE CASE empty input", "[warmup]")
29-
{
30-
std::vector<int> a;
31-
std::vector<int> b;
30+
TEST_CASE("compareTriplets EDGE CASE empty input", "[warmup]") {
31+
std::vector<int> a;
32+
std::vector<int> b;
3233

33-
std::vector<int> result = hackerrank::warmup::compareTriplets(
34-
a,
35-
b
36-
);
34+
std::vector<int> result = hackerrank::warmup::compareTriplets(a, b);
3735

38-
CHECK(result == std::vector<int>{0, 0});
36+
CHECK(result == std::vector<int>{0, 0});
3937
}

src/tests/unit/lib/hackerrank/warmup/diagonal_difference.test.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
#include <nlohmann/json.hpp>
1010
using json = nlohmann::json;
1111

12-
TEST_CASE("diagonalDifference JSON Test Cases", "[warmup]")
13-
{
14-
std::filesystem::path cwd = std::filesystem::current_path();
15-
std::string path = cwd.string() + "/unit/lib/hackerrank/warmup/diagonal_difference.testcases.json";
12+
TEST_CASE("diagonalDifference JSON Test Cases", "[warmup]") {
13+
std::filesystem::path cwd = std::filesystem::current_path();
14+
std::string path =
15+
cwd.string() +
16+
"/unit/lib/hackerrank/warmup/diagonal_difference.testcases.json";
1617

17-
INFO("diagonalDifference JSON test cases FILE: " << path);
18+
INFO("diagonalDifference JSON test cases FILE: " << path);
1819

19-
std::ifstream f(path);
20-
json data = json::parse(f);
20+
std::ifstream f(path);
21+
json data = json::parse(f);
2122

22-
for (auto testcase : data) {
23-
long result = hackerrank::warmup::diagonalDifference(testcase["matrix"]);
24-
CHECK(result == testcase["expected"]);
25-
}
23+
for (auto testcase : data) {
24+
long result = hackerrank::warmup::diagonalDifference(testcase["matrix"]);
25+
CHECK(result == testcase["expected"]);
26+
}
2627
}
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
#include <catch2/catch_test_macros.hpp>
22

33
#include <exercises/hackerrank/warmup/simple_array_sum.hpp>
4-
#include <vector>
54
#include <filesystem>
65
#include <fstream>
76
#include <nlohmann/json.hpp>
7+
#include <vector>
88

99
using json = nlohmann::json;
1010

11-
TEST_CASE("simpleArraySum", "[warmup]")
12-
{
13-
std::filesystem::path cwd = std::filesystem::current_path();
14-
std::string path = cwd.string() + "/unit/lib/hackerrank/warmup/simple_array_sum.testcases.json";
11+
TEST_CASE("simpleArraySum", "[warmup]") {
12+
std::filesystem::path cwd = std::filesystem::current_path();
13+
std::string path =
14+
cwd.string() +
15+
"/unit/lib/hackerrank/warmup/simple_array_sum.testcases.json";
1516

16-
INFO("simpleArraySum JSON test cases FILE: " << path);
17+
INFO("simpleArraySum JSON test cases FILE: " << path);
1718

18-
std::ifstream f(path);
19-
json data = json::parse(f);
19+
std::ifstream f(path);
20+
json data = json::parse(f);
2021

21-
for (auto testcase : data) {
22-
int result = hackerrank::warmup::simpleArraySum(testcase["input"]);
23-
CHECK(result == testcase["expected"]);
24-
}
22+
for (auto testcase : data) {
23+
int result = hackerrank::warmup::simpleArraySum(testcase["input"]);
24+
CHECK(result == testcase["expected"]);
25+
}
2526
}

0 commit comments

Comments
 (0)