Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
trs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
trs
Commits
ac56e741
Commit
ac56e741
authored
13 years ago
by
Sander Mathijs van Veen
Browse files
Options
Downloads
Patches
Plain Diff
Minor improvements to unit test cases and updated pybison.
parent
474ea0ed
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
external/pybison
+1
-1
1 addition, 1 deletion
external/pybison
src/calc.py
+5
-2
5 additions, 2 deletions
src/calc.py
tests/test_calc.py
+2
-2
2 additions, 2 deletions
tests/test_calc.py
tests/test_variables.py
+1
-1
1 addition, 1 deletion
tests/test_variables.py
with
9 additions
and
6 deletions
pybison
@
858c8461
Subproject commit
f1e152a6c890c168ab2c1a4cafaf82b3d3a672fc
Subproject commit
858c8461cb56a983ca63ad7420919673f2d91014
This diff is collapsed.
Click to expand it.
src/calc.py
+
5
−
2
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
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_calc.py
+
2
−
2
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
)]
...
...
This diff is collapsed.
Click to expand it.
tests/test_variables.py
+
1
−
1
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):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment