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

Testcases to check Reversal of Binary Tree. More...

Functions

void test1 ()
 < Use the BinaryTree More...
 
void test2 ()
 A Test to check an edge case (NULL root element) More...
 
void test3 ()
 A Test to check correct reversal of a Binary Tree. More...
 
void test4 ()
 A Test to check correct functionality with duplicate values. More...
 
void test5 ()
 A Test to check correct functionality with a harder test case. More...
 
void test6 ()
 A Test to check correct functionality with an array sorted using std::sort. More...
 

Detailed Description

Testcases to check Reversal of Binary Tree.

Testcases to check Union of Two Arrays.

Function Documentation

◆ test1()

void tests::test1 ( )

< Use the BinaryTree

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

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

Returns
void

< 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

167 {
168 BinaryTree bst;
169 std::vector<int64_t> pre_reversal, post_reversal;
170 std::cout << "TEST CASE 1\n";
171 std::cout << "Initializing tree with a single element (5)\n";
172 bst.add(5);
173 pre_reversal = bst.get_level_order();
174 std::cout << "Before reversal: ";
175 bst.print();
176 std::cout << "After reversal: ";
177 bst.reverse();
178 post_reversal = bst.get_level_order();
179 assert(pre_reversal.size() ==
180 post_reversal.size()); ///< Check for equal sizes
181 assert(pre_reversal.size() ==
182 1); ///< Ensure that there is only one element
183 assert(pre_reversal[0] ==
184 post_reversal[0]); ///< Check if both elements are same
185 bst.print();
186 std::cout << "TEST PASSED!\n\n";
187}
T size(T... args)
Here is the call graph for this function:

◆ test2()

void tests::test2 ( )

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

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

Returns
void

< 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 b

< Should print 2 3

191 {
192 BinaryTree bst;
193 std::vector<int64_t> pre_reversal, post_reversal;
194 std::cout << "TEST CASE 2\n";
195 std::cout << "Creating empty tree (root points to NULL)\n";
196 pre_reversal = bst.get_level_order();
197 std::cout << "Before reversal: ";
198 bst.print();
199 std::cout << "After reversal: ";
200 bst.reverse();
201 post_reversal = bst.get_level_order();
202 assert(pre_reversal.size() ==
203 post_reversal.size()); ///< Check for equal sizes
204 assert(pre_reversal.size() ==
205 0); ///< Ensure that there is only one element
206 bst.print();
207 std::cout << "TEST PASSED!\n\n";
208}
Here is the call graph for this function:

◆ test3()

void tests::test3 ( )

A Test to check correct reversal of a Binary Tree.

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

Returns
void

< Check for equality

< Check for equality

< Check if result is correct

< Should print 2 3 4 6

< Check if result is correct

< Should print 2 3 4 6

212 {
213 BinaryTree bst;
214 std::vector<int64_t> pre_reversal, post_reversal;
215 std::vector<int64_t> pre_res = {4, 3, 6, 2, 5, 7, 1};
216 std::vector<int64_t> post_res = {4, 6, 3, 7, 5, 2, 1};
217 std::cout << "TEST CASE 3\n";
218 std::cout << "Creating tree with elements (4, 6, 3, 2, 5, 7, 1)\n";
219 bst.add(4);
220 bst.add(6);
221 bst.add(3);
222 bst.add(2);
223 bst.add(5);
224 bst.add(7);
225 bst.add(1);
226 pre_reversal = bst.get_level_order();
227 assert(pre_reversal == pre_res); ///< Check for equality
228 std::cout << "Before reversal: ";
229 bst.print();
230 std::cout << "After reversal: ";
231 bst.reverse();
232 post_reversal = bst.get_level_order();
233 assert(post_reversal == post_res); ///< Check for equality
234 bst.print();
235 std::cout << "TEST PASSED!\n\n";
236}

◆ test4()

void tests::test4 ( )

A Test to check correct functionality with duplicate values.

Returns
void

< Check if result is correct

< Should print 2 3 4 6 7

149 {
150 std::cout << "TEST CASE 4\n";
151 std::cout << "Intialized a = {4, 6, 6, 7} b = {2, 3, 4}\n";
152 std::cout << "Expected result: {2, 3, 4, 6, 7}\n";
153 std::vector<int32_t> a = {4, 6, 6, 7};
154 std::vector<int32_t> b = {2, 3, 4};
156 std::vector<int32_t> expected = {2, 3, 4, 6, 7};
157 assert(result == expected); ///< Check if result is correct
158 print(result); ///< Should print 2 3 4 6 7
159 std::cout << "TEST PASSED!\n\n";
160}
uint64_t result(uint64_t n)
Definition: fibonacci_sum.cpp:76
std::vector< int32_t > get_union(const std::vector< int32_t > &first, const std::vector< int32_t > &second)
Gets the union of two sorted arrays, and returns them in a vector.
Definition: union_of_two_arrays.cpp:48
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:

◆ test5()

void tests::test5 ( )

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

Returns
void

< Check if result is correct

< Should print 1 2 3 4 5 6 7 9

165 {
166 std::cout << "TEST CASE 5\n";
167 std::cout << "Intialized a = {1, 4, 6, 7, 9} b = {2, 3, 5}\n";
168 std::cout << "Expected result: {1, 2, 3, 4, 5, 6, 7, 9}\n";
169 std::vector<int32_t> a = {1, 4, 6, 7, 9};
170 std::vector<int32_t> b = {2, 3, 5};
172 std::vector<int32_t> expected = {1, 2, 3, 4, 5, 6, 7, 9};
173 assert(result == expected); ///< Check if result is correct
174 print(result); ///< Should print 1 2 3 4 5 6 7 9
175 std::cout << "TEST PASSED!\n\n";
176}
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 1 2 3 4 5 6 7 8 9 11

182 {
183 std::cout << "TEST CASE 6\n";
184 std::cout << "Intialized a = {1, 3, 3, 2, 5, 9, 4, 3, 2} ";
185 std::cout << "b = {11, 3, 7, 8, 6}\n";
186 std::cout << "Expected result: {1, 2, 3, 4, 5, 6, 7, 8, 9, 11}\n";
187 std::vector<int32_t> a = {1, 3, 3, 2, 5, 9, 4, 3, 2};
188 std::vector<int32_t> b = {11, 3, 7, 8, 6};
189 std::sort(a.begin(), a.end()); ///< Sort vector a
190 std::sort(b.begin(), b.end()); ///< Sort vector b
192 std::vector<int32_t> expected = {1, 2, 3, 4, 5, 6, 7, 8, 9, 11};
193 assert(result == expected); ///< Check if result is correct
194 print(result); ///< Should print 1 2 3 4 5 6 7 8 9 11
195 std::cout << "TEST PASSED!\n\n";
196}
T begin(T... args)
T end(T... args)
T sort(T... args)
Here is the call graph for this function: