Преглед на файлове

Minor improvements to unit test cases and updated pybison.

Sander Mathijs van Veen преди 14 години
родител
ревизия
ac56e74108
променени са 4 файла, в които са добавени 9 реда и са изтрити 6 реда
  1. 1 1
      external/pybison
  2. 5 2
      src/calc.py
  3. 2 2
      tests/test_calc.py
  4. 1 1
      tests/test_variables.py

+ 1 - 1
external/pybison

@@ -1 +1 @@
-Subproject commit f1e152a6c890c168ab2c1a4cafaf82b3d3a672fc
+Subproject commit 858c8461cb56a983ca63ad7420919673f2d91014

+ 5 - 2
src/calc.py

@@ -3,6 +3,7 @@
 A simple pybison parser program implementing a calculator
 """
 
+from __future__ import division
 from sympy import Symbol
 from logger import filter_non_ascii
 
@@ -48,6 +49,7 @@ class Parser(BisonParser):
     def __init__(self, **kwargs):
         BisonParser.__init__(self, **kwargs)
         self.interactive = kwargs.get('interactive', 0)
+        self.timeout = kwargs.get('timeout', 0)
 
     # ------------------------------------------------------------------
     # override default read method with a version that prompts for input
@@ -117,8 +119,9 @@ class Parser(BisonParser):
         # rule: NUMBER
         if option == 0:
             # TODO: A bit hacky, this achieves long integers and floats.
-            # return float(values[0]) if '.' in values[0] else long(values[0])
-            return float(values[0])
+            #return float(values[0]) if '.' in values[0] else long(values[0])
+            #return float(values[0])
+            return float(values[0]) if '.' in values[0] else int(values[0])
 
         # rule: IDENTIFIER
         if option == 1:

+ 2 - 2
tests/test_calc.py

@@ -26,8 +26,8 @@ class TestCalc(unittest.TestCase):
         run_expressions(expressions)
 
     def test_infinity(self):
-        expressions = [('2^9999', None),
-                       ('2^-9999', 0.0),
+        expressions = [('2^3000', 2**3000),
+                       ('2^-3000', 0.0),
                        ('2^99999999999', None),
                        ('2^-99999999999', 0.0)]
 

+ 1 - 1
tests/test_variables.py

@@ -19,7 +19,7 @@ class TestVariables(unittest.TestCase):
 
     def test_addition_of_two_terms(self):
         a, b = symbols('a,b')
-        expressions = [('4*a + 5*b', 4.0*a + 5.0*b)]
+        expressions = [('4*a + 5*b', 4*a + 5*b)]
         run_expressions(expressions)
 
     #def test_short_addition_of_two_terms(self):