test_calc.py 864 B

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