79947c376b
Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2617
72 lines
2.3 KiB
C++
72 lines
2.3 KiB
C++
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
/**
|
|
* gtest/gtest.h must be included before rapidcheck/gtest.h!
|
|
*/
|
|
#include <gtest/gtest.h>
|
|
#include <rapidcheck.h>
|
|
#include <rapidcheck/gtest.h>
|
|
|
|
#include "storage/v2/storage.hpp"
|
|
|
|
/**
|
|
* It is possible to run test with custom seed with:
|
|
* RC_PARAMS="seed=1" ./random_graph
|
|
*/
|
|
RC_GTEST_PROP(RandomGraph, RandomGraph,
|
|
(std::vector<std::string> vertex_labels,
|
|
std::vector<std::string> edge_types)) {
|
|
RC_PRE(!vertex_labels.empty());
|
|
RC_PRE(!edge_types.empty());
|
|
|
|
int vertices_num = vertex_labels.size();
|
|
int edges_num = edge_types.size();
|
|
|
|
storage::Storage db;
|
|
std::vector<storage::VertexAccessor> vertices;
|
|
std::unordered_map<storage::VertexAccessor, std::string> vertex_label_map;
|
|
std::unordered_map<storage::EdgeAccessor, std::string> edge_type_map;
|
|
|
|
auto dba = db.Access();
|
|
|
|
for (auto label : vertex_labels) {
|
|
auto vertex_accessor = dba.CreateVertex();
|
|
RC_ASSERT(vertex_accessor.AddLabel(dba.NameToLabel(label)).HasValue());
|
|
vertex_label_map.insert({vertex_accessor, label});
|
|
vertices.push_back(vertex_accessor);
|
|
}
|
|
|
|
for (auto type : edge_types) {
|
|
auto &from = vertices[*rc::gen::inRange(0, vertices_num)];
|
|
auto &to = vertices[*rc::gen::inRange(0, vertices_num)];
|
|
auto maybe_edge_accessor =
|
|
dba.CreateEdge(&from, &to, dba.NameToEdgeType(type));
|
|
RC_ASSERT(maybe_edge_accessor.HasValue());
|
|
edge_type_map.insert({*maybe_edge_accessor, type});
|
|
}
|
|
|
|
dba.AdvanceCommand();
|
|
|
|
int edges_num_check = 0;
|
|
int vertices_num_check = 0;
|
|
for (auto vertex : dba.Vertices(storage::View::OLD)) {
|
|
auto label = vertex_label_map.at(vertex);
|
|
auto maybe_labels = vertex.Labels(storage::View::OLD);
|
|
RC_ASSERT(maybe_labels.HasValue());
|
|
const auto &labels = *maybe_labels;
|
|
RC_ASSERT(labels.size() == 1);
|
|
RC_ASSERT(dba.LabelToName(labels[0]) == label);
|
|
vertices_num_check++;
|
|
auto maybe_edges = vertex.OutEdges(storage::View::OLD);
|
|
RC_ASSERT(maybe_edges.HasValue());
|
|
for (auto &edge : *maybe_edges) {
|
|
const auto &type = edge_type_map.at(edge);
|
|
RC_ASSERT(dba.EdgeTypeToName(edge.EdgeType()) == type);
|
|
edges_num_check++;
|
|
}
|
|
}
|
|
RC_ASSERT(vertices_num_check == vertices_num);
|
|
RC_ASSERT(edges_num_check == edges_num);
|
|
}
|