avl_tree_test.hxx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef AVL_TREE_TEST_HXX
  2. #define AVL_TREE_TEST_HXX
  3. #include "tester.hxx"
  4. #include "libbinom/include/binom_impl/avl_tree.hxx"
  5. #include "libbinom/include/variables/key_value.hxx"
  6. #include "libbinom/include/utils/reverse_iterator.hxx"
  7. #include "print_variable.hxx"
  8. void printAVLTree(binom::priv::AVLTree& avl_tree) {
  9. TEST_ANNOUNCE(AVL Tree print:)
  10. GRP_PUSH
  11. for(auto& element : reverse_iterator::ReverseRange(avl_tree)) {
  12. binom::utils::printVariable(element.getKey());
  13. }
  14. GRP_POP
  15. }
  16. void testAVLTree() {
  17. using namespace binom;
  18. using namespace binom::priv;
  19. using AVLNode = AVLTree::AVLNode;
  20. RAIIPerfomanceTest test_perf("AVLTree test: ");
  21. SEPARATOR
  22. TEST_ANNOUNCE(AVLTree test)
  23. GRP_PUSH
  24. TEST_ANNOUNCE(AVLTree nodes inserting...)
  25. GRP_PUSH
  26. PRINT_RUN(AVLTree avl_tree);
  27. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(5))));
  28. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(.125))));
  29. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(20))));
  30. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(1))));
  31. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(.25))));
  32. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(literals::ui16arr{1,2,3,4,5,6,7,8,9,10}))));
  33. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(256))));
  34. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(256_ui64))));
  35. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(74))));
  36. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(-.0))));
  37. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(.125_f32))));
  38. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(83))));
  39. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(.0_f32))));
  40. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(20_ui16))));
  41. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(.5))));
  42. PRINT_RUN(avl_tree.insert(new AVLNode(KeyValue(literals::ui8arr{1,2,3,4,5,6,7,8,9,10}))));
  43. printAVLTree(avl_tree);
  44. GRP_POP
  45. TEST_ANNOUNCE(AVLTree nodes removing...)
  46. GRP_PUSH
  47. PRINT_RUN(delete avl_tree.extract(KeyValue(5)));
  48. PRINT_RUN(delete avl_tree.extract(KeyValue(.125)));
  49. PRINT_RUN(delete avl_tree.extract(KeyValue(20)));
  50. PRINT_RUN(delete avl_tree.extract(KeyValue(1)));
  51. PRINT_RUN(delete avl_tree.extract(KeyValue(.25)));
  52. PRINT_RUN(delete avl_tree.extract(KeyValue(literals::ui16arr{1,2,3,4,5,6,7,8,9,10})));
  53. PRINT_RUN(delete avl_tree.extract(KeyValue(256)));
  54. printAVLTree(avl_tree);
  55. PRINT_RUN(delete avl_tree.extract(KeyValue(256_ui64)));
  56. PRINT_RUN(delete avl_tree.extract(KeyValue(74)));
  57. PRINT_RUN(delete avl_tree.extract(KeyValue(-.0)));
  58. PRINT_RUN(delete avl_tree.extract(KeyValue(.125_f32)));
  59. PRINT_RUN(delete avl_tree.extract(KeyValue(83)));
  60. PRINT_RUN(delete avl_tree.extract(KeyValue(.0_f32)));
  61. PRINT_RUN(delete avl_tree.extract(KeyValue(20_ui16)));
  62. PRINT_RUN(delete avl_tree.extract(KeyValue(.5)));
  63. PRINT_RUN(delete avl_tree.extract(KeyValue(literals::ui8arr{1,2,3,4,5,6,7,8,9,10})));
  64. printAVLTree(avl_tree);
  65. GRP_POP
  66. GRP_POP
  67. }
  68. #endif // AVL_TREE_TEST_HXX