Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 106 additions & 24 deletions test/test.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,122 @@
#include <catch2/catch_test_macros.hpp>
#include <iostream>

// uncomment and replace the following with your own headers
// #include "AVL.h"
#include <vector>
#include <random>
#include <algorithm>
#include <string>
#include "AVL.h"

using namespace std;
//UF ID: 23793962
//Name: Angela Acquista

// the syntax for defining a test is below. It is important for the name to be unique, but you can group multiple tests with [tags]. A test can have [multiple][tags] using that syntax.
TEST_CASE("Example Test Name - Change me!", "[flag]"){
// instantiate any class members that you need to test here
int one = 1;

// anything that evaluates to false in a REQUIRE block will result in a failing test
REQUIRE(one == 0); // fix me!
TEST_CASE("Test 1: Incorrect Commands", "[incorrect]"){

// all REQUIRE blocks must evaluate to true for the whole test to pass
REQUIRE(false); // also fix me!
MyAVLTree tree;
REQUIRE(tree.insert("Poo Pee", "A11y") == false);
REQUIRE(tree.insert("Doo Dee", "45679999") == false);
REQUIRE(tree.insert("Ooga Booga", "-123456") == false);
REQUIRE(tree.insert("", "87654321") == false);
REQUIRE(tree.insert("Wack Back", "1234A567") == false);
}

TEST_CASE("Test 2", "[flag]"){
// you can also use "sections" to share setup code between tests, for example:
int one = 1;
TEST_CASE("Test 2: Insert and Rotate", "[rotations]"){

MyAVLTree tree;

SECTION("Left-Left Rotation Case") {

tree.insert("third", "3");
tree.insert("second", "2");
tree.insert("first", "1");
REQUIRE((tree.inorder()).size() == 3);
REQUIRE(tree.search("3") == true);
REQUIRE(tree.search("2") == true);
REQUIRE(tree.search("1") == true);
}
SECTION("Right-Right Rotation Case") {

SECTION("num is 2") {
int num = one + 1;
REQUIRE(num == 2);
};
tree.insert("fourth", "4");
tree.insert("fifth", "5");
tree.insert("sixth", "6");
REQUIRE((tree.inorder()).size() == 3);
REQUIRE(tree.search("4") == true);
REQUIRE(tree.search("5") == true);
REQUIRE(tree.search("6") == true);
}
SECTION("Left-Right Rotation Case") {

SECTION("num is 3") {
int num = one + 2;
REQUIRE(num == 3);
};
tree.insert("ninth", "9");
tree.insert("seventh", "7");
tree.insert("eighth", "8");
REQUIRE((tree.inorder()).size() == 3);
REQUIRE(tree.search("9") == true);
REQUIRE(tree.search("8") == true);
REQUIRE(tree.search("7") == true);
}
SECTION("Right-Left Rotation Case") {

// each section runs the setup code independently to ensure that they don't affect each other
tree.insert("tenth", "10");
tree.insert("twelfth", "12");
tree.insert("eleventh", "11");
REQUIRE((tree.inorder()).size() == 3);
REQUIRE(tree.search("10") == true);
REQUIRE(tree.search("12") == true);
REQUIRE(tree.search("11") == true);
}
}

TEST_CASE("Test 3: Insert and Delete", "[deletions]"){

MyAVLTree tree;
random_device rd;
mt19937 gen(rd());
vector<string> ids, removing;

for(int i = 1; i <= 100; i++){

string id = to_string(10000000 + i);
string name = "Student" + to_string(i);
REQUIRE(tree.insert(name, id) == true);
ids.push_back(id);
}
REQUIRE(ids.size() == 100);
vector<string> ordered = tree.inorder();
REQUIRE(ordered.size() == 100);

for(size_t i = 1; i < ordered.size(); i++){

REQUIRE(stoll(ordered.at(i)) > stoll(ordered.at(i - 1)));
}
vector<string> remaining = ids;

for(int i = 0; i < 10; i++){

uniform_int_distribution<> dis(0, remaining.size() - 1);
int rand = dis(gen);
removing.push_back(remaining.at(rand));
remaining.erase(remaining.begin() + rand);
}
for(const auto& id : removing){

REQUIRE(tree.remove(id) == true);
}
vector<string> final = tree.inorder();
REQUIRE(final.size() == 90);

for(size_t i = 1; i < final.size(); i++){

REQUIRE(stoll(final.at(i)) > stoll(final.at(i - 1)));
}
for(const auto& removed : removing){

REQUIRE(tree.search(removed) == false);
}
for(const auto& remains : remaining){

REQUIRE(tree.search(remains) == true);
}
}
// you must write 5 unique, meaningful tests for credit on the testing portion of this project!

// the provided test from the template is below.
Expand Down