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
c02502b3
Commit
c02502b3
authored
Feb 16, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New constant for calculator and new tests
parent
3a515bfd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
1 deletions
+10
-1
courseware/capa/calc.py
+7
-1
courseware/tests.py
+3
-0
No files found.
courseware/capa/calc.py
View file @
c02502b3
...
@@ -4,6 +4,7 @@ import math
...
@@ -4,6 +4,7 @@ import math
import
operator
import
operator
import
numpy
import
numpy
import
scipy.constants
from
pyparsing
import
Word
,
alphas
,
nums
,
oneOf
,
Literal
from
pyparsing
import
Word
,
alphas
,
nums
,
oneOf
,
Literal
from
pyparsing
import
ZeroOrMore
,
OneOrMore
,
StringStart
from
pyparsing
import
ZeroOrMore
,
OneOrMore
,
StringStart
...
@@ -24,7 +25,12 @@ default_functions = {'sin' : numpy.sin,
...
@@ -24,7 +25,12 @@ default_functions = {'sin' : numpy.sin,
'abs'
:
numpy
.
abs
'abs'
:
numpy
.
abs
}
}
default_variables
=
{
'j'
:
numpy
.
complex
(
0
,
1
),
default_variables
=
{
'j'
:
numpy
.
complex
(
0
,
1
),
'e'
:
numpy
.
complex
(
numpy
.
e
)
'e'
:
numpy
.
e
,
'pi'
:
numpy
.
pi
,
'k'
:
scipy
.
constants
.
k
,
'c'
:
scipy
.
constants
.
c
,
'T'
:
298.15
,
'q'
:
scipy
.
constants
.
e
}
}
log
=
logging
.
getLogger
(
"mitx.courseware.capa"
)
log
=
logging
.
getLogger
(
"mitx.courseware.capa"
)
...
...
courseware/tests.py
View file @
c02502b3
...
@@ -27,6 +27,9 @@ class ModelsTest(unittest.TestCase):
...
@@ -27,6 +27,9 @@ class ModelsTest(unittest.TestCase):
self
.
assertEqual
(
calc
.
evaluator
({},{},
"-1"
),
-
1
)
self
.
assertEqual
(
calc
.
evaluator
({},{},
"-1"
),
-
1
)
self
.
assertEqual
(
calc
.
evaluator
({},{},
"-0.33"
),
-.
33
)
self
.
assertEqual
(
calc
.
evaluator
({},{},
"-0.33"
),
-.
33
)
self
.
assertEqual
(
calc
.
evaluator
({},{},
"-.33"
),
-.
33
)
self
.
assertEqual
(
calc
.
evaluator
({},{},
"-.33"
),
-.
33
)
self
.
assertEqual
(
calc
.
evaluator
(
variables
,
functions
,
"R1*R3"
),
8.0
)
self
.
assertTrue
(
abs
(
calc
.
evaluator
(
variables
,
functions
,
"sin(e)-0.41"
))
<
0.01
)
self
.
assertTrue
(
abs
(
calc
.
evaluator
(
variables
,
functions
,
"k*T/q-0.025"
))
<
0.001
)
exception_happened
=
False
exception_happened
=
False
try
:
try
:
evaluator
({},{},
"5+7 QWSEKO"
)
evaluator
({},{},
"5+7 QWSEKO"
)
...
...
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