@startuml
participant Participant as Foo
actor Actor as Foo1
boundary Boundary as Foo2
control Control as Foo3
entity Entity as Foo4
database Database as Foo5
collections Collections as Foo6
queue Queue as Foo7
Foo -> Foo1 : To actor
Foo -> Foo2 : To boundary
Foo -> Foo3 : To control
Foo -> Foo4 : To entity
Foo -> Foo5 : To database
Foo -> Foo6 : To collections
Foo -> Foo7: To queue
Foo <-- Foo7: Response from queue
@enduml
@startuml
start
repeat
:Test something;
if (Something went wrong?) then (no)
#palegreen:OK;
break
endif
->NOK;
:Alert "Error with long text";
repeat while (Something went wrong with long text?) is (yes) not (no)
->//merged step//;
:Alert "Success";
stop
@enduml
# 运行下面代码前,确保依赖已安装# pip3 install matplotlib --userimportmath,randomimportmatplotlib.pyplotaspltplt.xkcd()classLocation(object):def__init__(self,x,y):self.x=float(x)self.y=float(y)defmove(self,xc,yc):returnLocation(self.x+float(xc),self.y+float(yc))defgetCoords(self):returnself.x,self.ydefgetDist(self,other):ox,oy=other.getCoords()xDist=self.x-oxyDist=self.y-oyreturnmath.sqrt(xDist**2+yDist**2)classCompassPt(object):possibles=('N','S','E','W')def__init__(self,pt):ifptinself.possibles:self.pt=ptelse:raiseValueError("in CompassPt.__init__")defmove(self,dist):ifself.pt=="N":return(0,dist)elifself.pt=="S":return(0,-dist)elifself.pt=="E":return(dist,0)elifself.pt=="W":return(-dist,0)else:raiseValueError("in CompassPt.move")classField(object):def__init__(self,drunk,loc):self.drunk=drunkself.loc=locdefmove(self,cp,dist):oldLoc=self.locxc,yc=cp.move(dist)self.loc=oldLoc.move(xc,yc)defgetLoc(self):returnself.locdefgetDrunk(self):returnself.drunkclassDrunk(object):def__init__(self,name):self.name=namedefmove(self,field,time=1):iffield.getDrunk()!=self:raiseValueError("Drunk.move called with drunk not in field")foriinrange(time):pt=CompassPt(random.choice(CompassPt.possibles))field.move(pt,1)defperformTrial(time,f):start=f.getLoc()distances=[0.0]fortinrange(1,time+1):f.getDrunk().move(f)newLoc=f.getLoc()distance=newLoc.getDist(start)distances.append(distance)returndistancesdeffirstTest():drunk=Drunk("Homser Simpson")foriinrange(5):f=Field(drunk,Location(0,0))distances=performTrial(500,f)plt.plot(distances)plt.title("Homer's random Walk")plt.xlabel("Time")plt.ylabel("Distance from origin")fname="images/mit6.00/simulation_random_walk_trail1.png"plt.savefig(fname)returnfnamereturnfirstTest()