Example #1
0

#include "../tests/catch.hpp"
#include "../include/BinarySearchTree.h"

SCENARIO ("Size of empty tree") {
    GIVEN("Given empty tree") {
        BinarySearchTree<int> tree;

       WHEN ("Decide size") {
            THEN ("Size must be empty") {
                REQUIRE(tree.ReturnSize() == 0);
            }
        }
    }
}

SCENARIO("Size of tree with some itemps"){
    GIVEN("Given not empty tree") {
        BinarySearchTree<int> tree{11, 14, 16, 18};

        WHEN ("Decide size") {
            THEN ("Size mustn`t be empty") {
                REQUIRE(tree.ReturnSize() != 0);
            }
        }
    }

}

SCENARIO("Size of empty const tree"){
Example #2
0
#include "../tests/catch.hpp"
#include "../include/BinarySearchTree.h"

SCENARIO ("Size must decrease"){
  GIVEN ("Tree and its size"){
    BinarySearchTree<int> tree{11, 12, 15, 9, 10, 14, 17, 13};
    auto size = tree.ReturnSize();
    tree.Remove(13);
    THEN ("Size decrease"){
      REQUIRE(tree.ReturnSize() == size - 1);
    }
  }
}

SCENARIO ("Changing the tree")
{
  GIVEN ("Two trees")
  {
    WHEN ("Remove root")
    {
      BinarySearchTree<int> tree1{11};
      BinarySearchTree<int> tree2;
      tree1.Remove(11);
      THEN ("Tree must be equal"){
         REQUIRE(tree1 == tree2);
      }
    }
    WHEN ("Root without offsprings")
    {
      BinarySearchTree<int> tree1{11, 12, 9};
      BinarySearchTree<int> tree2{11, 9};