コード例 #1
0
 def test_assignment_visa_variabel(self):
     line = "3 = a"
     line1 = "a"
     wtok = TokenizeWrapper( line )
     result = my_calculator.assignment( wtok )
     wtok1 = TokenizeWrapper(line1)
     self.assertEqual( my_calculator.assignment(wtok1) , 3 )
コード例 #2
0
 def test_assignment_full(self):
     line = "(2=x) + (3=y=z) = a"
     wtok = TokenizeWrapper( line )
     result = my_calculator.assignment( wtok )
     self.assertEqual(my_calculator.vardict.get('x') , 2 )
     self.assertEqual(my_calculator.vardict.get('y') , 3 )
     self.assertEqual(my_calculator.vardict.get('z') , 3 )
     self.assertEqual(my_calculator.vardict.get('a') , 5 )
コード例 #3
0
 def test_korrekt_expression(self):
     while True:
         line = "1 + 1 + 1"
         try:
             wtok = TokenizeWrapper(line)
             result = my_calculator.expression(wtok)
             self.assertEqual( result , 3)
         except TokenError:
             print('*** Error. Unbalanced parentheses')
         except CalculatorException as e:
             print(e)
コード例 #4
0
ファイル: calculator.py プロジェクト: rogue67/pysource
def main():
    print("Very simple calculator")
    while True:
        line = input('HAL 9000 :')
        try:
            wtok = TokenizeWrapper(line)
            result = statement(wtok)
            print('Result: ', result)
        except TokenError:
            print('*** Error. Unbalanced parentheses')
        except CalculatorException as e:
            print(e)
コード例 #5
0
 def test_assignment_pythagoras(self):
     line = "sin(2)*sin(2) + cos(2)*cos(2)"
     wtok = TokenizeWrapper( line )
     result = my_calculator.assignment( wtok )
     self.assertEqual(result , 1.0 )
コード例 #6
0
 def test_term_mul(self) :
     line = "2 * 3"
     wtok = TokenizeWrapper( line )
     result = my_calculator.term( wtok )
     self.assertEqual( result , 6 )
コード例 #7
0
 def test_assignment_dubbel_parantes_V(self):
     line = "((1+3)"
     wtok = TokenizeWrapper( line )
     self.assertRaises(my_calculator.TokenError, my_calculator.assignment , wtok)
コード例 #8
0
 def test_assignment_parantes(self):
     line = "(3 = z)"
     wtok = TokenizeWrapper( line )
     result = my_calculator.assignment( wtok )
     self.assertEqual( my_calculator.vardict.get('z') , 3 )
コード例 #9
0
 def test_assingment_log_negativ_input(self):
     line = "log( -1 )"
     wtok = TokenizeWrapper( line )
     self.assertRaises( my_calculator.CalculatorException , my_calculator.assignment, wtok )
コード例 #10
0
 def test_assingment_cos(self):
     line = "cos(3.141592653589793)"
     wtok = TokenizeWrapper( line )
     result = my_calculator.assignment( wtok )
     self.assertEqual( result , math.cos(math.pi))
コード例 #11
0
 def test_assingment_sin(self):
     line = 'sin( 10 )'
     wtok = TokenizeWrapper( line )
     result = my_calculator.assignment( wtok )
     self.assertEqual( result , math.sin( 10 ) )
コード例 #12
0
 def test_assignment_saknar_parantes(self):
     line = "1+(2+7 = h"
     wtok = TokenizeWrapper( line )
     self.assertRaises(my_calculator.TokenError, my_calculator.assignment , wtok)
コード例 #13
0
 def test_assingment_funktion_utan_parantes(self):
     line = "sin 4"
     wtok = TokenizeWrapper( line )
     self.assertRaises( my_calculator.CalculatorException , my_calculator.assignment, wtok )
コード例 #14
0
 def test_function_false(self):
     line = 'roger';
     wtok = TokenizeWrapper( line )
     self.assertFalse( my_calculator.is_function( wtok ),msg=None )
コード例 #15
0
 def test_function_true(self):
     line = 'sin';
     wtok = TokenizeWrapper( line )
     self.assertTrue( my_calculator.is_function( wtok ),msg=None )
コード例 #16
0
 def test_assignment_z(self):
     line = "1 + 2 + 3 = z"
     wtok = TokenizeWrapper( line )
     result = my_calculator.assignment( wtok )
     self.assertEqual( my_calculator.vardict.get('z') , 6 )
コード例 #17
0
 def test_assignment_inget_lika_med(self):
     line = "1 - (5 - 2*2)/(1+1) - (-2 + 1)"
     wtok = TokenizeWrapper( line )
     result = my_calculator.assignment( wtok )
     self.assertEqual(result , 1.5 )        
コード例 #18
0
 def test_assignment_log(self):
     line = "log( 2.718281828459045 )"
     wtok = TokenizeWrapper( line )
     result = my_calculator.assignment(wtok)
     self.assertEqual( result , 1.0)
コード例 #19
0
 def test_assignment_two_equal_vars(self):
     line = "(2=x=y)"
     wtok = TokenizeWrapper( line )
     result = my_calculator.assignment( wtok )
     self.assertEqual(my_calculator.vardict.get('x') , 2 )
     self.assertEqual(my_calculator.vardict.get('y') , 2 )
コード例 #20
0
 def test_assignment_exp(self):
     line = 'exp( 0 )'
     wtok = TokenizeWrapper( line )
     result = my_calculator.assignment( wtok )
     self.assertEqual( result , 1.0)
コード例 #21
0
 def test_expression_sju(self):
     line = "7"
     wtok = TokenizeWrapper( line )
     result = my_calculator.expression( wtok )
     self.assertEqual( result , 7 )
コード例 #22
0
 def test_assignment_minus(self):
     line = "-(2+2)"
     wtok = TokenizeWrapper( line )
     result = my_calculator.assignment( wtok )
     self.assertEqual( result , -4.0)        
コード例 #23
0
 def test_expression_minus(self):
     line = "2-3"
     wtok = TokenizeWrapper( line )
     result = my_calculator.expression( wtok )
     self.assertEqual( result , -1 )
コード例 #24
0
 def test_statement_dubbel_parantes_H(self):
     line = "(1+3))"
     wtok = TokenizeWrapper( line )
     self.assertRaises(my_calculator.CalculatorException, my_calculator.statement , wtok)
コード例 #25
0
 def test_term_sinus(self) :
     line = "sin(2)*sin(2)"
     wtok = TokenizeWrapper( line )
     result = my_calculator.term( wtok )
     self.assertEqual( result , math.sin(2)*math.sin(2) )
コード例 #26
0
 def test_statement_quit(self):
     line = "quit"
     wtok = TokenizeWrapper( line )
     self.assertRaises(SystemExit, my_calculator.statement, wtok)