Home | Trees | Indices | Help |
---|
|
1 """ 2 Algorithm Test Suite 3 4 Tests algorithms defined in algs.py 5 """ 6 7 try: 8 from datk.core.distalgs import * 9 from datk.core.networks import * 10 from datk.core.algs import * 11 from datk.core.tester import * 12 except ImportError: 13 raise ImportError( 14 """ Imports failed\n 15 To run tests, execute the following commands: 16 $ cd ../.. 17 $ python -m datk.tests.tests """) 18 from helpers import *21 """ 22 Convenient helper function to determine if environment is IPython. 23 24 Sets matplotlib inline, if indeed in IPython 25 Note that drawing is only safe in IPython qtconsole with matplotlib inline 26 27 @return: True iff environment is IPython 28 """ 29 try: 30 __IPYTHON__ 31 ip = get_ipython() 32 ip.magic("%matplotlib inline") 33 except NameError: 34 return False 35 else: 36 return True37 38 in_ipython = configure_ipython() 39 40 Algorithm.DEFAULT_PARAMS = {"draw":False, "verbosity" : Algorithm.QUIET} 47 53 59 65 71 77 83 89 9598 x = Random_Line_Network(10) 99 FloodMax(x) 100 testLeaderElection(x) 101 102 SynchBFS(x) 103 testBFS(x)104107 x = Bidirectional_Line(6, lambda t:t) 108 109 FloodMax(x) 110 testLeaderElection(x) 111 112 SynchBFSAck(x) 113 testBFSWithChildren(x)114117 x = Random_Line_Network(10) 118 119 FloodMax(x) 120 testLeaderElection(x) 121 122 SynchBFS(x) 123 testBFS(x) 124 125 SynchConvergeHeight(x)126129 x = Random_Line_Network(10) 130 131 FloodMax(x) 132 testLeaderElection(x) 133 134 SynchBFSAck(x) 135 testBFSWithChildren(x) 136 137 SynchConvergeHeight(x) 138 139 SynchBroadcast(x, {"attr":"height", "draw":in_ipython, "verbosity" : Algorithm.QUIET}) 140 testBroadcast(x, 'height')141144 x = Random_Line_Network(10) 145 146 FloodMax(x) 147 testLeaderElection(x) 148 149 SynchBFSAck(x) 150 testBFSWithChildren(x) 151 152 AsynchConvergeHeight(x) 153 154 SynchBroadcast(x, {"attr":"height", "draw":in_ipython, "verbosity" : Algorithm.QUIET}) 155 testBroadcast(x, 'height')156159 A = LCR() 160 a1 = Message(A) 161 a2 = Message(A) 162 a3 = Message(A) 163 164 B = LCR() 165 b1 = Message(B) 166 b2 = Message(B) 167 168 x = Bidirectional_Ring(4, lambda p:p) 169 assert x[0].get_msgs(A) == [] 170 x[0].send_msg(a1) 171 x[0].send_msg(a2) 172 assert a1.author == x[0] and a2.author == x[0] 173 x[2].send_msg(a3) 174 assert a3.author == x[2] 175 x[0].send_msg(b1) 176 assert b1.author == x[0] 177 x[2].send_msg(b2) 178 assert b2.author == x[2] 179 180 assert x[1].get_msgs(B) == [b1,b2] 181 assert x[1].get_msgs(A, x[0]) == [a1, a2] 182 assert x[1].get_msgs(A, x[0]) == [] 183 assert x[1].get_msgs(A) == [a3] 184 assert x[1].get_msgs(A) == []185188 x = Random_Line_Network(5) 189 state = x.state() 190 assert Do_Nothing(x).message_count == 0 191 assert state == x.state()192195 x = Unidirectional_Ring(5) 196 x1 = x.clone() 197 198 A = LCR() 199 A(x) 200 testLeaderElection(x) 201 202 C = Compose(LCR(), Do_Nothing()) 203 C(x1) 204 testLeaderElection(x1) 205 206 assert C.message_count == A.message_count, "Wrong message count"207210 x = Unidirectional_Ring(10) 211 x1 = x.clone() 212 x2 = x.clone() 213 214 A = LCR() 215 A(x) 216 testLeaderElection(x) 217 218 B = Compose(LCR(name="B1"), LCR(name="B2")) 219 B(x1) 220 testLeaderElection(x1) 221 222 C = Compose(Compose(LCR(), LCR()), LCR()) 223 C(x2) 224 testLeaderElection(x2) 225 226 assert B.message_count == 2*A.message_count, "Compose LCR LCR wrong message count" 227 assert C.message_count == 3*A.message_count, "Compose LCR LCR LCR wrong message count"228231 fm = FloodMax() 232 bfs = SynchBFSAck() 233 converge = SynchConvergeHeight() 234 broadcast = SynchBroadcast(params ={"attr":"height"}) 235 236 A = Chain(Chain(fm, bfs), Chain(converge, broadcast)) 237 x = Random_Line_Network(10) 238 A(x) 239 testLeaderElection(x) 240 testBFSWithChildren(x) 241 testBroadcast(x, 'height')242 248 254 255 summarize() 256
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Sat Dec 19 01:14:00 2015 | http://epydoc.sourceforge.net |