(
conststd::vector<int32_t> &array) {
32 for(int32_t i : array) {
33std::cout << i <<
" ";
50 conststd::vector<int32_t> &second) {
51std::vector<int32_t> res;
54 size_tf_length = first.size();
55 size_ts_length = second.size();
57 while(f_index < f_length && s_index < s_length) {
58 if(first[f_index] < second[s_index]) {
60}
else if(first[f_index] > second[s_index]) {
63 if((res.size() == 0) || (first[f_index] != res.back())) {
88std::cout <<
"TEST CASE 1\n";
89std::cout <<
"Intialized a = {} b = {}\n";
90std::cout <<
"Expected result: {}\n";
91std::vector<int32_t> a = {};
92std::vector<int32_t> b = {};
96std::cout <<
"TEST PASSED!\n\n";
103std::cout <<
"TEST CASE 2\n";
104std::cout <<
"Intialized a = {} b = {2, 3}\n";
105std::cout <<
"Expected result: {}\n";
106std::vector<int32_t> a = {};
107std::vector<int32_t> b = {2, 3};
111std::cout <<
"TEST PASSED!\n\n";
118std::cout <<
"TEST CASE 3\n";
119std::cout <<
"Intialized a = {4, 6} b = {3, 6}\n";
120std::cout <<
"Expected result: {6}\n";
121std::vector<int32_t> a = {4, 6};
122std::vector<int32_t> b = {3, 6};
124std::vector<int32_t> expected = {6};
125assert(result == expected);
127std::cout <<
"TEST PASSED!\n\n";
134std::cout <<
"TEST CASE 4\n";
135std::cout <<
"Intialized a = {4, 6, 6, 6} b = {2, 4, 4, 6}\n";
136std::cout <<
"Expected result: {4, 6}\n";
137std::vector<int32_t> a = {4, 6, 6, 6};
138std::vector<int32_t> b = {2, 4, 4, 6};
140std::vector<int32_t> expected = {4, 6};
141assert(result == expected);
143std::cout <<
"TEST PASSED!\n\n";
150std::cout <<
"TEST CASE 5\n";
151std::cout <<
"Intialized a = {1, 2, 3, 4, 6, 7, 9} b = {2, 3, 4, 5}\n";
152std::cout <<
"Expected result: {2, 3, 4}\n";
153std::vector<int32_t> a = {1, 2, 3, 4, 6, 7, 9};
154std::vector<int32_t> b = {2, 3, 4, 5};
156std::vector<int32_t> expected = {2, 3, 4};
157assert(result == expected);
159std::cout <<
"TEST PASSED!\n\n";
167std::cout <<
"TEST CASE 6\n";
168std::cout <<
"Intialized a = {1, 3, 3, 2, 5, 9, 4, 7, 3, 2} ";
169std::cout <<
"b = {11, 3, 7, 8, 6}\n";
170std::cout <<
"Expected result: {3, 7}\n";
171std::vector<int32_t> a = {1, 3, 3, 2, 5, 9, 4, 7, 3, 2};
172std::vector<int32_t> b = {11, 3, 7, 8, 6};
173std::sort(a.begin(), a.end());
174std::sort(b.begin(), b.end());
176std::vector<int32_t> expected = {3, 7};
177assert(result == expected);
179std::cout <<
"TEST PASSED!\n\n";
uint64_t result(uint64_t n)
static void test()
Function to test the correctness of get_intersection() function.
void print(const std::vector< int32_t > &array)
Prints the values of a vector sequentially, ending with a newline character.
std::vector< int32_t > get_intersection(const std::vector< int32_t > &first, const std::vector< int32_t > &second)
Gets the intersection of two sorted arrays, and returns them in a vector.
Testcases to check Union of Two Arrays.
void test1()
A Test to check an simple case.
void test4()
A Test to check a very large input.
void print(const std::vector< int32_t > &array)
Prints the values of a vector sequentially, ending with a newline character.
void test3()
A Test to check an invalid shift value.
void test6()
A Test to check correct functionality with an array sorted using std::sort.
void test2()
A Test to check an empty vector.
std::vector< int32_t > get_intersection(const std::vector< int32_t > &first, const std::vector< int32_t > &second)
Gets the intersection of two sorted arrays, and returns them in a vector.
void test5()
A Test to check a shift of zero.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4