Minor improvements to unit test cases and updated pybison.

parent 474ea0ed
pybison @ 858c8461
Subproject commit f1e152a6c890c168ab2c1a4cafaf82b3d3a672fc Subproject commit 858c8461cb56a983ca63ad7420919673f2d91014
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
A simple pybison parser program implementing a calculator A simple pybison parser program implementing a calculator
""" """
from __future__ import division
from sympy import Symbol from sympy import Symbol
from logger import filter_non_ascii from logger import filter_non_ascii
...@@ -48,6 +49,7 @@ class Parser(BisonParser): ...@@ -48,6 +49,7 @@ class Parser(BisonParser):
def __init__(self, **kwargs): def __init__(self, **kwargs):
BisonParser.__init__(self, **kwargs) BisonParser.__init__(self, **kwargs)
self.interactive = kwargs.get('interactive', 0) self.interactive = kwargs.get('interactive', 0)
self.timeout = kwargs.get('timeout', 0)
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# override default read method with a version that prompts for input # override default read method with a version that prompts for input
...@@ -117,8 +119,9 @@ class Parser(BisonParser): ...@@ -117,8 +119,9 @@ class Parser(BisonParser):
# rule: NUMBER # rule: NUMBER
if option == 0: if option == 0:
# TODO: A bit hacky, this achieves long integers and floats. # 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]) if '.' in values[0] else long(values[0])
return float(values[0]) #return float(values[0])
return float(values[0]) if '.' in values[0] else int(values[0])
# rule: IDENTIFIER # rule: IDENTIFIER
if option == 1: if option == 1:
......
...@@ -26,8 +26,8 @@ class TestCalc(unittest.TestCase): ...@@ -26,8 +26,8 @@ class TestCalc(unittest.TestCase):
run_expressions(expressions) run_expressions(expressions)
def test_infinity(self): def test_infinity(self):
expressions = [('2^9999', None), expressions = [('2^3000', 2**3000),
('2^-9999', 0.0), ('2^-3000', 0.0),
('2^99999999999', None), ('2^99999999999', None),
('2^-99999999999', 0.0)] ('2^-99999999999', 0.0)]
......
...@@ -19,7 +19,7 @@ class TestVariables(unittest.TestCase): ...@@ -19,7 +19,7 @@ class TestVariables(unittest.TestCase):
def test_addition_of_two_terms(self): def test_addition_of_two_terms(self):
a, b = symbols('a,b') 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) run_expressions(expressions)
#def test_short_addition_of_two_terms(self): #def test_short_addition_of_two_terms(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment