Exemplo n.º 1
0
 def test_evaluate_function_name_substring(self):
     from arithmetic import evaluate
     res = evaluate('f', variables={'af':'1'}, functions={'f': 'af'})
     self.assertEqual( res, '1' )
Exemplo n.º 2
0
 def test_evaluate_function_recursive_no_initial_value(self):
     from arithmetic import evaluate
     res = evaluate('f', functions={'f': 'f+1'})
     self.assertEqual( res, '0' )
Exemplo n.º 3
0
 def test_evaluate_variable_plus(self):
     from arithmetic import evaluate
     res = evaluate('f+1', variables={'f':'1'})
     self.assertEqual( res, '2' )
Exemplo n.º 4
0
 def test_evaluate_function(self):
     from arithmetic import evaluate
     res = evaluate('f', variables={'a':'1'}, functions={'f': 'a+1'})
     self.assertEqual( res, '2' )
Exemplo n.º 5
0
 def test_evaluate_numeric(self):
     from arithmetic import evaluate
     res = evaluate('5+2')
     self.assertEqual( res, '7' )
Exemplo n.º 6
0
 def test_evaluate_variable(self):
     from arithmetic import evaluate
     res = evaluate('a', variables={'a':'1'})
     self.assertEqual( res, '1' )
Exemplo n.º 7
0
 def test_evaluate_factors(self):
     from arithmetic import evaluate
     res = evaluate('5**2')
     self.assertEqual( res, '25' )
Exemplo n.º 8
0
 def test_evaluate_factor_multiple_word_identifier(self):
     from arithmetic import evaluate
     res = evaluate('avg val', variables={'avg val':'5'})
     self.assertEqual( res, '5' )
Exemplo n.º 9
0
 def test_evaluate_factor_open_parenthesis(self):
     from arithmetic import evaluate
     res = evaluate('(1)')
     self.assertEqual( res, '1' )
Exemplo n.º 10
0
 def test_evaluate_factor_percentage(self):
     from arithmetic import evaluate
     res = evaluate('50%')
     self.assertEqual( res, '0.5' )
Exemplo n.º 11
0
 def test_evaluate_negative_factor(self):
     from arithmetic import evaluate
     res = evaluate('5*-2')
     self.assertEqual( res, '-10' )