Commit 8c838c71 authored by Sebastien Robin's avatar Sebastien Robin

unit test: show how to test examples (first test of TwoServers.py)

parent 71b8c72e
......@@ -45,34 +45,43 @@ M2.defineRouting([Q],[E])
E.defineRouting([M2])
initialize() #initialize the simulation (SimPy method)
#initialize all the objects
#initialize all the objects
R.initialize()
for object in G.ObjList:
object.initialize()
for objectInterruption in G.ObjectInterruptionList:
objectInterruption.initialize()
def main():
for object in G.ObjList:
object.initialize()
for objectInterruption in G.ObjectInterruptionList:
objectInterruption.initialize()
#activate all the objects
for object in G.ObjList:
activate(object, object.run())
#activate all the objects
for object in G.ObjList:
activate(object, object.run())
for objectInterruption in G.ObjectInterruptionList:
activate(objectInterruption, objectInterruption.run())
for objectInterruption in G.ObjectInterruptionList:
activate(objectInterruption, objectInterruption.run())
G.maxSimTime=1440.0 #set G.maxSimTime 1440.0 minutes (1 day)
simulate(until=G.maxSimTime) #run the simulation
G.maxSimTime=1440.0 #set G.maxSimTime 1440.0 minutes (1 day)
simulate(until=G.maxSimTime) #run the simulation
#carry on the post processing operations for every object in the topology
for object in G.ObjList:
object.postProcessing()
R.postProcessing()
#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"
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}
#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, "%"
if __name__ == '__main__':
main()
# ===========================================================================
# 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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment