Example #1
0
            public void TestCompareTo()
            {
                VisitableQueue <int>[] qs = new VisitableQueue <int> [3];

                for (int i = 0; i < 3; i++)
                {
                    qs[i] = new VisitableQueue <int>();

                    for (int j = 0; j < i; j++)
                    {
                        qs[i].Enqueue(j * 4);
                    }
                }

                Assert.AreEqual(qs[0].CompareTo(qs[1]), -1);
                Assert.AreEqual(qs[2].CompareTo(qs[1]), 1);

                VisitableQueue <int> sameQ = qs[1];

                Assert.AreEqual(qs[1].CompareTo(sameQ), 0);


                object obj = new object();

                Assert.AreEqual(qs[0].CompareTo(obj), -1);
            }
Example #2
0
            public void TestVisitor()
            {
                VisitableQueue <int> q       = GetTestQueue();
                SumVisitor           visitor = new SumVisitor();

                q.Accept(visitor);

                Assert.AreEqual(visitor.Sum, 0 + 3 + 6 + 9 + 12);
            }
Example #3
0
            public void TestFixedSize()
            {
                VisitableQueue <int> q = new VisitableQueue <int>();

                Assert.AreEqual(q.IsFixedSize, false);

                q = GetTestQueue();
                Assert.AreEqual(q.IsFixedSize, false);
            }
Example #4
0
            public void TestReadOnly()
            {
                VisitableQueue <int> q = new VisitableQueue <int>();

                Assert.AreEqual(q.IsReadOnly, false);

                q.Add(5);
                Assert.AreEqual(q.IsReadOnly, false);
            }
Example #5
0
            public void TestIsFull()
            {
                // IsFull must always return false.
                VisitableQueue <int> q = GetTestQueue();

                Assert.AreEqual(q.IsFull, false);

                q = new VisitableQueue <int>();
                Assert.AreEqual(q.IsFull, false);
            }
Example #6
0
            private VisitableQueue <int> GetTestQueue()
            {
                VisitableQueue <int> q = new VisitableQueue <int>(5);

                for (int i = 0; i < 5; i++)
                {
                    q.Enqueue(i * 3);
                }

                return(q);
            }
Example #7
0
            public void TestEnumerator()
            {
                VisitableQueue <int> q = GetTestQueue();

                IEnumerator <int> enumerator = q.GetEnumerator();

                for (int i = 0; i < 5; i++)
                {
                    Assert.AreEqual(enumerator.MoveNext(), true);
                    Assert.AreEqual(enumerator.Current, i * 3);
                }

                Assert.AreEqual(enumerator.MoveNext(), false);
            }
Example #8
0
            public void TestStoppingVisitor()
            {
                VisitableQueue <int> q = GetTestQueue();

                ComparableFindingVisitor <int> visitor = new ComparableFindingVisitor <int>(6);

                q.Accept(visitor);

                Assert.AreEqual(visitor.Found, true);

                visitor = new ComparableFindingVisitor <int>(99);
                q.Accept(visitor);
                Assert.AreEqual(visitor.Found, false);
            }
Example #9
0
            public void TestAdd()
            {
                VisitableQueue <int> q = new VisitableQueue <int>();

                q.Add(5);

                Assert.AreEqual(q.Count, 1);
                Assert.AreEqual(q.Peek(), 5);
                Assert.AreEqual(q.Dequeue(), 5);

                q.Enqueue(3);
                q.Add(4);

                Assert.AreEqual(q.Count, 2);
                Assert.AreEqual(q.Dequeue(), 3);
                Assert.AreEqual(q.Dequeue(), 4);
            }
Example #10
0
            public void TestCompare()
            {
                VisitableQueue <int> q1 = new VisitableQueue <int>(6);
                VisitableQueue <int> q2 = new VisitableQueue <int>(4);

                VisitableQueue <int> q3 = new VisitableQueue <int>(8);

                q3.Enqueue(2);

                VisitableQueue <int> q4 = new VisitableQueue <int>(6);

                object o = new object();

                Assert.AreEqual(q1.CompareTo(q2), 0);
                Assert.AreEqual(q1.CompareTo(q3), -1);
                Assert.AreEqual(q3.CompareTo(q4), 1);
                Assert.AreEqual(q1.CompareTo(o), -1);
            }
Example #11
0
        public void TestSuccesfulInit()
        {
            VisitableList <int> l = new VisitableList <int>();

            l = new VisitableList <int>(5);

            VisitableQueue <int> q = new VisitableQueue <int>();

            for (int i = 0; i < 3; i++)
            {
                q.Enqueue(i * 2);
            }

            l = new VisitableList <int>(q);

            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(l[i], i * 2);
            }
        }
Example #12
0
        /// <summary>
        /// Performs a breadth-first traversal from the specified vertex.
        /// </summary>
        /// <param name="visitor">The visitor to use.</param>
        /// <param name="startVertex">The vertex to start from.</param>
        public void BreadthFirstTraversal(IVisitor <Vertex <T> > visitor, Vertex <T> startVertex)
        {
            if (visitor == null)
            {
                throw new ArgumentNullException("visitor");
            }

            if (startVertex == null)
            {
                throw new ArgumentNullException("startVertex");
            }

            var visitedVertices = new List <Vertex <T> >(graphVertices.Count);

            var q = new VisitableQueue <Vertex <T> >();

            q.Enqueue(startVertex);
            visitedVertices.Add(startVertex);

            while (!((q.IsEmpty) || (visitor.HasCompleted)))
            {
                Vertex <T> vertex = q.Dequeue();

                visitor.Visit(vertex);

                List <Edge <T> > edges = vertex.EmanatingEdgeList;

                for (int i = 0; i < edges.Count; i++)
                {
                    Vertex <T> vertexToVisit = edges[i].GetPartnerVertex(vertex);

                    if (!visitedVertices.Contains(vertexToVisit))
                    {
                        q.Enqueue(vertexToVisit);
                        visitedVertices.Add(vertexToVisit);
                    }
                }
            }
        }
Example #13
0
            public void TestSuccesfulInit()
            {
                VisitableQueue <int> q = new VisitableQueue <int>();

                Assert.AreEqual(q.Count, 0);
                Assert.AreEqual(q.IsEmpty, true);
                Assert.AreEqual(q.IsFull, false);

                VisitableStack <int> stack = new VisitableStack <int>();

                for (int i = 0; i < 3; i++)
                {
                    stack.Push(i * 4);
                }

                q = new VisitableQueue <int>(stack);

                for (int i = 2; i >= 0; i--)
                {
                    Assert.AreEqual(q.Dequeue(), i * 4);
                }
            }
Example #14
0
 public void TestUnsuccesfulInit()
 {
     VisitableQueue <int> q = new VisitableQueue <int>(-5);
 }
Example #15
0
            public void TestNullVisitor()
            {
                VisitableQueue <int> q = new VisitableQueue <int>();;

                q.Accept(null);
            }
Example #16
0
            public void TestInvalidCompareTo()
            {
                VisitableQueue <int> q = new VisitableQueue <int>();

                q.CompareTo(null);
            }