Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Hsin-Yu Chien
edx-platform-release
Commits
43395b70
Commit
43395b70
authored
11 years ago
by
Peter Baratta
Browse files
Options
Downloads
Patches
Plain Diff
Enable coverage for calc module; split off tests
parent
82482e89
Loading
Loading
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
common/lib/calc/.coveragerc
+15
-0
15 additions, 0 deletions
common/lib/calc/.coveragerc
common/lib/calc/calc.py
+0
-24
0 additions, 24 deletions
common/lib/calc/calc.py
common/lib/calc/tests/test_calc.py
+9
-2
9 additions, 2 deletions
common/lib/calc/tests/test_calc.py
with
24 additions
and
26 deletions
common/lib/calc/.coveragerc
0 → 100644
+
15
−
0
View file @
43395b70
# .coveragerc for common/lib/calc
[run]
data_file = reports/common/lib/calc/.coverage
source = common/lib/calc
branch = true
[report]
ignore_errors = True
[html]
title = Calc Python Test Coverage Report
directory = reports/common/lib/calc/cover
[xml]
output = reports/common/lib/calc/coverage.xml
This diff is collapsed.
Click to expand it.
common/lib/calc/calc.py
+
0
−
24
View file @
43395b70
...
...
@@ -230,27 +230,3 @@ def evaluator(variables, functions, string, cs=False):
expr
<<
Optional
((
plus
|
minus
))
+
term
+
ZeroOrMore
((
plus
|
minus
)
+
term
)
# -5 + 4 - 3
expr
=
expr
.
setParseAction
(
sum_parse_action
)
return
(
expr
+
stringEnd
).
parseString
(
string
)[
0
]
if
__name__
==
'
__main__
'
:
variables
=
{
'
R1
'
:
2.0
,
'
R3
'
:
4.0
}
functions
=
{
'
sin
'
:
numpy
.
sin
,
'
cos
'
:
numpy
.
cos
}
print
"
X
"
,
evaluator
(
variables
,
functions
,
"
10000||sin(7+5)-6k
"
)
print
"
X
"
,
evaluator
(
variables
,
functions
,
"
13
"
)
print
evaluator
({
'
R1
'
:
2.0
,
'
R3
'
:
4.0
},
{},
"
13
"
)
print
evaluator
({
'
e1
'
:
1
,
'
e2
'
:
1.0
,
'
R3
'
:
7
,
'
V0
'
:
5
,
'
R5
'
:
15
,
'
I1
'
:
1
,
'
R4
'
:
6
},
{},
"
e2
"
)
print
evaluator
({
'
a
'
:
2.2997471478310274
,
'
k
'
:
9
,
'
m
'
:
8
,
'
x
'
:
0.66009498411213041
},
{},
"
5
"
)
print
evaluator
({},
{},
"
-1
"
)
print
evaluator
({},
{},
"
-(7+5)
"
)
print
evaluator
({},
{},
"
-0.33
"
)
print
evaluator
({},
{},
"
-.33
"
)
print
evaluator
({},
{},
"
5+1*j
"
)
print
evaluator
({},
{},
"
j||1
"
)
print
evaluator
({},
{},
"
e^(j*pi)
"
)
print
evaluator
({},
{},
"
fact(5)
"
)
print
evaluator
({},
{},
"
factorial(5)
"
)
try
:
print
evaluator
({},
{},
"
5+7 QWSEKO
"
)
except
UndefinedVariable
:
print
"
Successfully caught undefined variable
"
This diff is collapsed.
Click to expand it.
common/lib/calc/tests/test_calc.py
+
9
−
2
View file @
43395b70
...
...
@@ -3,7 +3,7 @@ unittests for calc.py
Run like this:
rake test_common/lib/calc
??
rake test_common/lib/calc
"""
...
...
@@ -82,6 +82,8 @@ class EvaluatorTest(unittest.TestCase):
operator
,
input_str
,
answer
)
self
.
assertEqual
(
answer
,
result
,
msg
=
fail_msg
)
def
test_raises_zero_division_err
(
self
):
'''
Ensure division by zero gives an error
'''
self
.
assertRaises
(
ZeroDivisionError
,
calc
.
evaluator
,
{},
{},
'
1/0
'
)
...
...
@@ -98,6 +100,8 @@ class EvaluatorTest(unittest.TestCase):
# I don't know why you would want this, but it works.
self
.
assertEqual
(
calc
.
evaluator
({},
{},
"
j||1
"
),
0.5
+
0.5j
)
def
test_parallel_resistors_zero_error
(
self
):
'''
Check the behavior of the || operator with 0
'''
self
.
assertRaises
(
ZeroDivisionError
,
calc
.
evaluator
,
{},
{},
'
0||1
'
)
...
...
@@ -121,7 +125,7 @@ class EvaluatorTest(unittest.TestCase):
angles
=
[
'
-pi/4
'
,
'
0
'
,
'
pi/6
'
,
'
pi/5
'
,
'
5*pi/4
'
,
'
9*pi/4
'
,
'
1 + j
'
]
sin_values
=
[
-
0.707
,
0
,
0.5
,
0.588
,
-
0.707
,
0.707
,
1.298
+
0.635j
]
cos_values
=
[
0.707
,
1
,
0.866
,
0.809
,
-
0.707
,
0.707
,
0.834
-
0.989j
]
tan_values
=
[
-
1
,
0
,
0.577
,
0.727
,
1
,
1
,
0.762j
,
0.272
+
1.084j
]
tan_values
=
[
-
1
,
0
,
0.577
,
0.727
,
1
,
1
,
0.272
+
1.084j
]
# Cannot test tan(pi/2) b/c pi/2 is a float and not precise...
self
.
assert_function_values
(
'
sin
'
,
angles
,
sin_values
)
...
...
@@ -239,6 +243,9 @@ class EvaluatorTest(unittest.TestCase):
variables
=
{
'
x
'
:
9.72
,
'
y
'
:
7.91
,
'
loooooong
'
:
6.4
}
# Should not change value of constant
# even with different numbers of variables...
self
.
assertEqual
(
calc
.
evaluator
({
'
x
'
:
9.72
},
{},
'
13
'
),
13
)
self
.
assertEqual
(
calc
.
evaluator
({
'
x
'
:
9.72
,
'
y
'
:
7.91
},
{},
'
13
'
),
13
)
self
.
assertEqual
(
calc
.
evaluator
(
variables
,
{},
'
13
'
),
13
)
# Easy evaluation
...
...
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