Come up with test cases for the RPN (RPNTest. java) to ensure it works correctly. A good way to test the RPN valuator by sending tokens one at a time to evaluate() or by calling the evaluateLine() passing a full text line. There should a test for all special cases, for example division by 0, or pop and empty stack, etc.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

How could I come up with an assertEquals method for each of the methods in RPNTest.java? Below is what I have so far.

RPNTest.java

public class RPNTest
{
// A Linked List Node

    class Node
    {

        int data;       // integer data
        Node next;      // pointer to the next node
    }

    class Stack
    {

        private Node top;
        private int nodesCount;

        public Stack()
        {
            this.top = null;
            this.nodesCount = 0;
        }

        // Utility function to add an element `x` to the stack
        public void push(int x)        // insert at the beginning
        {
            // allocate a new node in a heap
            Node node = new Node();

            // check if stack (heap) is full. Then inserting an element would
            // lead to stack overflow
            if (node == null) {
                System.out.println("Heap Overflow");
                return;
            }

            System.out.println("Inserting " + x);

            // set data in the allocated node
            node.data = x;

            // set the .next pointer of the new node to point to the current
            // top node of the list
            node.next = top;

            // update top pointer
            top = node;

            // increase stack's size by 1
            this.nodesCount += 1;
        }

        // Utility function to check if the stack is empty or not
        public boolean isEmpty()
        {
            return top == null;
        }

        // Utility function to return the top element of the stack
        public int peek()
        {
            // check for an empty stack
            if (isEmpty()) {
                System.out.println("The stack is empty");
                System.exit(-1);
            }
            return top.data;
        }

        // Utility function to pop a top element from the stack
        public int pop()        // remove at the beginning
        {
            // check for stack underflow
            if (isEmpty()) {
                System.out.println("Stack Underflow");
                System.exit(-1);
            }

            // take note of the top node's data
            int top = peek();

            System.out.println("Removing " + top);

            // decrease stack's size by 1
            this.nodesCount -= 1;

            // update the top pointer to point to the next node
            this.top = (this.top).next;

            return top;
        }

        // Utility function to return the size of the stack
        public int numElements()
        {
            return this.nodesCount;
        }
    }

    class Main
    {

        public static void main(String[] args)
        {
            Stack stack = new Stack<E>();
            stack.push(1);
            stack.push(2);
            stack.push(3);

            System.out.println("The top element is " + stack.peek());

            stack.pop();
            stack.pop();
            stack.pop();

            if (stack.isEmpty()) {
                System.out.println("The stack is empty");
            }
            else {
                System.out.println("The stack is not empty");
            }
        }
    }
}

Come up with test cases for the RPN (RPNEest.java) to ensure it works correctly. A good way to test the RPN evaluator is by sending tokens one at a time to evaluate() or by calling the evaluateLine() passing a full text line. There should be a test for all special cases, for example division by 0, or pop and empty stack, etc.
Transcribed Image Text:Come up with test cases for the RPN (RPNEest.java) to ensure it works correctly. A good way to test the RPN evaluator is by sending tokens one at a time to evaluate() or by calling the evaluateLine() passing a full text line. There should be a test for all special cases, for example division by 0, or pop and empty stack, etc.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of Threads
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education