Exemple #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' )
Exemple #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' )
Exemple #3
0
 def test_evaluate_variable_plus(self):
     from arithmetic import evaluate
     res = evaluate('f+1', variables={'f':'1'})
     self.assertEqual( res, '2' )
Exemple #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' )
Exemple #5
0
 def test_evaluate_numeric(self):
     from arithmetic import evaluate
     res = evaluate('5+2')
     self.assertEqual( res, '7' )
Exemple #6
0
 def test_evaluate_variable(self):
     from arithmetic import evaluate
     res = evaluate('a', variables={'a':'1'})
     self.assertEqual( res, '1' )
Exemple #7
0
 def test_evaluate_factors(self):
     from arithmetic import evaluate
     res = evaluate('5**2')
     self.assertEqual( res, '25' )
Exemple #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' )
Exemple #9
0
 def test_evaluate_factor_open_parenthesis(self):
     from arithmetic import evaluate
     res = evaluate('(1)')
     self.assertEqual( res, '1' )
Exemple #10
0
 def test_evaluate_factor_percentage(self):
     from arithmetic import evaluate
     res = evaluate('50%')
     self.assertEqual( res, '0.5' )
Exemple #11
0
 def test_evaluate_negative_factor(self):
     from arithmetic import evaluate
     res = evaluate('5*-2')
     self.assertEqual( res, '-10' )