Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
trs
Commits
ac56e741
Commit
ac56e741
authored
Nov 21, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor improvements to unit test cases and updated pybison.
parent
474ea0ed
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
6 deletions
+9
-6
external/pybison
external/pybison
+1
-1
src/calc.py
src/calc.py
+5
-2
tests/test_calc.py
tests/test_calc.py
+2
-2
tests/test_variables.py
tests/test_variables.py
+1
-1
No files found.
pybison
@
858c8461
Subproject commit
f1e152a6c890c168ab2c1a4cafaf82b3d3a672fc
Subproject commit
858c8461cb56a983ca63ad7420919673f2d91014
src/calc.py
View file @
ac56e741
...
...
@@ -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
:
...
...
tests/test_calc.py
View file @
ac56e741
...
...
@@ -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
)]
...
...
tests/test_variables.py
View file @
ac56e741
...
...
@@ -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):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment