Skip to content

Commit

Permalink
[09_queue] array_queue_test, passed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam0205 committed Oct 10, 2018
1 parent 286f925 commit 0983790
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions c-cpp/09_queue/array_queue_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <iostream>
#include "array_queue.hpp"

int main() {
auto do_traverse = [&](auto item){ std::cout << item << ' '; };

ArrayQueue<int> array_queue_1(3);
array_queue_1.enqueue(1);
array_queue_1.enqueue(2);
array_queue_1.enqueue(3);
// array_queue_1.enqueue(4); // throw
array_queue_1.traverse(do_traverse);
std::cout << std::endl;

ArrayQueue<int> array_queue_2(array_queue_1); // copy constructor
array_queue_2.traverse(do_traverse);
std::cout << std::endl;

ArrayQueue<int> array_queue_3(std::move(array_queue_2)); // move constructor
array_queue_3.traverse(do_traverse);
std::cout << std::endl;
array_queue_2.traverse(do_traverse);
std::cout << std::endl;

std::cout << array_queue_3.head() << std::endl;
array_queue_3.dequeue();
std::cout << array_queue_3.head() << std::endl;
array_queue_3.dequeue();
std::cout << array_queue_3.head() << std::endl;
array_queue_3.dequeue();
// std::cout << array_queue_3.head() << std::endl; // throw
// array_queue_3.dequeue(); // throw

ArrayQueue<int> array_queue_4(1);
array_queue_4 = array_queue_1; // copy assignment
array_queue_4.traverse(do_traverse);
std::cout << std::endl;

ArrayQueue<int> array_queue_5(100);
array_queue_5 = std::move(array_queue_4); // move assignment
array_queue_5.traverse(do_traverse);
std::cout << std::endl;
array_queue_4.traverse(do_traverse);
std::cout << std::endl;

std::cout << array_queue_5.head() << std::endl;
array_queue_5.dequeue();
std::cout << array_queue_5.head() << std::endl;
array_queue_5.dequeue();
std::cout << array_queue_5.head() << std::endl;
array_queue_5.dequeue();
// std::cout << array_queue_5.head() << std::endl; // throw
// array_queue_5.dequeue(); // throw

return 0;
}

0 comments on commit 0983790

Please sign in to comment.