Skip to content

Commit

Permalink
Merge branch 'hotfix/2.2.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
xorz57 committed Sep 22, 2017
2 parents b31ff36 + b715e13 commit d802f8b
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 3 deletions.
74 changes: 73 additions & 1 deletion tests/test_binary_search_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SCENARIO("Test Binary Search Tree") {
REQUIRE(result == nullptr);
}
}
WHEN("The Binary Search Tree is not empty") {
WHEN("Nodes are inserted in random order") {
REQUIRE(binary_search_tree.insert(4 , -10) == true);
REQUIRE(binary_search_tree.insert(2 , 30) == true);
REQUIRE(binary_search_tree.insert(90, -74) == true);
Expand Down Expand Up @@ -67,5 +67,77 @@ SCENARIO("Test Binary Search Tree") {
REQUIRE(result->value == 1);
}
}
WHEN("Nodes are inserted in ascending order") {
for (int i = 0; i < 10; i++) {
REQUIRE(binary_search_tree.insert(i, i*i) == true);
}
THEN("Test empty") {
REQUIRE(binary_search_tree.empty() == false);
}
THEN("Test size") {
REQUIRE(binary_search_tree.size() == 10);
}
THEN("Test height") {
REQUIRE(binary_search_tree.height() == 10);
}
THEN("Test maximum") {
auto max = binary_search_tree.maximum();
REQUIRE(max != nullptr);
REQUIRE(max->key == 9);
REQUIRE(max->value == 81);
}
THEN("Test minimum") {
auto min = binary_search_tree.minimum();
REQUIRE(min != nullptr);
REQUIRE(min->key == 0);
REQUIRE(min->value == 0);
}
THEN("Test search for a node that does not exist") {
auto result = binary_search_tree.search(1337);
REQUIRE(result == nullptr);
}
THEN("Test search for a node that does exist") {
auto result = binary_search_tree.search(3);
REQUIRE(result != nullptr);
REQUIRE(result->key == 3);
REQUIRE(result->value == 9);
}
}
WHEN("Nodes are inserted in descending order") {
for (int i = 9; i >= 0; i--) {
REQUIRE(binary_search_tree.insert(i, i*i) == true);
}
THEN("Test empty") {
REQUIRE(binary_search_tree.empty() == false);
}
THEN("Test size") {
REQUIRE(binary_search_tree.size() == 10);
}
THEN("Test height") {
REQUIRE(binary_search_tree.height() == 10);
}
THEN("Test maximum") {
auto max = binary_search_tree.maximum();
REQUIRE(max != nullptr);
REQUIRE(max->key == 9);
REQUIRE(max->value == 81);
}
THEN("Test minimum") {
auto min = binary_search_tree.minimum();
REQUIRE(min != nullptr);
REQUIRE(min->key == 0);
REQUIRE(min->value == 0);
}
THEN("Test search for a node that does not exist") {
auto result = binary_search_tree.search(1337);
REQUIRE(result == nullptr);
}
THEN("Test search for a node that does exist") {
auto result = binary_search_tree.search(3);
REQUIRE(result != nullptr);
REQUIRE(result->key == 3);
REQUIRE(result->value == 9);
}
}
}
}
74 changes: 73 additions & 1 deletion tests/test_red_black_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SCENARIO("Test Red Black Tree") {
REQUIRE(result == nullptr);
}
}
WHEN("The Red Black Tree is not empty") {
WHEN("Nodes are inserted in random order") {
REQUIRE(red_black_tree.insert(4 , -10) == true);
REQUIRE(red_black_tree.insert(2 , 30) == true);
REQUIRE(red_black_tree.insert(90, -74) == true);
Expand Down Expand Up @@ -67,5 +67,77 @@ SCENARIO("Test Red Black Tree") {
REQUIRE(result->value == 1);
}
}
WHEN("Nodes are inserted in ascending order") {
for (int i = 0; i < 10; i++) {
REQUIRE(red_black_tree.insert(i, i*i) == true);
}
THEN("Test empty") {
REQUIRE(red_black_tree.empty() == false);
}
THEN("Test size") {
REQUIRE(red_black_tree.size() == 10);
}
THEN("Test height") {
REQUIRE(red_black_tree.height() == 5);
}
THEN("Test maximum") {
auto max = red_black_tree.maximum();
REQUIRE(max != nullptr);
REQUIRE(max->key == 9);
REQUIRE(max->value == 81);
}
THEN("Test minimum") {
auto min = red_black_tree.minimum();
REQUIRE(min != nullptr);
REQUIRE(min->key == 0);
REQUIRE(min->value == 0);
}
THEN("Test search for a node that does not exist") {
auto result = red_black_tree.search(1337);
REQUIRE(result == nullptr);
}
THEN("Test search for a node that does exist") {
auto result = red_black_tree.search(3);
REQUIRE(result != nullptr);
REQUIRE(result->key == 3);
REQUIRE(result->value == 9);
}
}
WHEN("Nodes are inserted in descending order") {
for (int i = 9; i >= 0; i--) {
REQUIRE(red_black_tree.insert(i, i*i) == true);
}
THEN("Test empty") {
REQUIRE(red_black_tree.empty() == false);
}
THEN("Test size") {
REQUIRE(red_black_tree.size() == 10);
}
THEN("Test height") {
REQUIRE(red_black_tree.height() == 5);
}
THEN("Test maximum") {
auto max = red_black_tree.maximum();
REQUIRE(max != nullptr);
REQUIRE(max->key == 9);
REQUIRE(max->value == 81);
}
THEN("Test minimum") {
auto min = red_black_tree.minimum();
REQUIRE(min != nullptr);
REQUIRE(min->key == 0);
REQUIRE(min->value == 0);
}
THEN("Test search for a node that does not exist") {
auto result = red_black_tree.search(1337);
REQUIRE(result == nullptr);
}
THEN("Test search for a node that does exist") {
auto result = red_black_tree.search(3);
REQUIRE(result != nullptr);
REQUIRE(result->key == 3);
REQUIRE(result->value == 9);
}
}
}
}
74 changes: 73 additions & 1 deletion tests/test_splay_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SCENARIO("Test Splay Tree") {
REQUIRE(result == nullptr);
}
}
WHEN("The Splay Tree is not empty") {
WHEN("Nodes are inserted in random order") {
REQUIRE(splay_tree.insert(4 , -10) == true);
REQUIRE(splay_tree.insert(2 , 30) == true);
REQUIRE(splay_tree.insert(90, -74) == true);
Expand Down Expand Up @@ -67,5 +67,77 @@ SCENARIO("Test Splay Tree") {
REQUIRE(result->value == 1);
}
}
WHEN("Nodes are inserted in ascending order") {
for (int i = 0; i < 10; i++) {
REQUIRE(splay_tree.insert(i, i*i) == true);
}
THEN("Test empty") {
REQUIRE(splay_tree.empty() == false);
}
THEN("Test size") {
REQUIRE(splay_tree.size() == 10);
}
THEN("Test height") {
REQUIRE(splay_tree.height() == 10);
}
THEN("Test maximum") {
auto max = splay_tree.maximum();
REQUIRE(max != nullptr);
REQUIRE(max->key == 9);
REQUIRE(max->value == 81);
}
THEN("Test minimum") {
auto min = splay_tree.minimum();
REQUIRE(min != nullptr);
REQUIRE(min->key == 0);
REQUIRE(min->value == 0);
}
THEN("Test search for a node that does not exist") {
auto result = splay_tree.search(1337);
REQUIRE(result == nullptr);
}
THEN("Test search for a node that does exist") {
auto result = splay_tree.search(3);
REQUIRE(result != nullptr);
REQUIRE(result->key == 3);
REQUIRE(result->value == 9);
}
}
WHEN("Nodes are inserted in descending order") {
for (int i = 9; i >= 0; i--) {
REQUIRE(splay_tree.insert(i, i*i) == true);
}
THEN("Test empty") {
REQUIRE(splay_tree.empty() == false);
}
THEN("Test size") {
REQUIRE(splay_tree.size() == 10);
}
THEN("Test height") {
REQUIRE(splay_tree.height() == 10);
}
THEN("Test maximum") {
auto max = splay_tree.maximum();
REQUIRE(max != nullptr);
REQUIRE(max->key == 9);
REQUIRE(max->value == 81);
}
THEN("Test minimum") {
auto min = splay_tree.minimum();
REQUIRE(min != nullptr);
REQUIRE(min->key == 0);
REQUIRE(min->value == 0);
}
THEN("Test search for a node that does not exist") {
auto result = splay_tree.search(1337);
REQUIRE(result == nullptr);
}
THEN("Test search for a node that does exist") {
auto result = splay_tree.search(3);
REQUIRE(result != nullptr);
REQUIRE(result->key == 3);
REQUIRE(result->value == 9);
}
}
}
}

0 comments on commit d802f8b

Please sign in to comment.