31void print(
const std::vector<int32_t> &array) {
32 for (int32_t i : array) {
33 std::cout << i <<
" ";
50 const std::vector<int32_t> &second) {
51 std::vector<int32_t> res;
54 size_t f_length = first.size();
55 size_t s_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())) {
88 std::cout <<
"TEST CASE 1\n";
89 std::cout <<
"Intialized a = {} b = {}\n";
90 std::cout <<
"Expected result: {}\n";
91 std::vector<int32_t> a = {};
92 std::vector<int32_t> b = {};
93 std::vector<int32_t>
result = get_intersection(a, b);
96 std::cout <<
"TEST PASSED!\n\n";
103 std::cout <<
"TEST CASE 2\n";
104 std::cout <<
"Intialized a = {} b = {2, 3}\n";
105 std::cout <<
"Expected result: {}\n";
106 std::vector<int32_t> a = {};
107 std::vector<int32_t> b = {2, 3};
108 std::vector<int32_t>
result = get_intersection(a, b);
111 std::cout <<
"TEST PASSED!\n\n";
118 std::cout <<
"TEST CASE 3\n";
119 std::cout <<
"Intialized a = {4, 6} b = {3, 6}\n";
120 std::cout <<
"Expected result: {6}\n";
121 std::vector<int32_t> a = {4, 6};
122 std::vector<int32_t> b = {3, 6};
123 std::vector<int32_t>
result = get_intersection(a, b);
124 std::vector<int32_t> expected = {6};
125 assert(result == expected);
127 std::cout <<
"TEST PASSED!\n\n";
134 std::cout <<
"TEST CASE 4\n";
135 std::cout <<
"Intialized a = {4, 6, 6, 6} b = {2, 4, 4, 6}\n";
136 std::cout <<
"Expected result: {4, 6}\n";
137 std::vector<int32_t> a = {4, 6, 6, 6};
138 std::vector<int32_t> b = {2, 4, 4, 6};
139 std::vector<int32_t>
result = get_intersection(a, b);
140 std::vector<int32_t> expected = {4, 6};
141 assert(result == expected);
143 std::cout <<
"TEST PASSED!\n\n";
150 std::cout <<
"TEST CASE 5\n";
151 std::cout <<
"Intialized a = {1, 2, 3, 4, 6, 7, 9} b = {2, 3, 4, 5}\n";
152 std::cout <<
"Expected result: {2, 3, 4}\n";
153 std::vector<int32_t> a = {1, 2, 3, 4, 6, 7, 9};
154 std::vector<int32_t> b = {2, 3, 4, 5};
155 std::vector<int32_t>
result = get_intersection(a, b);
156 std::vector<int32_t> expected = {2, 3, 4};
157 assert(result == expected);
159 std::cout <<
"TEST PASSED!\n\n";
167 std::cout <<
"TEST CASE 6\n";
168 std::cout <<
"Intialized a = {1, 3, 3, 2, 5, 9, 4, 7, 3, 2} ";
169 std::cout <<
"b = {11, 3, 7, 8, 6}\n";
170 std::cout <<
"Expected result: {3, 7}\n";
171 std::vector<int32_t> a = {1, 3, 3, 2, 5, 9, 4, 7, 3, 2};
172 std::vector<int32_t> b = {11, 3, 7, 8, 6};
173 std::sort(a.begin(), a.end());
174 std::sort(b.begin(), b.end());
175 std::vector<int32_t> result = get_intersection(a, b);
176 std::vector<int32_t> expected = {3, 7};
177 assert(result == expected);
179 std::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 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.
void test5()
A Test to check a shift of zero.