How to use addSigma method in fMBT

Best Python code snippet using fMBT_python

relax2.py

Source:relax2.py Github

copy

Full Screen

...32 def __init__(self,L=None):33 self.Sigma = []34 self.dist = {}35 if L:36 self.addSigma(L.get_actionnames())37 self.addtrans(L.get_transitions())38 self.addprops(L.get_stateprops())39 def addtrans(self,tr): 40 self.Trans = []41 for i,tl in enumerate(tr):42 self.Trans.append({})43 for (dest,act) in tl:44 if not act in self.Trans[i]:45 self.Trans[i][act] =set([dest])46 else:47 self.Trans[i][act].add(dest) 48 def addprops(self,pr):49 self.acc = set([])50 if 'acc' in pr:51 self.acc.update(pr['acc'])52 def addSigma(self,Sigma):53 if self.Sigma:54 toadd = set(Sigma)55 toadd.difference_update(self.Sigma)56 self.Sigma.extend(list(toadd))57 else:58 self.Sigma = Sigma59 """ Relax is dangerous, unless the DFA is a60 linear execution, as it may run forever.61 Did not bother to implement any weird stuff"""62 def relax(self,s=None,act = None):63 if s in self.acc:64 return set([]) ## nothing is added from accepting states.65 elif not s:66 s = 067 toadd = set([])68 for a in self.Trans[s]:69 for sp in self.Trans[s][a]:70 toadd.update(self.relax(sp,a))71 toadd.add((sp,a))72 for (sp,a) in toadd:73 if a not in self.Trans[s]:74 self.Trans[s][a] = set([])75 self.Trans[s][a].add(sp)76 return toadd77 """ Returns an LSTS """78 def to_LSTS(self,stream):79 out = lsts.writer(stream)80 out.set_transitions([[(dest,act) for act in s81 for dest in s[act]] for s in self.Trans])82 out.set_actionnames(self.Sigma)83 prop = {'acc':[i for i in self.acc]}84 for st in self.dist:85 nprop = str(self.dist[st])86 if not nprop in prop:87 prop[nprop] = []88 prop[nprop].append(st)89 out.set_stateprops(prop)90 return out91 """ makes self a full DFA. Again, not safe for92 nondeterministic automaton """93 def t_full(self):94 rej = False95 for t in self.Trans:96 for i in xrange(1,len(self.Sigma)):97 if i in t:continue98 if not rej:99 rej = len(self.Trans)100 self.Trans.append({})101 t[i] =set([rej])102 if rej:103 for i in xrange(1,len(self.Sigma)):104 self.Trans[-1][i] = set([rej])105 """cln removes states and trans that cannot reach acc-states."""106 def cln(self):107 revT = [{} for s in self.Trans]108 for s in xrange(len(self.Trans)):109 for a in self.Trans[s]:110 for sp in self.Trans[s][a]:111 if not a in revT[sp]:112 revT[sp][a] = set([])113 revT[sp][a].add(s)114 tag = self.acc.copy()115 Q = list(tag)116 while Q:117 s = Q.pop(0)118 for a in revT[s]:119 for sp in revT[s][a]:120 if sp in tag:continue121 tag.add(sp)122 Q.append(sp) 123 for s in xrange(len(self.Trans)):124 torem = set([])125 for a in self.Trans[s]:126 togo = set([])127 for sp in self.Trans[s][a]:128 if not sp in tag:129 togo.add(sp)130 self.Trans[s][a].difference_update(togo)131 if not self.Trans[s][a]:132 torem.add(a)133 for a in torem:134 self.Trans[s].pop(a)135 """ unreach removes all unreachable states """136 def unreach(self):137 newstates = {0:0}138 trel = [{}]139 cnum = 0140 stack = [0]141 while stack:142 s = stack.pop()143 for a in self.Trans[s]:144 for sp in self.Trans[s][a]:145 if not sp in newstates:146 cnum+=1147 newstates[sp] = cnum148 trel.append({})149 stack.append(sp)150 if not a in trel[newstates[s]]:151 trel[newstates[s]][a] = set([])152 trel[newstates[s]][a].add(newstates[sp])153 acc = set([])154 for s in self.acc:155 if s in newstates:156 acc.add(newstates[s])157 self.acc = acc158 self.Trans = trel159 """ backwards, backwadizes """160 def backwards(self):161 trans = [{} for i in xrange(len(self.Trans)+1)]162 for s,t in enumerate(self.Trans):163 for a in self.Trans[s]:164 for sp in self.Trans[s][a]:165 if not a in trans[sp+1]:166 trans[sp+1][a] = set([])167 trans[sp+1][a].add(s+1)168 trans[0][0] = set([s+1 for s in self.acc])169 self.Trans = trans170 self.acc = set([1])171 172 173 174 """ Min minimizes. Warning: bad and silly.175 It is correct, however. """176 def min(self):177 self.backwards()178 self.remove_taus()179 self.det()180 self.cln()181 self.unreach()182 self.backwards()183 self.remove_taus()184 self.det()185 self.cln()186 self.unreach()187 """ helper method remove_taus removes taus and replaces with188 regular nondeteminism """189 def remove_taus(self):190 init = 0191 foundstates = set([init])192 stack = [init]193 while stack:194 s = stack.pop()195 found2 = set([s])196 stack2 = [s]197 while stack2:198 s2 = stack2.pop()199 if not 0 in self.Trans[s2]:continue200 for s2p in self.Trans[s2][0]:201 if not s2p in found2:202 stack2.append(s2p)203 found2.add(s2p)204 for a in self.Trans[s2p]:205 if a == 0:continue206 if not a in self.Trans[s]:207 self.Trans[s][a] = set([]) 208 self.Trans[s][a].update(self.Trans[s2p][a])209 210 for a in self.Trans[s]:211 if a == 0:212 self.Trans[s][a] = set([])213 continue214 for sp in self.Trans[s][a]:215 if sp in foundstates:continue216 foundstates.add(sp)217 stack.append(sp) 218 """ makes current deterministic.219 warning: may be exponential """220 def det(self):221 init = (0,)222 newstates = {init:0}223 cnum = 0224 stack = [init]225 trel = [{}]226 acc = set([])227 while stack:228 ss = stack.pop()229 for a in xrange(len(self.Sigma)):230 news = set([])231 ac = False232 for s in ss:233 if a in self.Trans[s]: 234 for sp in self.Trans[s][a]:235 news.add(sp)236 if sp in self.acc:237 ac = True238 news = list(news)239 news.sort()240 news = tuple(news)241 if not news in newstates:242 cnum +=1243 newstates[news] = cnum244 trel.append({})245 stack.append(news)246 spp = newstates[news] 247 trel[newstates[ss]][a] = set([spp])248 if ac:acc.add(spp)249 self.Trans = trel250 self.acc = acc251 """ union adds D2, and this is the nondet-252 non-interleaving version """253 def union(self,D2):254 self.addSigma(D2.Sigma)255 cnum = len(self.Trans)256 newstates = {0:0}257 for s in xrange(len(D2.Trans)):258 for a in D2.Sigma:259 ai = D2.Sigma.index(a)260 ni = self.Sigma.index(a)261 if not ai in D2.Trans[s]: continue262 for sp in D2.Trans[s][ai]:263 if not sp in newstates:264 self.Trans.append({})265 newstates[sp] = cnum266 cnum+=1267 ss = newstates[s]268 ssp = newstates[sp]269 if sp in D2.acc:270 self.acc.add(ssp)271 if not ni in self.Trans[ss]:272 self.Trans[ss][ni] = set([])273 self.Trans[ss][ni].add(ssp)274 275 """ 'add' adds another trace to current 276 and returns a new DFA. Safe only for det.277 Interleaves them completely """278 def add(self,D2):279 stnumbering = {(0,0):0} # store for the states280 cnumber = 0 # number for the states new DFA281 acc = set([]) # acc-set for the new DFA282 trans = [{}] # transrel for the new. sigma is union.283 stack = [(0,0)] # going in "pseudoDFS"284 Sg1 = self.Sigma285 Sg2 = D2.Sigma286 Sigma = set(Sg1).union(Sg2) # union of alphabets287 Sigma.remove('tau')288 SL = ['tau']289 SL.extend(list(Sigma))290 while stack:291 (x,y) = stack.pop()292 st = stnumbering[(x,y)] 293 if x in self.acc or y in D2.acc: # union294 acc.add(st)295 for a in Sigma:296 ai = SL.index(a)297 if a in Sg1 and a in Sg2: # this is in joint alp.298 i = self.Sigma.index(a)299 j = D2.Sigma.index(a)300 if x == None or not i in self.Trans[x]:301 Xp = [None]302 else:303 Xp = self.Trans[x][i]304 if y == None or not j in D2.Trans[y]:305 Yp = [None]306 else:307 Yp = D2.Trans[y][j]308 succ = [(xp,yp) for xp in Xp for yp in Yp]309 for xp,yp in succ:310 if not (xp,yp) in stnumbering:311 cnumber += 1312 stnumbering[(xp,yp)] = cnumber313 stack.append((xp,yp))314 trans.append({})315 stp = stnumbering[(xp,yp)]316 if not ai in trans[st]:317 trans[st][ai] = set([])318 trans[st][ai].add(stp)319 elif a in Sg1:320 i = self.Sigma.index(a)321 if x==None or not i in self.Trans[x]: continue322 for xp in self.Trans[x][i]:323 if not (xp,y) in stnumbering:324 cnumber += 1325 stnumbering[(xp,y)] = cnumber326 stack.append((xp,y))327 trans.append({})328 stp = stnumbering[(xp,y)]329 if not ai in trans[st]:330 trans[st][ai] = set([])331 trans[st][ai].add(stp)332 elif a in Sg2:333 j = D2.Sigma.index(a)334 if y==None or not j in D2.Trans[y]: continue335 for yp in D2.Trans[y][j]:336 if not (x,yp) in stnumbering:337 cnumber += 1338 stnumbering[(x,yp)] = cnumber339 stack.append((x,yp))340 trans.append({})341 stp = stnumbering[(x,yp)]342 if not ai in trans[st]:343 trans[st][ai] = set([])344 trans[st][ai].add(stp)345 rr = DFA_lsts()346 rr.Trans = trans347 rr.addSigma(SL)348 rr.acc = acc349 return rr350 351 352 """ Intersection calculates the common language. works only353 for det and makes sense only for relaxed versions """354 def intersect(self,D2):355 D2.t_full()356 self.t_full()357 stnumbering = {(0,0):0} # store for the states358 cnumber = 0 # number for the states new DFA359 acc = set([]) # acc-set for the new DFA360 trans = [{}] # transrel for the new. sigma is union.361 stack = [(0,0)] # going in "pseudoDFS"362 Sg1 = set(self.Sigma)363 Sg2 = set(D2.Sigma)364 SigmaU = Sg1.union(Sg2) # union of alphabets365 SigmaU.remove('tau') # We don't consider them.366 SigmaI = Sg1.intersection(Sg2)367 SigmaI.remove('tau')368 SL = ['tau']369 SL.extend(list(SigmaI))370 while stack:371 (x,y) = stack.pop()372 st = stnumbering[(x,y)] 373 if x in self.acc and y in D2.acc: # union374 acc.add(st)375 for a in SigmaU: #NOTE it dismisses taus. 376 if a in SigmaI: # this is in joint alp.377 ai = SL.index(a)378 i = self.Sigma.index(a)379 j = D2.Sigma.index(a)380 for xp in self.Trans[x][i]:381 for yp in D2.Trans[y][j]:382 if not (xp,yp) in stnumbering:383 cnumber += 1384 stnumbering[(xp,yp)] = cnumber385 stack.append((xp,yp))386 trans.append({})387 stp = stnumbering[(xp,yp)]388 if not ai in trans[st]:389 trans[st][ai] = set([])390 trans[st][ai].add(stp)391 elif a in Sg1: # here only if in Sg1,not sg2392 ai = 0 # Noncommon alphabets are replaced by 0393 i = self.Sigma.index(a)394 for xp in self.Trans[x][i]:395 if not (xp,y) in stnumbering:396 cnumber += 1397 stnumbering[(xp,y)] = cnumber398 stack.append((xp,y))399 trans.append({})400 stp = stnumbering[(xp,y)]401 if not ai in trans[st]:402 trans[st][ai] = set([])403 trans[st][ai].add(stp)404 elif a in Sg2:405 ai = 0406 j = D2.Sigma.index(a)407 for yp in D2.Trans[y][j]:408 if not (x,yp) in stnumbering:409 cnumber += 1410 stnumbering[(x,yp)] = cnumber411 stack.append((x,yp))412 trans.append({})413 stp = stnumbering[(x,yp)]414 if not ai in trans[st]:415 trans[st][ai] = set([])416 trans[st][ai].add(stp)417 rr = DFA_lsts()418 rr.Trans = trans419 rr.addSigma(SL)420 rr.acc = acc421 rr.remove_taus()422 rr.det()423 rr.cln()424 rr.unreach()425 return rr426 """ retain remoces all the actions except those in 'act'427 """428 def retain(self,act):429 Sigma = act430 trns = [{} for i in self.Trans]431 for s,t in enumerate(self.Trans):432 for a in self.Sigma:433 i = self.Sigma.index(a)434 if a in act:435 j = Sigma.index(a)436 trns[s][j] = set([])437 if i in t:438 trns[s][j].update(t[i])439 elif i in t:440 if not 0 in trns[s]:441 trns[s][0] = set([])442 trns[s][0].update(t[i])443 self.Trans = trns444 self.Sigma = Sigma445 self.remove_taus()446 self.det()447 self.cln()448 self.unreach()449 450 451 452 """ Negate is a function that takes another dfa,453 and removes from it all accepting traces that454 this one accepts. Result is nondet, in general.455 Not safe otherwise!! """456 def negate(self,D2):457 self.retain(D2.Sigma) 458 if DEBUG: 459 self.to_LSTS(open('foo.lsts','w')).write()460 self.t_full()461 stnumbering = {(0,0):0} # store for the states462 cnumber = 0 # number for the states new DFA463 acc = set([]) # acc-set for the new DFA464 uacc = set([]) # accset of current;used for negating.465 trans = [{}] # transrel for the new. sigma from D2466 stack = [(0,0)] # going in "pseudoDFS"467 while stack:468 (x,y) = stack.pop()469 st = stnumbering[(x,y)]470 if y in D2.acc:471 acc.add(st) # not the final;must be fixed472 if x in self.acc:473 uacc.add(st)474 for a in self.Trans[x]: ## We follow self.475 if self.Sigma[a] in D2.Sigma: # this is in joint alp.476 b = D2.Sigma.index(self.Sigma[a])477 for xp in self.Trans[x][a]:478 if not b in D2.Trans[y]:479 continue480 for yp in D2.Trans[y][b]:481 if not (xp,yp) in stnumbering:482 cnumber += 1483 stnumbering[(xp,yp)] = cnumber484 stack.append((xp,yp))485 trans.append({})486 stp = stnumbering[(xp,yp)]487 if not b in trans[st]:488 trans[st][b] = set([])489 trans[st][b].add(stp)490 else: # Others become taus. 491 for xp in self.Trans[x][a]:492 if not (xp,y) in stnumbering:493 cnumber += 1494 stnumbering[(xp,y)] = cnumber495 stack.append((xp,y))496 trans.append({})497 stp = stnumbering[(xp,y)]498 if not 0 in trans[st]:499 trans[st][0] = set([])500 trans[st][0].add(stp)501 # Now we clean the acc-sets.502 503 acc.difference_update(uacc)504 rr = DFA_lsts()505 rr.Trans = trans506 rr.addSigma(D2.Sigma)507 rr.acc = acc508 rr.remove_taus()509 rr.det()510 return rr511 def addDistances(self):512 ptrans = [{} for st in self.Trans]513 for st in xrange(len(self.Trans)):514 for a in self.Trans[st]:515 for sp in self.Trans[st][a]:516 if not a in ptrans[sp]:517 ptrans[sp][a] = set([])518 ptrans[sp][a].add(st)519 dist = {}520 for st in self.acc:...

Full Screen

Full Screen

urls.py

Source:urls.py Github

copy

Full Screen

1from django.urls import path2from . import views3urlpatterns = [4 path('', views.index, name='index'),5 path('addTechnique/', views.addTechnique, name='addTechnique'),6 path('addSigma/', views.addSigma, name='addSigma'),7 path('technique/<str:pk>', views.individualTechnique, name='individualTechnique'),8 #path('updateNotesPerTech/<str:pk>', views.updateNotesPerTech, name='updateNotesPerTech'),9 #path('elements/', views.index, name='index'),10 #path('sigma_rules/', views.sigma_rules.as_view(), name='sigma_rules'),11 #path('alltactics/', views.alltactics, name='alltactics'),12 #path('tactics/', views.TacticListView.as_view(), name='tactics'),13 #path('tactics/<str:pk>', views.TacticDetailView.as_view(), name='tactic-detail'),14 #path('techniques/', views.TechniqueListView.as_view(), name='techniques'),15 #path('alltechniques/', views.alltechniques, name='alltechniques'),16 #path('techniques/<str:pk>', views.TechniqueDetailView.as_view(), name='technique-detail'),17 #path('allTechPerTactic', views.allTechPerTactic, name="allTechPerTactic"),18 #path('atomics/<str:pk>', views.atomics, name='atomics'),19 #path('notesPerTech/<str:pk>', views.notesPerTech, name='notesPerTech'),20 # These are for notes functions21 path('addnote/<str:pk>', views.addnote, name='note'),22 path('note/<int:pk>', views.NoteDetailView.as_view(), name='note-detail'),23 path('addnote/<str:pk>', views.NoteCreate.as_view(), name='note_create'),24 path('note/<str:pk>/delete/', views.NoteDelete.as_view(), name='note_delete'),25 path('note/<str:pk>/update/', views.NoteUpdate.as_view(), name='note_update'),26 #path('noteCreator/<str:pk>', views.noteCreator, name='noteCreator'),27 #path('note/<str:pk>', views.notesPerTech, name='notesPerTech'),28 #path('note/create/<str:pk>', views.NoteCreate.as_view(), name='note_create'),...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful