示例#1
0
        private void testClear(BasicStack <DSString> the_stack)
        {
            //make sure size() and isEmpty() are correct before clear
            Assert.AreEqual(false, the_stack.isEmpty());
            Assert.AreEqual(10, the_stack.size());

            //after clearing
            the_stack.clear();
            Assert.AreEqual(true, the_stack.isEmpty());
            Assert.AreEqual(0, the_stack.size());

            //after readding and clearing
            the_stack.push(new DSString("13"));
            Assert.AreEqual(false, the_stack.isEmpty());
            Assert.AreEqual(1, the_stack.size());
        }
示例#2
0
        private void testIsEmpty(BasicStack <DSString> the_stack)
        {
            //check while not empty
            Assert.IsFalse(the_stack.isEmpty());

            //after empty
            the_stack.clear();
            Assert.IsTrue(the_stack.isEmpty());

            //after re-addition
            the_stack.push(new DSString("1"));
            Assert.IsFalse(the_stack.isEmpty());

            //after empty again
            the_stack.clear();
            Assert.IsTrue(the_stack.isEmpty());
        }
示例#3
0
 /// <summary>
 /// Shows whether there is another element to traverse in the tree.
 /// </summary>
 /// <returns>true if there are more elements, otherwise false.</returns>
 public bool hasNext()
 {
     if (my_traversal_method == GraphTraversals.BreadthFirst)
     {
         return(!my_element_queue.isEmpty());
     }
     else
     {
         return(!my_element_stack.isEmpty());
     }
 }
示例#4
0
        private void testPeek(BasicStack <DSString> the_stack)
        {
            //check multiple peeks
            Assert.AreEqual("9", the_stack.peek().value);
            Assert.AreEqual("9", the_stack.peek().value);

            //peek after removal
            the_stack.pop();
            Assert.AreEqual("8", the_stack.peek().value);

            //peek with nothing on the stack
            while (!the_stack.isEmpty())
            {
                the_stack.pop();
            }
            Assert.AreEqual(null, the_stack.peek());
        }
示例#5
0
        private void testPush(BasicStack <DSString> the_stack)
        {
            //items already added in initialization

            //make sure first size is right
            Assert.AreEqual(10, the_stack.size());

            //make sure first removal matches FIFO ordering
            Assert.AreEqual("9", the_stack.pop().value);

            //remove all elements and check last item to make sure removals match FIFO ordering
            string element = "";

            while (!the_stack.isEmpty())
            {
                element = the_stack.pop().value;
            }
            Assert.AreEqual("0", element);
        }
示例#6
0
 public bool hasNext()
 {
     return(!my_elements.isEmpty());
 }