示例#1
0
    def testPushOneBadType(self):
        # Create an RPNCalculator and try to push a non-numeric ValueError

        try:
            s = RPNCaculator()
            s.push('Seed')
        except TypeError:
            pass
    def testPushOne(self):
        #Test the push method
        #pushing in only one element each time
        #and check the corresponding stack status

        S = RPNCaculator()
        S.push(5)

        self.assertEqual(str(S), '[5*]')
        S = RPNCaculator()

        S.push(7.5)
        self.assertEqual(str(S), '[7.5*]')
    def testAddFloat(self):
        # Test the addition of the floats

        # Push two floats 
        # apply addition method
        # CHeck just the  resultant sum value on the stack
        s = RPNCaculator()
        s.push(2.3)
        s.push(5.7)
        s.add()
        self.assertEqual(str(s),'[8.0*]')
        a = s.pop()
        self.assertEqual(a,8)
示例#4
0
    def testSubInt(self):
        # Test the subtraction of integers

        # Benign test of two pushes
        # Apply the subtraction Method
        # Check just the resultant subtraction value on the stack
        s = RPNCaculator()
        s.push(2)
        s.push(5)
        s.sub()
        self.assertEqual(str(s), '[-3*]')
        a = s.pop()
        self.assertEqual(a, -3)
示例#5
0
    def testPushOne(self):
        #Test the push method
        #pushing in only one element each time
        #and check the corresponding stack status

        S = RPNCaculator()
        S.push(5)

        self.assertEqual(str(S), '[5*]')
        S = RPNCaculator()

        S.push(7.5)
        self.assertEqual(str(S), '[7.5*]')
示例#6
0
    def testAddFloat(self):
        # Test the addition of the floats

        # Push two floats
        # apply addition method
        # CHeck just the  resultant sum value on the stack
        s = RPNCaculator()
        s.push(2.3)
        s.push(5.7)
        s.add()
        self.assertEqual(str(s), '[8.0*]')
        a = s.pop()
        self.assertEqual(a, 8)
    def testSubInt(self):
        # Test the subtraction of integers


        # Benign test of two pushes
        # Apply the subtraction Method
        # Check just the resultant subtraction value on the stack        
        s = RPNCaculator()
        s.push(2)
        s.push(5)
        s.sub()
        self.assertEqual(str(s),'[-3*]')
        a = s.pop()
        self.assertEqual(a,-3)
示例#8
0
    def testAddInt(self):
        #Test the addition of two integers

        # Benign test of two pushes
        # apply the add Method
        # Check just the resultant sum value on the stack
        s = RPNCaculator()
        s.push(2)
        s.push(5)
        s.add()
        #check just the result on the stack

        self.assertEqual(str(s), '[7*]')
        a = s.pop()
        self.assertEqual(a, 7)
    def testAddInt(self):
        #Test the addition of two integers


        # Benign test of two pushes
        # apply the add Method
        # Check just the resultant sum value on the stack
        s = RPNCaculator()
        s.push(2)
        s.push(5)
        s.add()
        #check just the result on the stack

        self.assertEqual(str(s),'[7*]')
        a = s.pop()
        self.assertEqual(a,7)
    def testPushTwo(self):
        # Create an RPNCalculator, push two values and compare string result
        s =  RPNCaculator()
        s.push(2)
        s.push(5)
        self.assertEqual(str(s),'[5*, 2]')

        s =  RPNCaculator()
        s.push(2)
        s.push(5.78)
        self.assertEqual(str(s),'[5.78*, 2]')
示例#11
0
    def testPushTwo(self):
        # Create an RPNCalculator, push two values and compare string result
        s = RPNCaculator()
        s.push(2)
        s.push(5)
        self.assertEqual(str(s), '[5*, 2]')

        s = RPNCaculator()
        s.push(2)
        s.push(5.78)
        self.assertEqual(str(s), '[5.78*, 2]')
    def testAddThree(self):
        #Test adding of three numbers (Mixture of the floats and integers)

        #Push first two values onto the stack
        #Apply the addition (the sum back to the stack)
        #push the third to the stack
        #apply the addition
        #Check just the final resultant sum value on the stack
        s = RPNCaculator()
        s.push(3)
        s.push(5.7)
        s.add()
        s.push(2.3)
        s.add()
        self.assertEqual(str(s),'[11.0*]')
        a = s.pop()
        self.assertEqual(a,11.0)        
示例#13
0
    def testAddThree(self):
        #Test adding of three numbers (Mixture of the floats and integers)

        #Push first two values onto the stack
        #Apply the addition (the sum back to the stack)
        #push the third to the stack
        #apply the addition
        #Check just the final resultant sum value on the stack
        s = RPNCaculator()
        s.push(3)
        s.push(5.7)
        s.add()
        s.push(2.3)
        s.add()
        self.assertEqual(str(s), '[11.0*]')
        a = s.pop()
        self.assertEqual(a, 11.0)