MCPcopy Create free account
hub / github.com/antgroup/vsag / BasicTest

Method BasicTest

src/datacell/graph_interface_test.cpp:29–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27using namespace vsag;
28
29void
30GraphInterfaceTest::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());

Callers 5

TestGraphDataCellFunction · 0.45
TestExtraInfoDataCellFunction · 0.45
TestFlattenDataCellFunction · 0.45
TestSparseGraphDataCellFunction · 0.45

Calls 15

randomFunction · 0.85
test_serializionFunction · 0.85
getMethod · 0.80
MaxCapacityMethod · 0.80
SetTotalCountMethod · 0.80
SetMaxCapacityMethod · 0.80
SetMaximumDegreeMethod · 0.80
MaximumDegreeMethod · 0.45
ResizeMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected