Пример #1
0
        public void SaveGraph_LoadGraph_ReturnsEqualGraph(
            int obstaclePercent, int[] graphParams)
        {
            graphAssembler = new GraphAssemble(
                vertexFactory,
                coordinateFactory,
                graphFactory,
                costFactory,
                radarFactory);

            IGraph deserialized;
            var    graph = graphAssembler.AssembleGraph(
                obstaclePercent, graphParams);
            var serializer = new GraphSerializer(
                formatter, vertexConverter, graphFactory);

            using (var stream = new MemoryStream())
            {
                serializer.SaveGraph(graph, stream);
                stream.Seek(0, SeekOrigin.Begin);
                deserialized = serializer.LoadGraph(stream);
            }

            Assert.AreEqual(graph, deserialized);
            Assert.AreNotSame(graph, deserialized);
        }
Пример #2
0
        public void AssembleGraph_ReturnsNotNullGraph(int obstaclePercent, int[] dimensionSizes)
        {
            var graph = graphAssembler.AssembleGraph(obstaclePercent, dimensionSizes);

            bool CoordinatesAreUnique()
            {
                var uniqueVertices = graph.Vertices
                                     .DistinctBy(vertex => vertex.Position)
                                     .ToArray();

                return(uniqueVertices.Length == graph.Size);
            }

            bool IsTestVertexType(IVertex vertex)
            {
                return(vertex?.GetType() == typeof(TestVertex));
            }

            Assert.IsTrue(graph.DimensionsSizes.SequenceEqual(dimensionSizes));
            Assert.IsTrue(graph.Vertices.All(IsTestVertexType));
            Assert.IsTrue(CoordinatesAreUnique());
        }
Пример #3
0
        public GraphPathTests()
        {
            graphAssemble = new TestGraph2DAssemble();
            expectedPraphPathCoordinates = new ICoordinate[]
            {
                new TestCoordinate(0, 0), //1
                new TestCoordinate(0, 1), //5
                new TestCoordinate(1, 2), //8
                new TestCoordinate(1, 3), //1
                new TestCoordinate(2, 4), //3
                new TestCoordinate(3, 5), //2
                new TestCoordinate(3, 6), //1
                new TestCoordinate(4, 7)  //5
            };
            graph = graphAssemble.AssembleGraph(0);
            var source = graph[expectedPraphPathCoordinates.First()];
            var target = graph[expectedPraphPathCoordinates.Last()];

            endPoints      = new EndPoints(source, target);
            parentVertices = new ParentVertices();
            FormParentVertices(parentVertices);
        }
Пример #4
0
        public void SaveGraph_LoadGraph_NotSerializableCoordinate_ThrowsCantSerializeGraphException(
            int obstaclePercent, int[] graphParams)
        {
            graphAssembler = new GraphAssemble(
                vertexFactory,
                notSerializableCoordinateFactory,
                graphFactory,
                costFactory,
                radarFactory);

            var graph = graphAssembler.AssembleGraph(
                obstaclePercent, graphParams);
            var serializer = new GraphSerializer(
                formatter, vertexConverter, graphFactory);

            Assert.Throws <CantSerializeGraphException>(() =>
            {
                using var stream = new MemoryStream();
                serializer.SaveGraph(graph, stream);
                stream.Seek(0, SeekOrigin.Begin);
                serializer.LoadGraph(stream);
            });
        }