Exemple #1
0
        public void NotEqualsOp()
        {
            var x = NodeIdentity.Of("foo");
            var y = NodeIdentity.Of("bar");

            (x != y).Should().BeTrue();
        }
        public void TwoPathsOverSameNodesButDifferentOrderHaveDifferentHashcode()
        {
            var p1 = Path.Of(NodeIdentity.Of("A"), NodeIdentity.Of("B"));
            var p2 = Path.Of(NodeIdentity.Of("B"), NodeIdentity.Of("A"));

            p1.GetHashCode().Should().NotBe(p2.GetHashCode());
        }
        public void TwoPathsOverSameNodesHaveSameHashcode()
        {
            var p1 = Path.Of(NodeIdentity.Of("A"), NodeIdentity.Of("B"));
            var p2 = Path.Of(NodeIdentity.Of("A"), NodeIdentity.Of("B"));

            p1.GetHashCode().Should().Be(p2.GetHashCode());
        }
        public void TwoInstancesWithSameValuesHaveDifferentRefId()
        {
            var p1 = NodeIdentity.Of("test");
            var p2 = NodeIdentity.Of("test");

            p2.GetRefId().Should().NotBe(p1.GetRefId());
        }
        public void NonEmptyPathIsNotEmpty()
        {
            var path = Path.Of(NodeIdentity.Of("foo"));

            path.Should().NotBeEmpty();
            Path.IsEmpty(path).Should().BeFalse();
        }
        public void TwoPointersToSameInstanceHasSameRefId()
        {
            var p1 = NodeIdentity.Of("test");
            var p2 = p1;

            p2.GetRefId().Should().Be(p1.GetRefId());
        }
Exemple #7
0
        public void Equatable()
        {
            var x = NodeIdentity.Of("foo");
            var y = NodeIdentity.Of("foo");

            x.Equals(y).Should().BeTrue();
        }
Exemple #8
0
        public void ObjectEquals()
        {
            var x = NodeIdentity.Of("foo");
            var y = NodeIdentity.Of("foo");

            x.Should().Be(y);
        }
Exemple #9
0
        public void ObjectEqualsNegativeTest()
        {
            var x = NodeIdentity.Of("foo");
            var y = NodeIdentity.Of("bar");

            x.Should().NotBe(y);
        }
Exemple #10
0
        public void HashCodeNegativeTest()
        {
            var x = NodeIdentity.Of("foo");
            var y = NodeIdentity.Of("bar");

            x.GetHashCode().Should().NotBe(y.GetHashCode());
        }
Exemple #11
0
        public void HashCode()
        {
            var x = NodeIdentity.Of("foo");
            var y = NodeIdentity.Of("foo");

            x.GetHashCode().Should().Be(y.GetHashCode());
        }
Exemple #12
0
        public void EquatableNegativeTest()
        {
            var x = NodeIdentity.Of("foo");
            var y = NodeIdentity.Of("bar");

            x.Equals(y).Should().BeFalse();
        }
Exemple #13
0
 public void GraphCannotBeNull()
 {
     typeof(DepthFirst).Invoking(_ =>
                                 DepthFirst.VisitAll(null, NodeIdentity.Of("A")).ToList())
     .Should().Throw <ArgumentNullException>()
     .Which.ParamName.Should().Be("graph");
 }
Exemple #14
0
        public void EqualsOpNegativeTest()
        {
            var x = NodeIdentity.Of("foo");
            var y = NodeIdentity.Of("bar");

            (x == y).Should().BeFalse();
        }
Exemple #15
0
        public void EqualsOpItself()
        {
            var x = NodeIdentity.Of("foo");

#pragma warning disable CS1718 // Comparison made to same variable
            (x == x).Should().BeTrue();
#pragma warning restore CS1718 // Comparison made to same variable
        }
Exemple #16
0
        public void ReturnsEmptyPathIfNoPathIsFound()
        {
            var path = (object)BreadthFirst.FindPath(CreateSimpleGraph(),
                                                     NodeIdentity.Of("A"),
                                                     node => node == NodeIdentity.Of("notfound"));

            path.Should().Be(Path.Empty);
        }
        public void InstanceHasSameRefId()
        {
            var p1          = NodeIdentity.Of("test");
            var firstRefId  = p1.GetRefId();
            var secondRefId = p1.GetRefId();

            secondRefId.Should().Be(firstRefId);
        }
        public void ExampleFromPaper()
        {
            var graph = CreateGraph();
            var paths = CreatePaths();
            var xform = TouringGraphTransformer
                        .Transform(graph, paths, NodeIdentity.Of("S"), NodeIdentity.Of("T"));

            xform.EdgeCount.Should().Be(17);
        }
Exemple #19
0
        public void TwoPathsOverSameNodesButDifferentOrderAreNotEqual()
        {
            object p1 = Path.Of(NodeIdentity.Of("A"), NodeIdentity.Of("B"));
            object p2 = Path.Of(NodeIdentity.Of("B"), NodeIdentity.Of("A"));

            p1.Should().NotBe(p2);
            ((Path)p1 == (Path)p2).Should().BeFalse();
            ((Path)p1 != (Path)p2).Should().BeTrue();
        }
Exemple #20
0
 public void CanFindStraightPath()
 {
     BreadthFirst.FindPath(GraphFactory.BuildGraph("A-B", "B-C", "C-D"), NodeIdentity.Of("A"), node => node == NodeIdentity.Of("D"))
     .Should().ContainInOrder(
         NodeIdentity.Of("A"),
         NodeIdentity.Of("B"),
         NodeIdentity.Of("C"),
         NodeIdentity.Of("D")
         ).And.HaveCount(4);
 }
Exemple #21
0
 public void DoesNotVisitDisconnectedNodes()
 {
     DepthFirst.VisitAll(
         GraphFactory.BuildGraph("A-B", "C-D"), NodeIdentity.Of("A"))
     .Should()
     .ContainInOrder(
         NodeIdentity.Of("A"),
         NodeIdentity.Of("B")
         ).And.HaveCount(2);
 }
Exemple #22
0
 public void FindsShortestPath()
 {
     BreadthFirst.FindPath(
         GraphFactory.BuildGraph("A-B", "B-C", "C-D", "A-D"),
         NodeIdentity.Of("A"),
         node => node == NodeIdentity.Of("D"))
     .Should().ContainInOrder(
         NodeIdentity.Of("A"),
         NodeIdentity.Of("D")
         ).And.HaveCount(2);
 }
Exemple #23
0
 public void VisitsNodesInOrder()
 {
     DepthFirst.VisitAll(CreateSimpleGraph(), NodeIdentity.Of("A"))
     .Should().ContainInOrder(
         NodeIdentity.Of("A"),
         NodeIdentity.Of("B2"),
         NodeIdentity.Of("C2"),
         NodeIdentity.Of("C1"),
         NodeIdentity.Of("B1")
         ).And.HaveCount(5);
 }
Exemple #24
0
        public void CannotBeMutated()
        {
            var nodes = new List <NodeIdentity> {
                NodeIdentity.Of("foo")
            };
            var path = Path.Of(nodes);

            nodes.Add(NodeIdentity.Of("bar"));

            path.Should().NotContain(NodeIdentity.Of("bar"));
        }
Exemple #25
0
        public static DirectedGraph Transform(DirectedGraph originalGraph, IEnumerable <Path> primePaths,
                                              NodeIdentity start, NodeIdentity end)
        {
            ArgumentHelpers.ThrowIfNull(() => originalGraph);
            ArgumentHelpers.ThrowIfNull(() => primePaths);

            var nodes = new List <NodeIdentity> {
                start, end
            };
            var edges          = new List <DirectedEdge>();
            var nodePathLookup = new Dictionary <NodeIdentity, Path>();

            nodePathLookup.Add(start, Path.Of(start));
            nodePathLookup.Add(end, Path.Of(end));

            foreach (var path in primePaths)
            {
                var node = NodeIdentity.Of(Describe(path));
                nodes.Add(node);
                nodePathLookup.Add(node, path);
            }

            foreach (var firstPathKey in nodes)
            {
                if (firstPathKey == end)
                {
                    continue;
                }
                var firstPath = nodePathLookup[firstPathKey];

                foreach (var secondPathKey in nodes)
                {
                    if (secondPathKey == firstPathKey || secondPathKey == start)
                    {
                        continue;
                    }
                    var secondPath = nodePathLookup[secondPathKey];

                    var maybeEdge = firstPath.Extend(secondPath, originalGraph);
                    if (Path.IsEmpty(maybeEdge))
                    {
                        continue;
                    }

                    if (!ContainsAnyOtherPrimePath(primePaths, maybeEdge, firstPath, secondPath))
                    {
                        edges.Add(DirectedEdge.Between(firstPathKey, secondPathKey));
                    }
                }
            }

            return(DirectedGraph.Of(edges, nodes));
        }
Exemple #26
0
        public void EqualsNullOp()
        {
            var x = NodeIdentity.Of("foo");

            (x == null).Should().BeFalse();
        }
Exemple #27
0
 private static NodeIdentity CreateSubstituteNode(Path cycle)
 {
     return(NodeIdentity.Of("Substituted cycle: " + cycle.GetRefId().ToString()));
 }
        public void PathDoesNotVisitOtherNodes()
        {
            var path = GraphFactory.CreateEdges("A-B", "B-C", "C-D", "D-E");

            path.Visits(NodeIdentity.Of("Q")).Should().BeFalse();
        }
 public static NodeIdentity CreateNode(string description)
 {
     return(NodeIdentity.Of(description));
 }
        public void PathVisitsNodeInMiddle()
        {
            var path = GraphFactory.CreateEdges("A-B", "B-C", "C-D", "D-E");

            path.Visits(NodeIdentity.Of("C")).Should().BeTrue();
        }