Exemplo n.º 1
0
        public void TestSimpleSearch()
        {
            IList <Tuple <int, IList <Edge> > > order = new List <Tuple <int, IList <Edge> > >();
            Graph g = TestGraphs.GetTestGraphWithoutLoop();

            g.DepthFirstSearch((v, edges) =>
            {
                order.Add(new Tuple <int, IList <Edge> >(int.Parse(v.Name.Replace("v", string.Empty)), edges));
                return(true);
            });
            Assert.AreEqual(10, order.Count);
            int i1  = this.GetIndexOfTupleWithSpeicficFirstvalue(order, 1);
            int i2  = this.GetIndexOfTupleWithSpeicficFirstvalue(order, 2);
            int i3  = this.GetIndexOfTupleWithSpeicficFirstvalue(order, 3);
            int i4  = this.GetIndexOfTupleWithSpeicficFirstvalue(order, 4);
            int i5  = this.GetIndexOfTupleWithSpeicficFirstvalue(order, 5);
            int i6  = this.GetIndexOfTupleWithSpeicficFirstvalue(order, 6);
            int i7  = this.GetIndexOfTupleWithSpeicficFirstvalue(order, 7);
            int i8  = this.GetIndexOfTupleWithSpeicficFirstvalue(order, 8);
            int i9  = this.GetIndexOfTupleWithSpeicficFirstvalue(order, 9);
            int i10 = this.GetIndexOfTupleWithSpeicficFirstvalue(order, 10);

            Assert.AreEqual(0, i1);
            Assert.IsTrue(i1 < i4);
            Assert.IsTrue(i4 < i8);
            Assert.IsTrue(i1 < i3);
            Assert.IsTrue(i3 < i7);
            Assert.IsTrue(i3 < i6);
            Assert.IsTrue(i6 < i10);
            Assert.IsTrue(i1 < i2);
            Assert.IsTrue(i2 < i5);
            Assert.IsTrue(i5 < i9);
        }
Exemplo n.º 2
0
        public void TestSimpleBreadthFirstSearch2()
        {
            List <Tuple <Vertex, IList <Edge> > > order = new();
            Graph g = TestGraphs.GetTestGraphWithoutLoop();

            g.BreadthFirstSearch((v, edges) =>
            {
                order.Add(new Tuple <Vertex, IList <Edge> >(v, edges));
                return(true);
            });
            Assert.AreEqual(g.GetVertex("v1"), order[0].Item1);
            Assert.AreEqual(0, order[0].Item2.Count);
            //todo write asserts for content of order of edges
        }
Exemplo n.º 3
0
        public void TestSimpleBreadthFirstSearch()
        {
            List <int> order = new();
            Graph      g     = TestGraphs.GetTestGraphWithoutLoop();

            g.BreadthFirstSearch((v, edges) =>
            {
                order.Add(int.Parse(v.Name.Replace("v", string.Empty)));
                return(true);
            });
            Assert.AreEqual(10, order.Count);
            Assert.AreEqual(1, order[0]);
            Assert.IsTrue(new HashSet <int>(new int[] { 2, 3, 4 }).SetEquals(new int[] { order[1], order[2], order[3] }));
            Assert.IsTrue(new HashSet <int>(new int[] { 5, 6, 7, 8 }).SetEquals(new int[] { order[4], order[5], order[6], order[7] }));
            Assert.IsTrue(new HashSet <int>(new int[] { 9, 10 }).SetEquals(new int[] { order[8], order[9] }));
        }