예제 #1
0
 def test_tokenize_addition(self):
     '''Tokenizes a rpn expression'''
     self.assert_tokenize('4 2 +', [4, 2, make_operator('+')])
예제 #2
0
 def test_make_operator_add(self):
     '''Addition operator should add'''
     stack = [4, 2]
     operator = make_operator('+')
     operator(stack)
     self.assertEqual(stack.pop(), 6)
예제 #3
0
 def test_tokenize_with_operator(self):
     '''Tokenizes operators correctly'''
     self.assert_tokenize('+', [make_operator('+')])
예제 #4
0
 def test_tokenize_division(self):
     '''Tokenizes a rpn division'''
     self.assert_tokenize('4 2 /', [4, 2, make_operator('/')])
예제 #5
0
 def test_tokenize_multiplication(self):
     '''Tokenizes a rpn subtraction'''
     self.assert_tokenize('4 2 *', [4, 2, make_operator('*')])
예제 #6
0
 def test_make_operator_multiply(self):
     '''Multiplication operator should multiply'''
     stack = [4, 2]
     operator = make_operator('*')
     operator(stack)
     self.assertEqual(stack.pop(), 8)
예제 #7
0
 def test_tokenize_subtraction(self):
     '''Tokenizes a rpn subtraction'''
     self.assert_tokenize('4 2 -', [4, 2, make_operator('-')])
예제 #8
0
 def test_make_operator_subtract(self):
     '''Division operator should divide'''
     stack = [4, 2]
     operator = make_operator('/')
     operator(stack)
     self.assertEqual(stack.pop(), 2)
예제 #9
0
 def test_make_operator_subtract(self):
     '''Subtraction operator should add'''
     stack = [4, 2]
     operator = make_operator('-')
     operator(stack)
     self.assertEqual(stack.pop(), 2)
예제 #10
0
 def test_execute_addition(self):
     '''Should execute an addition correctly'''
     self.assert_execute([4, 2, make_operator('+')], 6)
예제 #11
0
파일: rpn_test.py 프로젝트: Djsouls/calc
 def test_execute_multiplication(self):
     '''Should execute a multiplication correctly'''
     self.assert_execute([4, 2, make_operator('*')], 8)
예제 #12
0
파일: rpn_test.py 프로젝트: Djsouls/calc
 def test_execute_division(self):
     '''Should execute a division correctly'''
     self.assert_execute([4, 2, make_operator('/')], 2)