Skip to content

Commit 47685a5

Browse files
committed
fix: removed unnecessary whitespaces
1 parent c846d8b commit 47685a5

File tree

1 file changed

+6
-32
lines changed

1 file changed

+6
-32
lines changed

greedy_algorithms/binary_addition.cpp

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
* @author [Muhammad Junaid Khalid](https://github.com/mjk22071998)
1414
*/
1515

16-
#include <algorithm>
17-
#include <cassert>
18-
#include <iostream>
19-
#include <string>
16+
#include <algorithm> /// for reverse function
17+
#include <cassert> /// for tests
18+
#include <iostream> /// for input and outputs
19+
#include <string> /// for sting class
2020

2121
/**
2222
* @namespace
@@ -52,13 +52,9 @@ class BinaryAddition {
5252
result.push_back((sum % 2) +
5353
'0'); // Append the sum's current bit to result
5454
}
55-
56-
// If there's still a carry left, append it
5755
if (carry) {
5856
result.push_back('1');
5957
}
60-
61-
// The result is built in reverse order, so reverse it before returning
6258
std::reverse(result.begin(), result.end());
6359
return result;
6460
}
@@ -68,50 +64,28 @@ class BinaryAddition {
6864
/**
6965
* Function to run tests for the addBinary method.
7066
*/
71-
void runTests() {
67+
void tests() {
7268
BinaryAddition binaryAddition;
7369

74-
// Test case for two binary strings of equal length without any carry over.
7570
assert(binaryAddition.addBinary("1010", "1101") == "10111");
76-
77-
// Test case for two binary strings of equal length with a carry over.
7871
assert(binaryAddition.addBinary("1111", "1111") == "11110");
79-
80-
// Test case for two binary strings where one is longer than the other.
8172
assert(binaryAddition.addBinary("101", "11") == "1000");
82-
83-
// Test case for a binary string of all zeros.
8473
assert(binaryAddition.addBinary("0", "0") == "0");
85-
86-
// Test case where both binary strings consist of all ones.
8774
assert(binaryAddition.addBinary("1111", "1111") == "11110");
88-
89-
// Test case where one binary string is zero and the other is non-zero.
9075
assert(binaryAddition.addBinary("0", "10101") == "10101");
9176
assert(binaryAddition.addBinary("10101", "0") == "10101");
92-
93-
// Test case for large binary numbers with many digits.
9477
assert(binaryAddition.addBinary("101010101010101010101010101010",
9578
"110110110110110110110110110110") ==
9679
"1100001100001100001100001100000");
97-
98-
// Test case where one binary string is much longer than the other.
9980
assert(binaryAddition.addBinary("1", "11111111") == "100000000");
100-
101-
// Test case for adding empty strings (edge case).
10281
assert(binaryAddition.addBinary("", "") == "");
103-
104-
// Test case where both binary strings consist of alternating ones and
105-
// zeros.
10682
assert(binaryAddition.addBinary("10101010", "01010101") == "11111111");
107-
108-
std::cout << "All tests passed!" << std::endl;
10983
}
11084

11185
/**
11286
* Main function to execute the program.
11387
*/
11488
int main() {
115-
runTests();
89+
tests();
11690
return 0;
11791
}

0 commit comments

Comments
 (0)