コード例 #1
0
        public unsafe void GetAdjacent_should_work()
        {
            using (var storage = new GraphStorage())
            {
                long vertexId1, vertexId2, vertexId3, vertexId4, vertexId5;
                using (var tx = storage.WriteTransaction())
                {
                    vertexId1 = storage.AddVertex(tx, new byte[] { 1, 2, 3 });
                    vertexId2 = storage.AddVertex(tx, new byte[] { 3, 2, 1 });
                    vertexId3 = storage.AddVertex(tx, new byte[] { 4, 5, 6 });
                    vertexId4 = storage.AddVertex(tx, new byte[] { 7 });
                    vertexId5 = storage.AddVertex(tx, new byte[] { 8 });

                    storage.AddEdge(tx, vertexId1, vertexId2);
                    storage.AddEdge(tx, vertexId1, vertexId3);
                    storage.AddEdge(tx, vertexId1, vertexId5);

                    storage.AddEdge(tx, vertexId4, vertexId2);
                    storage.AddEdge(tx, vertexId4, vertexId4);
                    storage.AddEdge(tx, vertexId4, vertexId1);

                    storage.AddEdge(tx, vertexId2, vertexId3);
                    tx.Commit();
                }

                using (var tx = storage.ReadTransaction())
                {
                    var adjacentVertices = storage.GetAdjacent(tx, vertexId1).ToList();
                    adjacentVertices.Should()
                    .HaveCount(3)
                    .And.Contain(new[]
                    {
                        vertexId2,
                        vertexId3,
                        vertexId5
                    });

                    adjacentVertices = storage.GetAdjacent(tx, vertexId2).ToList();
                    adjacentVertices.Should()
                    .HaveCount(1)
                    .And.Contain(new[]
                    {
                        vertexId3
                    });

                    adjacentVertices = storage.GetAdjacent(tx, vertexId4).ToList();
                    adjacentVertices.Should()
                    .HaveCount(3)
                    .And.Contain(new[]
                    {
                        vertexId1,
                        vertexId2,
                        vertexId4
                    });
                }
            }
        }