test_calc.py 912 B

1234567891011121314151617181920212223242526272829303132333435
  1. import unittest
  2. from src.calc import Parser
  3. from tests.parser import ParserWrapper, run_expressions
  4. class TestCalc(unittest.TestCase):
  5. def setUp(self):
  6. pass
  7. def tearDown(self):
  8. pass
  9. def test_constructor(self):
  10. assert ParserWrapper(Parser, keepfiles=1).run(['1+4']) == 5.0
  11. def test_basic_on_exp(self):
  12. expressions = [('4', 4.0),
  13. ('3+4', 7.0),
  14. ('3-4', -1.0),
  15. ('3/4', .75),
  16. ('-4', -4.0),
  17. ('3^4', 81.0),
  18. ('(4)', 4.0)]
  19. run_expressions(Parser, expressions)
  20. def test_infinity(self):
  21. expressions = [('2^3000', 2**3000),
  22. ('2^-3000', 0.0)]
  23. # ('2^99999999999', None),
  24. # ('2^-99999999999', 0.0)]
  25. run_expressions(Parser, expressions)