# Algorithms_in_C++: tests Namespace Reference

Loading...
Searching...
No Matches
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.

Testcases to check Circular Linked List.

## 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)

A Test to check a single value.

Returns
  void

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

< Should print 3 4 5 1 2

< 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

< 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

{
std::cout << "TEST CASE 1\n";
std::cout << "Initialized arr = {1, 2, 3, 4, 5}\n";
std::cout << "Expected result: {3, 4, 5, 1, 2}\n";
std::vector<int32_t> arr = {1, 2, 3, 4, 5};
std::vector<int32_t> res = shift_left(arr, 2);
std::vector<int32_t> expected = {3, 4, 5, 1, 2};
assert(res == expected);
print(res); ///< Should print 3 4 5 1 2
std::cout << "TEST PASSED!\n\n";
}
std::cout
std::vector

## 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)

A Test to check a few values.

Returns
  void

< Should print empty newline

< 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

< 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

{
std::cout << "TEST CASE 2\n";
std::cout << "Initialized arr = {}\n";
std::cout << "Expected result: {}\n";
std::vector<int32_t> arr = {};
std::vector<int32_t> res = shift_left(arr, 2);
std::vector<int32_t> expected = {};
assert(res == expected);
print(res); ///< Should print empty newline
std::cout << "TEST PASSED!\n\n";
}

## 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.

A Test to check an input array.

Returns
  void

< 7 > 5

< Should print empty newline

< 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

< 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

{
std::cout << "TEST CASE 3\n";
std::cout << "Initialized arr = {1, 2, 3, 4, 5}\n";
std::cout << "Expected result: {}\n";
std::vector<int32_t> arr = {1, 2, 3, 4, 5};
std::vector<int32_t> res = shift_left(arr, 7); ///< 7 > 5
std::vector<int32_t> expected = {};
assert(res == expected);
print(res); ///< Should print empty newline
std::cout << "TEST PASSED!\n\n";
}

## test4()

void tests::test4 | ( |  | ) |

A Test to check a very large input.

A Test to check correct functionality with duplicate values.

A Test to check using a specific Node as the starting point.

Returns
  void

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

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

< Node we will start printing from

< Check if result is correct

< Should print 4 6

< Check if result is correct

< Should print 2 3 4 6 7

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

< Node we will start printing from

< Check if result is correct

< Should print 4 6

< Check if result is correct

< Should print 2 3 4 6 7

{
std::cout << "TEST CASE 4\n";
std::cout << "Initialized arr = {2, 4, ..., 420}\n";
std::cout << "Expected result: {4, 6, ..., 420, 2}\n";
std::vector<int32_t> arr;
for (int i = 1; i <= 210; i++) {
arr.push_back(i * 2);
}
print(arr);
std::vector<int32_t> res = shift_left(arr, 1);
std::vector<int32_t> expected;
for (int i = 1; i < 210; i++) {
expected.push_back(arr[i]);
}
expected.push_back(2);
assert(res == expected);
print(res); ///< Should print {4, 6, ..., 420, 2}
std::cout << "TEST PASSED!\n\n";
}
std::vector::push_back
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.

A Test to check an empty list.

Returns
  void

< Should print 1 2 3 4 5

< 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

< 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

{
std::cout << "TEST CASE 5\n";
std::cout << "Initialized arr = {1, 2, 3, 4, 5}\n";
std::cout << "Expected result: {1, 2, 3, 4, 5}\n";
std::vector<int32_t> arr = {1, 2, 3, 4, 5};
std::vector<int32_t> res = shift_left(arr, 0);
assert(res == arr);
print(res); ///< Should print 1 2 3 4 5
std::cout << "TEST PASSED!\n\n";
}

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

{
std::cout << "TEST CASE 6\n";
std::cout << "Intialized a = {1, 3, 3, 2, 5, 9, 4, 7, 3, 2} ";
std::cout << "b = {11, 3, 7, 8, 6}\n";
std::cout << "Expected result: {3, 7}\n";
std::vector<int32_t> a = {1, 3, 3, 2, 5, 9, 4, 7, 3, 2};
std::vector<int32_t> b = {11, 3, 7, 8, 6};
std::sort(a.begin(), a.end()); ///< Sort vector a
std::sort(b.begin(), b.end()); ///< Sort vector b
std::vector<int32_t> result = get_intersection(a, b);
std::vector<int32_t> expected = {3, 7};
assert(result == expected); ///< Check if result is correct
print(result); ///< Should print 3 7
std::cout << "TEST PASSED!\n\n";
}
std::vector::begin
T begin(T... args)
std::vector::end
T end(T... args)
math::fibonacci_sum::result
uint64_t result(uint64_t n)
Definition: fibonacci_sum.cpp:76
operations_on_datastructures::get_intersection
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
std::sort
T sort(T... args)
Here is the call graph for this function: