def testBadAdd_just_string_or_operators(self): #Second of a sequence of tests intended to get a ValueError from the evaluate a = '+ + - - 2' b = ' - - - 5 5 5 5' c = ' - - - + + +' #------------------------------------------------------------------------------ #Test a try: s = RPNCaculator() a = s.eval(a) self.assertTrue(False,'no excpetion /or not right type excpetion rasied for bad sequences') except ValueError: pass #------------------------------------------------------------------------------ #Test b try: s = RPNCaculator() b = s.eval(b) self.assertTrue(False,'no excpetion /or not right type excpetion rasied for bad sequences') except ValueError : pass #------------------------------------------------------------------------------ #Test c try: s = RPNCaculator() c = s.eval(c) self.assertTrue(False,'no excpetion /or not right type excpetion rasied for bad sequences') except ValueError : pass
def testEvalExample_normal(self): # First of a number of tests intended to drive larger and more complicated # valid expression strings through eval, checking both the value returned by # the method and the final str() version of the value stack. a = '3 5 + 7 * 8 11 * - ' b = '1 3 * 7 + 20 + ' c = ' 4 2 / 4 + 3 * ' #------------------------------------------------------------------------------ #Test evaluation of sequence a (by both the return value and the status of the stack) t = RPNCaculator() a = t.eval(a) self.assertEqual(-32,a) self.assertEqual(str(t),'[-32*]') #------------------------------------------------------------------------------ #Test evaluation of sequence b (by both the return value and the status of the stack) t = RPNCaculator() b = t.eval(b) self.assertEqual(30,b) self.assertEqual(str(t),'[30*]') #Test evaluation of sequence c (by both the return value and the status of the stack) #------------------------------------------------------------------------------ t = RPNCaculator() c = t.eval(c) self.assertEqual(18,c) self.assertEqual(str(t),'[18*]')
def testEvalExample_normal(self): # First of a number of tests intended to drive larger and more complicated # valid expression strings through eval, checking both the value returned by # the method and the final str() version of the value stack. a = '3 5 + 7 * 8 11 * - ' b = '1 3 * 7 + 20 + ' c = ' 4 2 / 4 + 3 * ' #------------------------------------------------------------------------------ #Test evaluation of sequence a (by both the return value and the status of the stack) t = RPNCaculator() a = t.eval(a) self.assertEqual(-32, a) self.assertEqual(str(t), '[-32*]') #------------------------------------------------------------------------------ #Test evaluation of sequence b (by both the return value and the status of the stack) t = RPNCaculator() b = t.eval(b) self.assertEqual(30, b) self.assertEqual(str(t), '[30*]') #Test evaluation of sequence c (by both the return value and the status of the stack) #------------------------------------------------------------------------------ t = RPNCaculator() c = t.eval(c) self.assertEqual(18, c) self.assertEqual(str(t), '[18*]')
def testSimpleEvalWhitespace(self): # Number of eval tests with strings just being one or two numbers, but with # different cases of leading. trailing whitespace and use of tabs separating # tokens a = ' 2 3 ' b = ' 2 4 ' c = ' 2 4 ' # containing none-space white space(tab) #Test a (by both the return value and the status of the stack) #------------------------------------------------------------------------------ s = RPNCaculator() a = s.eval(a) self.assertEqual(str(s),'[3*, 2]') self.assertEqual(a,3) #Test b (by both the return value and the status of the stack) #------------------------------------------------------------------------------ s = RPNCaculator() b = s.eval(b) self.assertEqual(str(s),'[4*, 2]') self.assertEqual(b,4) #Test c (by both the return value and the status of the stack) #------------------------------------------------------------------------------ s = RPNCaculator() c = s.eval(c) self.assertEqual(str(s),'[4*, 2]') self.assertEqual(c,4)
def testBadAdd(self): # First of a sequence of tests intended to get a ValueError from the evaluate # method a = '3 + 5 ' b = '3 5 + +' #------------------------------------------------------------------------------ #Test a try: s = RPNCaculator() a = s.eval(a) self.assertTrue( False, 'no excpetion /or not right type excpetion rasied for bad sequences' ) except ValueError: pass #------------------------------------------------------------------------------ #Test b try: s = RPNCaculator() b = s.eval(b) self.assertTrue( False, 'no excpetion /or not right type excpetion rasied for bad sequences' ) except ValueError: pass
def testSimpleEvalWhitespace(self): # Number of eval tests with strings just being one or two numbers, but with # different cases of leading. trailing whitespace and use of tabs separating # tokens a = ' 2 3 ' b = ' 2 4 ' c = ' 2 4 ' # containing none-space white space(tab) #Test a (by both the return value and the status of the stack) #------------------------------------------------------------------------------ s = RPNCaculator() a = s.eval(a) self.assertEqual(str(s), '[3*, 2]') self.assertEqual(a, 3) #Test b (by both the return value and the status of the stack) #------------------------------------------------------------------------------ s = RPNCaculator() b = s.eval(b) self.assertEqual(str(s), '[4*, 2]') self.assertEqual(b, 4) #Test c (by both the return value and the status of the stack) #------------------------------------------------------------------------------ s = RPNCaculator() c = s.eval(c) self.assertEqual(str(s), '[4*, 2]') self.assertEqual(c, 4)
def testEvalAdd(self): # Combinations to check evaluate on multiple additions a ='3 5 +' b = ' 3 5 + 5 + 20 + 7 +' # Test a (by both the return value and the status of the stack) #------------------------------------------------------------------------------ s = RPNCaculator() a = s.eval(a) self.assertEqual(str(s),'[8*]') self.assertEqual(a,8) # Test b (by both the return value and the status of the stack) #------------------------------------------------------------------------------ s = RPNCaculator() b = s.eval(b) self.assertEqual(str(s),'[40*]') self.assertEqual(b,40)
def testBadAdd_just_string_or_operators(self): #Second of a sequence of tests intended to get a ValueError from the evaluate a = '+ + - - 2' b = ' - - - 5 5 5 5' c = ' - - - + + +' #------------------------------------------------------------------------------ #Test a try: s = RPNCaculator() a = s.eval(a) self.assertTrue( False, 'no excpetion /or not right type excpetion rasied for bad sequences' ) except ValueError: pass #------------------------------------------------------------------------------ #Test b try: s = RPNCaculator() b = s.eval(b) self.assertTrue( False, 'no excpetion /or not right type excpetion rasied for bad sequences' ) except ValueError: pass #------------------------------------------------------------------------------ #Test c try: s = RPNCaculator() c = s.eval(c) self.assertTrue( False, 'no excpetion /or not right type excpetion rasied for bad sequences' ) except ValueError: pass
def testEvalAdd(self): # Combinations to check evaluate on multiple additions a = '3 5 +' b = ' 3 5 + 5 + 20 + 7 +' # Test a (by both the return value and the status of the stack) #------------------------------------------------------------------------------ s = RPNCaculator() a = s.eval(a) self.assertEqual(str(s), '[8*]') self.assertEqual(a, 8) # Test b (by both the return value and the status of the stack) #------------------------------------------------------------------------------ s = RPNCaculator() b = s.eval(b) self.assertEqual(str(s), '[40*]') self.assertEqual(b, 40)
def testEvalExample_number_first(self): # Second of a number of tests intended to drive larger and more complicated # valid expression strings through eval, checking both the value returned by # the method and the final str() version of the value stack. a = '3 3 3 3 + + +' b = '2 2 2 2 * / +' #------------------------------------------------------------------------------ #Test evaluation of sequence a (by both the return value and the status of the stack) t = RPNCaculator() a = t.eval(a) self.assertEqual(12,a) self.assertEqual(str(t),'[12*]') #------------------------------------------------------------------------------ #Test evaluation of sequence b (by both the return value and the status of the stack) t = RPNCaculator() b = t.eval(b) self.assertEqual(2.5,b) self.assertEqual(str(t),'[2.5*]')
def testEvalExample_number_first(self): # Second of a number of tests intended to drive larger and more complicated # valid expression strings through eval, checking both the value returned by # the method and the final str() version of the value stack. a = '3 3 3 3 + + +' b = '2 2 2 2 * / +' #------------------------------------------------------------------------------ #Test evaluation of sequence a (by both the return value and the status of the stack) t = RPNCaculator() a = t.eval(a) self.assertEqual(12, a) self.assertEqual(str(t), '[12*]') #------------------------------------------------------------------------------ #Test evaluation of sequence b (by both the return value and the status of the stack) t = RPNCaculator() b = t.eval(b) self.assertEqual(2.5, b) self.assertEqual(str(t), '[2.5*]')
def testSimpleEval(self): # Sequence of three eval tests, first evaluates a single number as the string # checks are both for the return value from the method as well as the contents # of the stack. Next two test do the same for two numbers in string and three # numbers in string #Test for one number s = RPNCaculator() a = s.eval('2 ') self.assertEqual(str(s),'[2*]') self.assertEqual(a,2) #Test for two number s = RPNCaculator() a = s.eval('2 3 ') self.assertEqual(a,3) self.assertEqual(str(s),'[3*, 2]') #Test for three number s = RPNCaculator() a = s.eval('2 3 5') self.assertEqual(str(s),'[5*, 3, 2]') self.assertEqual(a,5)
def testSimpleEval(self): # Sequence of three eval tests, first evaluates a single number as the string # checks are both for the return value from the method as well as the contents # of the stack. Next two test do the same for two numbers in string and three # numbers in string #Test for one number s = RPNCaculator() a = s.eval('2 ') self.assertEqual(str(s), '[2*]') self.assertEqual(a, 2) #Test for two number s = RPNCaculator() a = s.eval('2 3 ') self.assertEqual(a, 3) self.assertEqual(str(s), '[3*, 2]') #Test for three number s = RPNCaculator() a = s.eval('2 3 5') self.assertEqual(str(s), '[5*, 3, 2]') self.assertEqual(a, 5)
def testBadAdd(self): # First of a sequence of tests intended to get a ValueError from the evaluate # method a = '3 + 5 ' b = '3 5 + +' #------------------------------------------------------------------------------ #Test a try: s = RPNCaculator() a = s.eval(a) self.assertTrue(False,'no excpetion /or not right type excpetion rasied for bad sequences') except ValueError: pass #------------------------------------------------------------------------------ #Test b try: s = RPNCaculator() b = s.eval(b) self.assertTrue(False,'no excpetion /or not right type excpetion rasied for bad sequences') except ValueError : pass
def main(): #while loop will go on forever n = 0 while(n <= 10): try: #ask user to enter the sequence in the right format as described var = input('enter the thing you want to caculate'+':'+' ') if var == 'quit': return else: #call the evaluate method a= RPNCaculator() a = a.eval(var) print (a) #Catch the value Error except ValueError: print('INVALID')
def main(): #while loop will go on forever n = 0 while (n <= 10): try: #ask user to enter the sequence in the right format as described var = input('enter the thing you want to caculate' + ':' + ' ') if var == 'quit': return else: #call the evaluate method a = RPNCaculator() a = a.eval(var) print(a) #Catch the value Error except ValueError: print('INVALID')