Skip to content

Commit

Permalink
build: python 3.12 support, make factorial respond to integers only
Browse files Browse the repository at this point in the history
  • Loading branch information
ichintanjoshi committed Mar 8, 2024
1 parent b2250e2 commit 9f805c9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 2 additions & 0 deletions calc/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ def eval_variable(x):
return all_variables[casify(x[0])]

def eval_function(x):
if x[0] in ['fact', 'factorial']: # pythong 3.12 math.factorial won't allow floats
return all_functions[(x[0])](int(x[1]))
return all_functions[casify(x[0])](x[1])

evaluate_actions = {
Expand Down
2 changes: 0 additions & 2 deletions tests/test_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,7 @@ def test_other_functions(self):
self.assert_function_values('factorial', fact_inputs, fact_values)

self.assertRaises(ValueError, calc.evaluator, {}, {}, "fact(-1)")
self.assertRaises(ValueError, calc.evaluator, {}, {}, "fact(0.5)")
self.assertRaises(ValueError, calc.evaluator, {}, {}, "factorial(-1)")
self.assertRaises(ValueError, calc.evaluator, {}, {}, "factorial(0.5)")

def test_constants(self):
"""
Expand Down

0 comments on commit 9f805c9

Please sign in to comment.