Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
80a27f93
Commit
80a27f93
authored
May 31, 2013
by
Peter Baratta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test and functionality for trailing period
parent
46967a78
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
3 deletions
+16
-3
common/lib/calc/calc.py
+1
-1
common/lib/calc/tests/test_calc.py
+15
-2
No files found.
common/lib/calc/calc.py
View file @
80a27f93
...
...
@@ -183,7 +183,7 @@ def evaluator(variables, functions, string, cs=False):
number_part
=
Word
(
nums
)
# 0.33 or 7 or .34
inner_number
=
(
number_part
+
Optional
(
"."
+
number_part
))
|
(
"."
+
number_part
)
inner_number
=
(
number_part
+
Optional
(
"."
+
Optional
(
number_part
)
))
|
(
"."
+
number_part
)
# 0.33k or -17
number
=
(
Optional
(
minus
|
plus
)
+
inner_number
...
...
common/lib/calc/tests/test_calc.py
View file @
80a27f93
...
...
@@ -5,7 +5,7 @@ Unit tests for calc.py
import
unittest
import
numpy
import
calc
from
pyparsing
import
ParseException
class
EvaluatorTest
(
unittest
.
TestCase
):
"""
...
...
@@ -20,6 +20,11 @@ class EvaluatorTest(unittest.TestCase):
def
test_number_input
(
self
):
"""
Test different kinds of float inputs
See also
test_trailing_period (slightly different)
test_exponential_answer
test_si_suffix
"""
easy_eval
=
lambda
x
:
calc
.
evaluator
({},
{},
x
)
...
...
@@ -30,7 +35,15 @@ class EvaluatorTest(unittest.TestCase):
self
.
assertEqual
(
easy_eval
(
"-13"
),
-
13
)
self
.
assertEqual
(
easy_eval
(
"-3.14"
),
-
3.14
)
self
.
assertEqual
(
easy_eval
(
"-.618033989"
),
-
0.618033989
)
# See also test_exponential_answer and test_si_suffix
def
test_trailing_period
(
self
):
"""
Test that things like '4.' will be 4 and not throw an error
"""
try
:
self
.
assertEqual
(
4.0
,
calc
.
evaluator
({},
{},
'4.'
))
except
ParseException
:
self
.
fail
(
"'4.' is a valid input, but threw an exception"
)
def
test_exponential_answer
(
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