mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
clang-format and clang-tidy fixes for 2405a142
This commit is contained in:
parent
2405a1423b
commit
24c901c9a5
@ -20,7 +20,8 @@
|
|||||||
namespace backtracking {
|
namespace backtracking {
|
||||||
/**
|
/**
|
||||||
* @namespace Subsets
|
* @namespace Subsets
|
||||||
* @brief Functions for the [Subset Sum](https://en.wikipedia.org/wiki/Subset_sum_problem) problem.
|
* @brief Functions for the [Subset
|
||||||
|
* Sum](https://en.wikipedia.org/wiki/Subset_sum_problem) problem.
|
||||||
*/
|
*/
|
||||||
namespace subset_sum {
|
namespace subset_sum {
|
||||||
/**
|
/**
|
||||||
@ -58,31 +59,41 @@ static void test() {
|
|||||||
// Test 1
|
// Test 1
|
||||||
std::cout << "1st test ";
|
std::cout << "1st test ";
|
||||||
std::vector<int> array1 = {-7, -3, -2, 5, 8}; // input array
|
std::vector<int> array1 = {-7, -3, -2, 5, 8}; // input array
|
||||||
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
|
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
|
||||||
std::cout << "passed" << std::endl;
|
std::cout << "passed" << std::endl;
|
||||||
|
|
||||||
// Test 2
|
// Test 2
|
||||||
std::cout << "2nd test ";
|
std::cout << "2nd test ";
|
||||||
std::vector<int> array2 = {1, 2, 3, 3};
|
std::vector<int> array2 = {1, 2, 3, 3};
|
||||||
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)}
|
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)}
|
||||||
std::cout << "passed" << std::endl;
|
std::cout << "passed" << std::endl;
|
||||||
|
|
||||||
// Test 3
|
// Test 3
|
||||||
std::cout << "3rd test ";
|
std::cout << "3rd test ";
|
||||||
std::vector<int> array3 = {1, 1, 1, 1};
|
std::vector<int> array3 = {1, 1, 1, 1};
|
||||||
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)}
|
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)}
|
||||||
std::cout << "passed" << std::endl;
|
std::cout << "passed" << std::endl;
|
||||||
|
|
||||||
// Test 4
|
// Test 4
|
||||||
std::cout << "4th test ";
|
std::cout << "4th test ";
|
||||||
std::vector<int> array4 = {3, 3, 3, 3};
|
std::vector<int> array4 = {3, 3, 3, 3};
|
||||||
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)}
|
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)}
|
||||||
std::cout << "passed" << std::endl;
|
std::cout << "passed" << std::endl;
|
||||||
|
|
||||||
// Test 5
|
// Test 5
|
||||||
std::cout << "5th test ";
|
std::cout << "5th test ";
|
||||||
std::vector<int> array5 = {};
|
std::vector<int> array5 = {};
|
||||||
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
|
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
|
||||||
std::cout << "passed" << std::endl;
|
std::cout << "passed" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user