29void print(
const std::vector<int32_t> &array) {
30 for (int32_t i : array) {
31 std::cout << i <<
" ";
46std::vector<int32_t>
shift_left(
const std::vector<int32_t> &array,
48 if (array.size() <= shift) {
51 std::vector<int32_t> res(array.size());
52 for (
size_t i = shift; i < array.size(); i++) {
53 res[i - shift] = array[i];
55 for (
size_t i = 0; i < shift; i++) {
56 res[array.size() - shift + i] =
76 std::cout <<
"TEST CASE 1\n";
77 std::cout <<
"Initialized arr = {1, 2, 3, 4, 5}\n";
78 std::cout <<
"Expected result: {3, 4, 5, 1, 2}\n";
79 std::vector<int32_t> arr = {1, 2, 3, 4, 5};
80 std::vector<int32_t> res = shift_left(arr, 2);
81 std::vector<int32_t> expected = {3, 4, 5, 1, 2};
82 assert(res == expected);
84 std::cout <<
"TEST PASSED!\n\n";
91 std::cout <<
"TEST CASE 2\n";
92 std::cout <<
"Initialized arr = {}\n";
93 std::cout <<
"Expected result: {}\n";
94 std::vector<int32_t> arr = {};
95 std::vector<int32_t> res = shift_left(arr, 2);
96 std::vector<int32_t> expected = {};
97 assert(res == expected);
99 std::cout <<
"TEST PASSED!\n\n";
106 std::cout <<
"TEST CASE 3\n";
107 std::cout <<
"Initialized arr = {1, 2, 3, 4, 5}\n";
108 std::cout <<
"Expected result: {}\n";
109 std::vector<int32_t> arr = {1, 2, 3, 4, 5};
110 std::vector<int32_t> res = shift_left(arr, 7);
111 std::vector<int32_t> expected = {};
112 assert(res == expected);
114 std::cout <<
"TEST PASSED!\n\n";
121 std::cout <<
"TEST CASE 4\n";
122 std::cout <<
"Initialized arr = {2, 4, ..., 420}\n";
123 std::cout <<
"Expected result: {4, 6, ..., 420, 2}\n";
124 std::vector<int32_t> arr;
125 for (
int i = 1; i <= 210; i++) {
126 arr.push_back(i * 2);
129 std::vector<int32_t> res = shift_left(arr, 1);
130 std::vector<int32_t> expected;
131 for (
int i = 1; i < 210; i++) {
132 expected.push_back(arr[i]);
134 expected.push_back(2);
135 assert(res == expected);
137 std::cout <<
"TEST PASSED!\n\n";
144 std::cout <<
"TEST CASE 5\n";
145 std::cout <<
"Initialized arr = {1, 2, 3, 4, 5}\n";
146 std::cout <<
"Expected result: {1, 2, 3, 4, 5}\n";
147 std::vector<int32_t> arr = {1, 2, 3, 4, 5};
148 std::vector<int32_t> res = shift_left(arr, 0);
151 std::cout <<
"TEST PASSED!\n\n";
static void test()
Function to test the correctness of shift_left() 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 > shift_left(const std::vector< int32_t > &array, size_t shift)
Shifts the given vector to the left by the shift amount and returns a new vector with the result....
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 test2()
A Test to check an empty vector.
void test5()
A Test to check a shift of zero.