Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
tests Namespace Reference

Testcases to check Union of Two Arrays. More...

Functions

void test1 ()
 A Test to check an simple case. More...
 
void test2 ()
 A Test to check an empty vector. More...
 
void test3 ()
 A Test to check an invalid shift value. More...
 
void test4 ()
 A Test to check a very large input. More...
 
void test5 ()
 A Test to check a shift of zero. More...
 
void test6 ()
 A Test to check correct functionality with an array sorted using std::sort. More...
 

Detailed Description

Testcases to check Union of Two Arrays.

Testcases to check Reversal of Binary Tree.

Testcases to check intersection of Two Arrays.

Function Documentation

◆ test1()

void tests::test1 ( )

A Test to check an simple case.

< Use the BinaryTree

A Test to check an edge case (two empty arrays)

Returns
void

A Test to check an edge case (single element reversal)

< Should print 4 5 1 2 3

< Check if result is empty

< Should only print newline

< Check for equal sizes

< Ensure that there is only one element

< Check if both elements are same

< Check if result is empty

< Should only print newline

< Check if result is empty

< Should only print newline

< Check for equal sizes

< Ensure that there is only one element

< Check if both elements are same

< Check if result is empty

< Should only print newline

76 {
77 std::cout << "TEST CASE 1\n";
78 std::cout << "Initialized arr = {1, 2, 3, 4, 5}\n";
79 std::cout << "Expected result: {4, 5, 1, 2, 3}\n";
80 std::vector<int32_t> arr = {1, 2, 3, 4, 5};
82 std::vector<int32_t> expected = {4, 5, 1, 2, 3};
83 assert(res == expected);
84 print(res); ///< Should print 4 5 1 2 3
85 std::cout << "TEST PASSED!\n\n";
86}
std::vector< int32_t > shift_right(const std::vector< int32_t > &array, size_t shift)
Shifts the given vector to the right by the shift amount and returns a new vector with the result....
Definition: array_right_rotation.cpp:47
void print(uint32_t N, const std::vector< bool > &is_prime)
Definition: sieve_of_eratosthenes.cpp:44
Here is the call graph for this function:

◆ test2()

void tests::test2 ( )

A Test to check an empty vector.

A Test to check an edge case (NULL root element)

A Test to check an edge case (one empty array)

Returns
void

< Should print empty newline

< Check if result is equal to a

< Should only print newline

< Check for equal sizes

< Ensure that there is only one element

< Check if result is equal to b

< Should print 2 3

< Check if result is equal to a

< Should only print newline

< Check for equal sizes

< Ensure that there is only one element

< Check if result is equal to b

< Should print 2 3

91 {
92 std::cout << "TEST CASE 2\n";
93 std::cout << "Initialized arr = {}\n";
94 std::cout << "Expected result: {}\n";
95 std::vector<int32_t> arr = {};
97 std::vector<int32_t> expected = {};
98 assert(res == expected);
99 print(res); ///< Should print empty newline
100 std::cout << "TEST PASSED!\n\n";
101}
Here is the call graph for this function:

◆ test3()

void tests::test3 ( )

A Test to check an invalid shift value.

A Test to check correct reversal of a Binary Tree.

A Test to check correct functionality with a simple test case.

Returns
void

< 7 > 5

< Should print empty newline

< Check if result is correct

< Should print 6

< Check for equality

< Check for equality

< Check if result is correct

< Should print 2 3 4 6

< Check if result is correct

< Should print 6

< Check for equality

< Check for equality

< Check if result is correct

< Should print 2 3 4 6

106 {
107 std::cout << "TEST CASE 3\n";
108 std::cout << "Initialized arr = {1, 2, 3, 4, 5}\n";
109 std::cout << "Expected result: {}\n";
110 std::vector<int32_t> arr = {1, 2, 3, 4, 5};
111 std::vector<int32_t> res = shift_right(arr, 7); ///< 7 > 5
112 std::vector<int32_t> expected = {};
113 assert(res == expected);
114 print(res); ///< Should print empty newline
115 std::cout << "TEST PASSED!\n\n";
116}
Here is the call graph for this function:

◆ test4()

void tests::test4 ( )

A Test to check a very large input.

A Test to check correct functionality with duplicate values.

Returns
void

< Should print {420, 2, 4, ..., 418}

< Check if result is correct

< Should print 4 6

< Check if result is correct

< Should print 2 3 4 6 7

< Check if result is correct

< Should print 4 6

< Check if result is correct

< Should print 2 3 4 6 7

121 {
122 std::cout << "TEST CASE 4\n";
123 std::cout << "Initialized arr = {2, 4, ..., 420}\n";
124 std::cout << "Expected result: {420, 2, 4, ..., 418}\n";
126 for (int i = 1; i <= 210; i++) {
127 arr.push_back(i * 2);
128 }
129 print(arr);
130 std::vector<int32_t> res = shift_right(arr, 1);
131 std::vector<int32_t> expected;
132 expected.push_back(420);
133 for (int i = 0; i < 209; i++) {
134 expected.push_back(arr[i]);
135 }
136 assert(res == expected);
137 print(res); ///< Should print {420, 2, 4, ..., 418}
138 std::cout << "TEST PASSED!\n\n";
139}
T push_back(T... args)
Here is the call graph for this function:

◆ test5()

void tests::test5 ( )

A Test to check a shift of zero.

A Test to check correct functionality with a harder test case.

Returns
void

< Should print 1 2 3 4 5

< Check if result is correct

< Should print 2 3 4

< Check if result is correct

< Should print 1 2 3 4 5 6 7 9

< Check if result is correct

< Should print 2 3 4

< Check if result is correct

< Should print 1 2 3 4 5 6 7 9

144 {
145 std::cout << "TEST CASE 5\n";
146 std::cout << "Initialized arr = {1, 2, 3, 4, 5}\n";
147 std::cout << "Expected result: {1, 2, 3, 4, 5}\n";
148 std::vector<int32_t> arr = {1, 2, 3, 4, 5};
149 std::vector<int32_t> res = shift_right(arr, 0);
150 assert(res == arr);
151 print(res); ///< Should print 1 2 3 4 5
152 std::cout << "TEST PASSED!\n\n";
153}
Here is the call graph for this function:

◆ test6()

void tests::test6 ( )

A Test to check correct functionality with an array sorted using std::sort.

Returns
void

< Sort vector a

< Sort vector b

< Check if result is correct

< Should print 3 7

< Sort vector a

< Sort vector b

< Check if result is correct

< Should print 1 2 3 4 5 6 7 8 9 11

< Sort vector a

< Sort vector b

< Check if result is correct

< Should print 1 2 3 4 5 6 7 8 9 11

166 {
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()); ///< Sort vector a
174 std::sort(b.begin(), b.end()); ///< Sort vector b
176 std::vector<int32_t> expected = {3, 7};
177 assert(result == expected); ///< Check if result is correct
178 print(result); ///< Should print 3 7
179 std::cout << "TEST PASSED!\n\n";
180}
T begin(T... args)
T end(T... args)
uint64_t result(uint64_t n)
Definition: fibonacci_sum.cpp:76
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.
Definition: intersection_of_two_arrays.cpp:49
T sort(T... args)
Here is the call graph for this function: