| 27 | using namespace vsag; |
| 28 | |
| 29 | void |
| 30 | GraphInterfaceTest::BasicTest(uint64_t max_id, |
| 31 | uint64_t count, |
| 32 | const GraphInterfacePtr& other, |
| 33 | bool test_delete) { |
| 34 | auto allocator = SafeAllocator::FactoryDefaultAllocator(); |
| 35 | auto max_degree = this->graph_->MaximumDegree(); |
| 36 | this->graph_->Resize(max_id); |
| 37 | UnorderedMap<InnerIdType, std::shared_ptr<Vector<InnerIdType>>> maps(allocator.get()); |
| 38 | std::unordered_set<InnerIdType> unique_keys; |
| 39 | while (unique_keys.size() < count) { |
| 40 | InnerIdType new_key = random() % max_id; |
| 41 | unique_keys.insert(new_key); |
| 42 | } |
| 43 | |
| 44 | std::vector<InnerIdType> keys(unique_keys.begin(), unique_keys.end()); |
| 45 | for (auto key : keys) { |
| 46 | maps[key] = std::make_shared<Vector<InnerIdType>>(allocator.get()); |
| 47 | } |
| 48 | |
| 49 | std::random_device rd; |
| 50 | std::mt19937 rng(rd()); |
| 51 | |
| 52 | for (auto& pair : maps) { |
| 53 | auto& vec_ptr = pair.second; |
| 54 | int max_possible_length = keys.size(); |
| 55 | int length = random() % (max_degree - 1) + 2; |
| 56 | length = std::min(length, max_possible_length); |
| 57 | std::vector<InnerIdType> temp_keys = keys; |
| 58 | std::shuffle(temp_keys.begin(), temp_keys.end(), rng); |
| 59 | |
| 60 | vec_ptr->resize(length); |
| 61 | for (int i = 0; i < length; ++i) { |
| 62 | (*vec_ptr)[i] = temp_keys[i]; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if (require_sorted_) { |
| 67 | for (auto& [key, value] : maps) { |
| 68 | std::sort(value->begin(), value->end()); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | for (auto& [key, value] : maps) { |
| 73 | this->graph_->InsertNeighborsById(key, *value); |
| 74 | } |
| 75 | |
| 76 | // Test GetNeighborSize |
| 77 | SECTION("Test GetNeighborSize") { |
| 78 | for (auto& [key, value] : maps) { |
| 79 | REQUIRE(this->graph_->GetNeighborSize(key) == value->size()); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // Test GetNeighbors |
| 84 | SECTION("Test GetNeighbors") { |
| 85 | for (auto& [key, value] : maps) { |
| 86 | Vector<InnerIdType> neighbors(allocator.get()); |
no test coverage detected