Skip to content

Commit

Permalink
changed non-overlapping test using Key object in Node;
Browse files Browse the repository at this point in the history
  • Loading branch information
riasc committed Aug 6, 2024
1 parent 9452e52 commit 90ca434
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions tests/IBPTreeTestSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,30 @@ TEST(IBPTreeTestSuite, CreateIBPTree) {
std::srand(std::time(nullptr));
int k = 3;
IBPTree tree(k);
std::vector<std::pair<dtp::Interval, std::shared_ptr<void>>> intervals;
std::vector<std::pair<Interval, std::shared_ptr<void>>> intervals;

intervals.push_back({{0, 10}, std::make_shared<int>(rand() % 100)});
intervals.push_back({{11, 20}, std::make_shared<int>(rand() % 100)});
intervals.push_back({{21, 30}, std::make_shared<int>(rand() % 100)});
intervals.push_back({{31, 40}, std::make_shared<int>(rand() % 100)});
intervals.push_back({{41, 50}, std::make_shared<int>(rand() % 100)});
intervals.push_back({{51, 60}, std::make_shared<int>(rand() % 100)});
intervals.push_back({{61, 70}, std::make_shared<int>(rand() % 100)});
intervals.push_back({{71, 80}, std::make_shared<int>(rand() % 100)});
intervals.push_back({{81, 90}, std::make_shared<int>(rand() % 100)});
intervals.push_back({{91, 100}, std::make_shared<int>(rand() % 100)});


/*
*/
for(int i=11; i < 10000; i+=10) {
intervals.push_back({{static_cast<size_t>(i), static_cast<size_t>(i+9)},
std::make_shared<int>(rand() % 100)});
}

std::cout << "#### Inserting data into the tree ####\n";

// insert data into the tree
std::vector<std::shared_ptr<void>> dataVector;
for(auto& intvl : intervals) { // insert data
KeyPtr key = std::make_shared<Key>(intvl.first, intvl.second);
std::cout << "Inserting key: " << key->getInterval().first << "," << key->getInterval().second;
Key key{intvl.first, intvl.second};
std::cout << "Inserting key: " << key.getInterval().getStart() << "," << key.getInterval().getEnd();
std::cout << " with the data: " << *std::static_pointer_cast<int>(intvl.second) << "\n";
tree.insert("chr1", key);
}

std::cout << "#### Searching for data within the tree ####\n";

// search for data within the tree
for(auto& intvl : intervals) {
std::cout << "Searching for interval [" << intvl.first.first << "," << intvl.first.second << "]";
std::cout << "Searching for interval [" << intvl.first.getStart() << "," << intvl.first.getEnd() << "]";
std::cout << " with the data: " << *std::static_pointer_cast<int>(intvl.second);
std::vector<std::shared_ptr<void>> searchResult = tree.search("chr1", intvl.first);

Expand All @@ -42,9 +39,9 @@ TEST(IBPTreeTestSuite, CreateIBPTree) {
std::cout << *std::static_pointer_cast<int>(data) << " ";
}
std::cout << "\n";
EXPECT_EQ(searchResult.size(), 1) << "The search result for interval [" << intvl.first.first << ","
<< intvl.first.second << "] was not correct";
EXPECT_EQ(searchResult.size(), 1) << "The search result for interval [" << intvl.first.getStart() << ","
<< intvl.first.getEnd() << "] was not correct";
EXPECT_EQ(*std::static_pointer_cast<int>(searchResult[0]), *std::static_pointer_cast<int>(intvl.second))
<< "The search result for interval [" << intvl.first.first << "," << intvl.first.second << "] was not correct";
<< "The search result for interval [" << intvl.first.getStart() << "," << intvl.first.getEnd() << "] was not correct";
}
}

0 comments on commit 90ca434

Please sign in to comment.