Skip to content

Commit 9cd0763

Browse files
authored
Update subset_sum.cpp
1 parent 6407a59 commit 9cd0763

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

backtracking/subset_sum.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
namespace backtracking {
2121
/**
2222
* @namespace Subsets
23-
* @brief Functions for the [Subset
24-
* Sum](https://en.wikipedia.org/wiki/Subset_sum_problem) problem.
23+
* @brief Functions for the [Subset Sum](https://en.wikipedia.org/wiki/Subset_sum_problem) problem.
2524
*/
2625
namespace subset_sum {
2726
/**
@@ -59,41 +58,31 @@ static void test() {
5958
// Test 1
6059
std::cout << "1st test ";
6160
std::vector<int> array1 = {-7, -3, -2, 5, 8}; // input array
62-
assert(backtracking::subset_sum::subset_sum(0, array1) ==
63-
2); // first argument in subset_sum function is the required sum and
64-
// second is the input array
61+
assert(backtracking::subset_sum::subset_sum(0, array1) == 2); // first argument in subset_sum function is the required sum and second is the input array
6562
std::cout << "passed" << std::endl;
6663

6764
// Test 2
6865
std::cout << "2nd test ";
6966
std::vector<int> array2 = {1, 2, 3, 3};
70-
assert(backtracking::subset_sum::subset_sum(6, array2) ==
71-
3); // here we are expecting 3 subsets which sum up to 6 i.e.
72-
// {(1,2,3),(1,2,3),(3,3)}
67+
assert(backtracking::subset_sum::subset_sum(6, array2) == 3); // here we are expecting 3 subsets which sum up to 6 i.e. {(1,2,3),(1,2,3),(3,3)}
7368
std::cout << "passed" << std::endl;
7469

7570
// Test 3
7671
std::cout << "3rd test ";
7772
std::vector<int> array3 = {1, 1, 1, 1};
78-
assert(backtracking::subset_sum::subset_sum(1, array3) ==
79-
4); // here we are expecting 4 subsets which sum up to 1 i.e.
80-
// {(1),(1),(1),(1)}
73+
assert(backtracking::subset_sum::subset_sum(1, array3) == 4); // here we are expecting 4 subsets which sum up to 1 i.e. {(1),(1),(1),(1)}
8174
std::cout << "passed" << std::endl;
8275

8376
// Test 4
8477
std::cout << "4th test ";
8578
std::vector<int> array4 = {3, 3, 3, 3};
86-
assert(backtracking::subset_sum::subset_sum(6, array4) ==
87-
6); // here we are expecting 6 subsets which sum up to 6 i.e.
88-
// {(3,3),(3,3),(3,3),(3,3),(3,3),(3,3)}
79+
assert(backtracking::subset_sum::subset_sum(6, array4) == 6); // here we are expecting 6 subsets which sum up to 6 i.e. {(3,3),(3,3),(3,3),(3,3),(3,3),(3,3)}
8980
std::cout << "passed" << std::endl;
9081

9182
// Test 5
9283
std::cout << "5th test ";
9384
std::vector<int> array5 = {};
94-
assert(backtracking::subset_sum::subset_sum(6, array5) ==
95-
0); // here we are expecting 0 subsets which sum up to 6 i.e. we
96-
// cannot select anything from an empty array
85+
assert(backtracking::subset_sum::subset_sum(6, array5) == 0); // here we are expecting 0 subsets which sum up to 6 i.e. we cannot select anything from an empty array
9786
std::cout << "passed" << std::endl;
9887
}
9988

0 commit comments

Comments
 (0)