Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
8c838c71
Commit
8c838c71
authored
Mar 07, 2014
by
Sebastien Robin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unit test: show how to test examples (first test of TwoServers.py)
parent
71b8c72e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
23 deletions
+74
-23
dream/simulation/Examples/TwoServers.py
dream/simulation/Examples/TwoServers.py
+32
-23
dream/simulation/Examples/__init__.py
dream/simulation/Examples/__init__.py
+0
-0
dream/tests/testSimulationExamples.py
dream/tests/testSimulationExamples.py
+42
-0
No files found.
dream/simulation/Examples/TwoServers.py
View file @
8c838c71
...
...
@@ -49,30 +49,39 @@ initialize() #initialize the simulation (SimPy method)
#initialize all the objects
R
.
initialize
()
for
object
in
G
.
ObjList
:
def
main
():
for
object
in
G
.
ObjList
:
object
.
initialize
()
for
objectInterruption
in
G
.
ObjectInterruptionList
:
for
objectInterruption
in
G
.
ObjectInterruptionList
:
objectInterruption
.
initialize
()
#activate all the objects
for
object
in
G
.
ObjList
:
#activate all the objects
for
object
in
G
.
ObjList
:
activate
(
object
,
object
.
run
())
for
objectInterruption
in
G
.
ObjectInterruptionList
:
for
objectInterruption
in
G
.
ObjectInterruptionList
:
activate
(
objectInterruption
,
objectInterruption
.
run
())
G
.
maxSimTime
=
1440.0
#set G.maxSimTime 1440.0 minutes (1 day)
G
.
maxSimTime
=
1440.0
#set G.maxSimTime 1440.0 minutes (1 day)
simulate
(
until
=
G
.
maxSimTime
)
#run the simulation
simulate
(
until
=
G
.
maxSimTime
)
#run the simulation
#carry on the post processing operations for every object in the topology
for
object
in
G
.
ObjList
:
#carry on the post processing operations for every object in the topology
for
object
in
G
.
ObjList
:
object
.
postProcessing
()
R
.
postProcessing
()
#print the results
print
"the system produced"
,
E
.
numOfExits
,
"parts"
print
"the blockage ratio of"
,
M1
.
objName
,
"is"
,
(
M1
.
totalBlockageTime
/
G
.
maxSimTime
)
*
100
,
"%"
print
"the working ratio of"
,
R
.
objName
,
"is"
,
(
R
.
totalWorkingTime
/
G
.
maxSimTime
)
*
100
,
"%"
R
.
postProcessing
()
#print the results
print
"the system produced"
,
E
.
numOfExits
,
"parts"
blockage_ratio
=
(
M1
.
totalBlockageTime
/
G
.
maxSimTime
)
*
100
working_ratio
=
(
R
.
totalWorkingTime
/
G
.
maxSimTime
)
*
100
print
"the blockage ratio of"
,
M1
.
objName
,
"is"
,
blockage_ratio
,
"%"
print
"the working ratio of"
,
R
.
objName
,
"is"
,
working_ratio
,
"%"
return
{
"parts"
:
E
.
numOfExits
,
"blockage_ratio"
:
blockage_ratio
,
"working_ratio"
:
working_ratio
}
if
__name__
==
'__main__'
:
main
()
dream/simulation/Examples/__init__.py
0 → 100644
View file @
8c838c71
dream/tests/testSimulationExamples.py
0 → 100644
View file @
8c838c71
# ===========================================================================
# Copyright 2014 Nexedi SA
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
from
unittest
import
TestCase
class
SimulationExamples
(
TestCase
):
"""
Test topology files. The simulation is launched with files Topology01.json,
Topology02.json, etc, and every time we look if the result is like we expect.
If the result format or content change, it is required to dump again all
result files. But this is easy to do :
dump=1 python setup.py test
This will regenerate all dump files in dream/tests/dump/.
Then you can check carefully if all outputs are correct. You could use git
diff to check what is different. Once you are sure that your new dumps are
correct, you could commit, your new dumps will be used as new reference.
"""
def
testTwoServers
(
self
):
from
dream.simulation.Examples.TwoServers
import
main
result
=
main
()
self
.
assertEquals
(
result
[
'parts'
],
732
)
self
.
assertTrue
(
78
<
result
[
"blockage_ratio"
]
<
79
)
self
.
assertTrue
(
26
<
result
[
"working_ratio"
]
<
27
)
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