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
2793bb43
Commit
2793bb43
authored
May 23, 2013
by
Peter Baratta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add few more tests; fix a small bug with parallel resistors
parent
2486f7c2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
4 deletions
+10
-4
common/lib/calc/calc.py
+2
-0
common/lib/calc/tests/test_calc.py
+8
-3
common/lib/capa/capa/tests/test_responsetypes.py
+0
-1
No files found.
common/lib/calc/calc.py
View file @
2793bb43
...
...
@@ -144,6 +144,8 @@ def evaluator(variables, functions, string, cs=False):
return
x
def
parallel
(
x
):
# Parallel resistors [ 1 2 ] => 2/3
# convert from pyparsing.ParseResults, which doesn't support '0 in x'
x
=
list
(
x
)
if
len
(
x
)
==
1
:
return
x
[
0
]
if
0
in
x
:
...
...
common/lib/calc/tests/test_calc.py
View file @
2793bb43
...
...
@@ -92,6 +92,10 @@ class EvaluatorTest(unittest.TestCase):
"""
self
.
assertRaises
(
ZeroDivisionError
,
calc
.
evaluator
,
{},
{},
'1/0'
)
self
.
assertRaises
(
ZeroDivisionError
,
calc
.
evaluator
,
{},
{},
'1/0.0'
)
self
.
assertRaises
(
ZeroDivisionError
,
calc
.
evaluator
,
{
'x'
:
0.0
},
{},
'1/x'
)
def
test_parallel_resistors
(
self
):
"""
...
...
@@ -107,12 +111,13 @@ class EvaluatorTest(unittest.TestCase):
self
.
assertEqual
(
calc
.
evaluator
({},
{},
'1||1||2'
),
0.4
)
self
.
assertEqual
(
calc
.
evaluator
({},
{},
"j||1"
),
0.5
+
0.5
j
)
def
test_parallel_resistors_
zero_error
(
self
):
def
test_parallel_resistors_
with_zero
(
self
):
"""
Check the behavior of the || operator with 0
"""
self
.
assertRaises
(
ZeroDivisionError
,
calc
.
evaluator
,
{},
{},
'0||1'
)
self
.
assertTrue
(
numpy
.
isnan
(
calc
.
evaluator
({},
{},
'0||1'
)))
self
.
assertTrue
(
numpy
.
isnan
(
calc
.
evaluator
({},
{},
'0.0||1'
)))
self
.
assertTrue
(
numpy
.
isnan
(
calc
.
evaluator
({
'x'
:
0.0
},
{},
'x||1'
)))
def
assert_function_values
(
self
,
fname
,
ins
,
outs
,
tolerance
=
1e-3
):
"""
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
2793bb43
...
...
@@ -10,7 +10,6 @@ import random
import
unittest
import
textwrap
import
mock
import
textwrap
from
.
import
new_loncapa_problem
,
test_system
...
...
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