Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python3 https://s3.amazonaws.com/iedu-attachments-question/7fec6bf4715981a2b535717ec2899e05_b7a73adce8ec34bdc58488aae13d23bc.pdf This is exp_eval_tests # Start of unittest - add to completely test functions in exp_eval import unittest from exp_eval import * class test_expressions(unittest.TestCase):

Python3

https://s3.amazonaws.com/iedu-attachments-question/7fec6bf4715981a2b535717ec2899e05_b7a73adce8ec34bdc58488aae13d23bc.pdf

This is exp_eval_tests

# Start of unittest - add to completely test functions in exp_eval

import unittest

from exp_eval import *

class test_expressions(unittest.TestCase):

def test_postfix_eval_01(self):

self.assertAlmostEqual(postfix_eval("3 5 +"), 8)

def test_postfix_eval_02(self):

try:

postfix_eval("blah")

self.fail()

except PostfixFormatException as e:

self.assertEqual(str(e), "Invalid token")

def test_postfix_eval_03(self):

try:

postfix_eval("4 +")

self.fail()

except PostfixFormatException as e:

self.assertEqual(str(e), "Insufficient operands")

def test_postfix_eval_04(self):

try:

postfix_eval("1 2 3 +")

self.fail()

except PostfixFormatException as e:

self.assertEqual(str(e), "Too many operands")

def test_infix_to_postfix_01(self):

self.assertEqual(infix_to_postfix("6 - 3"), "6 3 -")

self.assertEqual(infix_to_postfix("6"), "6")

def test_prefix_to_postfix(self):

self.assertEqual(prefix_to_postfix("* - 3 / 2 1 - / 4 5 6"), "3 2 1 / - 4 5 / 6 - *")

if __name__ == "__main__":

unittest.main()

This is exp_eval

from stack_array import Stack

# You do not need to change this class

class PostfixFormatException(Exception):

pass

def postfix_eval(input_str):

"""Evaluates a postfix expression"""

"""Input argument: a string containing a postfix expression where tokens

are space separated. Tokens are either operators + - * / ^ or numbers

Returns the result of the expression evaluation.

Raises an PostfixFormatException if the input is not well-formed"""

pass

def infix_to_postfix(input_str):

"""Converts an infix expression to an equivalent postfix expression"""

"""Input argument: a string containing an infix expression where tokens are

space separated. Tokens are either operators + - * / ^ parentheses ( ) or numbers

Returns a String containing a postfix expression """

pass

def prefix_to_postfix(input_str):

"""Converts a prefix expression to an equivalent postfix expression"""

"""Input argument: a string containing a prefix expression where tokens are

space separated. Tokens are either operators + - * / ^ parentheses ( ) or numbers

Returns a String containing a postfix expression(tokens are space separated)"""

pass

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions