How to use throw method in Sure

Best Python code snippet using sure_python

DistributedLawbotBossSuit.py

Source:DistributedLawbotBossSuit.py Github

copy

Full Screen

1from pandac.PandaModules import *2from direct.interval.IntervalGlobal import *3from direct.fsm import ClassicFSM, State4from direct.fsm import State5from direct.directnotify import DirectNotifyGlobal6import DistributedSuitBase7from toontown.toonbase import ToontownGlobals8from toontown.battle import MovieUtil9class DistributedLawbotBossSuit(DistributedSuitBase.DistributedSuitBase):10 notify = DirectNotifyGlobal.directNotify.newCategory('DistributedLawbotBossSuit')11 timeToShow = 1.012 timeToRelease = 3.1513 throwPaperEndTime = 4.3314 def __init__(self, cr):15 self.flyingEvidenceTrack = None16 try:17 self.DistributedSuit_initialized18 except:19 self.DistributedSuit_initialized = 120 DistributedSuitBase.DistributedSuitBase.__init__(self, cr)21 self.activeIntervals = {}22 self.boss = None23 self.fsm = ClassicFSM.ClassicFSM('DistributedLawbotBossSuit', [24 State.State('Off',25 self.enterOff,26 self.exitOff, [27 'Walk',28 'Battle',29 'neutral']),30 State.State('Walk',31 self.enterWalk,32 self.exitWalk, [33 'WaitForBattle',34 'Battle']),35 State.State('Battle',36 self.enterBattle,37 self.exitBattle, []),38 State.State('neutral',39 self.enterNeutral,40 self.exitNeutral, [41 'PreThrowProsecute',42 'PreThrowAttack',43 'Stunned']),44 State.State('PreThrowProsecute',45 self.enterPreThrowProsecute,46 self.exitPreThrowProsecute,47 ['PostThrowProsecute',48 'neutral',49 'Stunned']),50 State.State('PostThrowProsecute',51 self.enterPostThrowProsecute,52 self.exitPostThrowProsecute, [53 'neutral',54 'Stunned']),55 State.State('PreThrowAttack',56 self.enterPreThrowAttack,57 self.exitPreThrowAttack, [58 'PostThrowAttack',59 'neutral',60 'Stunned']),61 State.State('PostThrowAttack',62 self.enterPostThrowAttack,63 self.exitPostThrowAttack, [64 'neutral',65 'Stunned']),66 State.State('Stunned',67 self.enterStunned,68 self.exitStunned, [69 'neutral']),70 State.State('WaitForBattle',71 self.enterWaitForBattle,72 self.exitWaitForBattle, [73 'Battle'])],74 'Off', 'Off')75 self.fsm.enterInitialState()76 return77 def generate(self):78 self.notify.debug('DLBS.generate:')79 DistributedSuitBase.DistributedSuitBase.generate(self)80 def announceGenerate(self):81 DistributedSuitBase.DistributedSuitBase.announceGenerate(self)82 self.notify.debug('DLBS.announceGenerate')83 colNode = self.find('**/distAvatarCollNode*')84 colNode.setTag('pieCode', str(ToontownGlobals.PieCodeLawyer))85 self.attackEvidenceA = self.getEvidence(True)86 self.attackEvidenceB = self.getEvidence(True)87 self.attackEvidence = self.attackEvidenceA88 self.prosecuteEvidence = self.getEvidence(False)89 self.hideName()90 self.setPickable(False)91 def disable(self):92 self.notify.debug('DistributedSuit %d: disabling' % self.getDoId())93 self.setState('Off')94 DistributedSuitBase.DistributedSuitBase.disable(self)95 self.cleanupIntervals()96 self.boss = None97 return98 def delete(self):99 try:100 self.DistributedSuit_deleted101 except:102 self.DistributedSuit_deleted = 1103 self.notify.debug('DistributedSuit %d: deleting' % self.getDoId())104 del self.fsm105 DistributedSuitBase.DistributedSuitBase.delete(self)106 def d_requestBattle(self, pos, hpr):107 self.cr.playGame.getPlace().setState('WaitForBattle')108 self.sendUpdate('requestBattle', [pos[0],109 pos[1],110 pos[2],111 hpr[0],112 hpr[1],113 hpr[2]])114 return None115 def __handleToonCollision(self, collEntry):116 toonId = base.localAvatar.getDoId()117 self.notify.debug('Distributed suit: requesting a Battle with ' + 'toon: %d' % toonId)118 self.d_requestBattle(self.getPos(), self.getHpr())119 self.setState('WaitForBattle')120 return None121 def enterWalk(self):122 self.notify.debug('enterWalk')123 self.enableBattleDetect('walk', self.__handleToonCollision)124 self.loop('walk', 0)125 pathPoints = [Vec3(50, 15, 0),126 Vec3(50, 25, 0),127 Vec3(20, 25, 0),128 Vec3(20, 15, 0),129 Vec3(50, 15, 0)]130 self.tutWalkTrack = self.makePathTrack(self, pathPoints, 4.5, 'tutFlunkyWalk')131 self.tutWalkTrack.loop()132 def exitWalk(self):133 self.notify.debug('exitWalk')134 self.disableBattleDetect()135 self.tutWalkTrack.pause()136 self.tutWalkTrack = None137 return138 def enterNeutral(self):139 self.notify.debug('enterNeutral')140 self.notify.debug('DistributedLawbotBossSuit: Neutral')141 self.loop('neutral', 0)142 def exitNeutral(self):143 self.notify.debug('exitNeutral')144 def doAttack(self, x1, y1, z1, x2, y2, z2):145 self.notify.debug('x1=%.2f y1=%.2f z2=%.2f x2=%.2f y2=%.2f z2=%.2f' % (x1,146 y1,147 z1,148 x2,149 y2,150 z2))151 self.curTargetPt = Point3(x2, y2, z2)152 self.fsm.request('PreThrowAttack')153 return154 attackEvidence = self.getEvidence(True)155 nodePath = render156 node = nodePath.attachNewNode('attackEvidence-%s' % self.doId)157 node.setPos(x1, y1, z1)158 duration = 3.0159 throwName = self.uniqueName('lawyerAttack')160 throwingSeq = self.makeAttackThrowingTrack(attackEvidence, duration, Point3(x2, y2, z2))161 fullSequence = Sequence(throwingSeq, name=throwName)162 self.activeIntervals[throwName] = fullSequence163 fullSequence.start()164 def doProsecute(self):165 self.notify.debug('doProsecute')166 bounds = self.boss.prosecutionColNodePath.getBounds()167 panCenter = bounds.getCenter()168 localPos = panCenter169 prosecutionPanPos = render.getRelativePoint(self.boss.prosecutionColNodePath, localPos)170 self.curTargetPt = prosecutionPanPos171 self.fsm.request('PreThrowProsecute')172 return173 attackEvidence = self.getEvidence(False)174 nodePath = render175 node = nodePath.attachNewNode('prosecuteEvidence-%s' % self.doId)176 node.setPos(self.getPos())177 duration = ToontownGlobals.LawbotBossLawyerToPanTime178 throwName = self.uniqueName('lawyerProsecute')179 throwingSeq = self.makeProsecuteThrowingTrack(attackEvidence, duration, prosecutionPanPos)180 fullSequence = Sequence(throwingSeq, Func(self.boss.flashGreen), Func(self.clearInterval, throwName), name=throwName)181 self.activeIntervals[throwName] = fullSequence182 fullSequence.start()183 def makeDummySequence(self):184 retval = Sequence(Wait(10))185 return retval186 def makeProsecuteThrowingTrack(self, evidence, inFlightDuration, hitPos):187 suitTrack = Sequence()188 suitTrack.append(ActorInterval(self, 'throw-paper'))189 throwPaperDuration = suitTrack.getDuration()190 inFlight = Parallel(evidence.posInterval(inFlightDuration, hitPos, fluid=1))191 origHpr = self.getHpr()192 self.headsUp(hitPos)193 newHpr = self.getHpr()194 self.setHpr(origHpr)195 rotateTrack = Sequence(self.hprInterval(self.timeToShow, newHpr, fluid=1))196 propTrack = Sequence(Func(evidence.hide), Func(evidence.setPos, 0, 0.5, -0.3), Func(evidence.reparentTo, self.getRightHand()), Wait(self.timeToShow), Func(evidence.show), Wait(self.timeToRelease - self.timeToShow), Func(evidence.wrtReparentTo, render), Func(self.makeDummySequence), inFlight, Func(evidence.detachNode))197 throwingTrack = Parallel(suitTrack, propTrack, rotateTrack)198 return throwingTrack199 def makeAttackThrowingTrack(self, evidence, inFlightDuration, hitPos):200 suitTrack = Sequence()201 suitTrack.append(ActorInterval(self, 'throw-paper'))202 throwPaperDuration = suitTrack.getDuration()203 origHpr = self.getHpr()204 self.headsUp(hitPos)205 newHpr = self.getHpr()206 self.setHpr(origHpr)207 rotateTrack = Sequence(self.hprInterval(self.timeToShow, newHpr, fluid=1))208 propTrack = Sequence(Func(evidence.hide), Func(evidence.setPos, 0, 0.5, -0.3), Func(evidence.reparentTo, self.getRightHand()), Wait(self.timeToShow), Func(evidence.show), Wait(self.timeToRelease - self.timeToShow), Func(evidence.wrtReparentTo, render), Func(evidence.setZ, 1.3), evidence.posInterval(inFlightDuration, hitPos, fluid=1), Func(evidence.detachNode))209 throwingTrack = Parallel(suitTrack, propTrack, rotateTrack)210 return throwingTrack211 def makePreThrowAttackTrack(self, evidence, inFlightDuration, hitPos):212 suitTrack = Sequence()213 suitTrack.append(ActorInterval(self, 'throw-paper', endTime=self.timeToRelease))214 throwPaperDuration = suitTrack.getDuration()215 origHpr = self.getHpr()216 self.headsUp(hitPos)217 newHpr = self.getHpr()218 self.setHpr(origHpr)219 rotateTrack = Sequence(self.hprInterval(self.timeToShow, newHpr, fluid=1))220 propTrack = Sequence(Func(evidence.hide), Func(evidence.setPos, 0, 0.5, -0.3), Func(evidence.setScale, 1), Func(evidence.setHpr, 0, 0, 0), Func(evidence.reparentTo, self.getRightHand()), Wait(self.timeToShow), Func(evidence.show), Wait(self.timeToRelease - self.timeToShow))221 throwingTrack = Parallel(suitTrack, propTrack, rotateTrack)222 return throwingTrack223 def makePostThrowAttackTrack(self, evidence, inFlightDuration, hitPos):224 suitTrack = Sequence()225 suitTrack.append(ActorInterval(self, 'throw-paper', startTime=self.timeToRelease))226 propTrack = Sequence(Func(evidence.wrtReparentTo, render), Func(evidence.setScale, 1), Func(evidence.show), Func(evidence.setZ, 1.3), evidence.posInterval(inFlightDuration, hitPos, fluid=1), Func(evidence.hide))227 return (suitTrack, propTrack)228 def makePreThrowProsecuteTrack(self, evidence, inFlightDuration, hitPos):229 return self.makePreThrowAttackTrack(evidence, inFlightDuration, hitPos)230 def makePostThrowProsecuteTrack(self, evidence, inFlightDuration, hitPos):231 suitTrack = Sequence()232 suitTrack.append(ActorInterval(self, 'throw-paper', startTime=self.timeToRelease))233 propTrack = Sequence(Func(evidence.wrtReparentTo, render), Func(evidence.setScale, 1), Func(evidence.show), evidence.posInterval(inFlightDuration, hitPos, fluid=1), Func(evidence.hide))234 return (suitTrack, propTrack)235 def getEvidence(self, usedForAttack = False):236 model = loader.loadModel('phase_5/models/props/lawbook')237 if usedForAttack:238 bounds = model.getBounds()239 center = bounds.getCenter()240 radius = bounds.getRadius()241 sphere = CollisionSphere(center.getX(), center.getY(), center.getZ(), radius)242 colNode = CollisionNode('BossZap')243 colNode.setTag('attackCode', str(ToontownGlobals.BossCogLawyerAttack))244 colNode.addSolid(sphere)245 model.attachNewNode(colNode)246 model.setTransparency(1)247 model.setAlphaScale(0.5)248 return model249 def cleanupIntervals(self):250 for interval in self.activeIntervals.values():251 interval.finish()252 self.activeIntervals = {}253 def clearInterval(self, name, finish = 1):254 if name in self.activeIntervals:255 ival = self.activeIntervals[name]256 if finish:257 ival.finish()258 else:259 ival.pause()260 if name in self.activeIntervals:261 del self.activeIntervals[name]262 else:263 self.notify.debug('interval: %s already cleared' % name)264 def setBossCogId(self, bossCogId):265 self.bossCogId = bossCogId266 self.boss = base.cr.doId2do[bossCogId]267 def doStun(self):268 self.notify.debug('doStun')269 self.fsm.request('Stunned')270 def enterPreThrowProsecute(self):271 duration = ToontownGlobals.LawbotBossLawyerToPanTime272 throwName = self.uniqueName('preThrowProsecute')273 preThrowTrack = self.makePreThrowProsecuteTrack(self.prosecuteEvidence, duration, self.curTargetPt)274 fullSequence = Sequence(preThrowTrack, Func(self.requestStateIfNotInFlux, 'PostThrowProsecute'), name=throwName)275 self.activeIntervals[throwName] = fullSequence276 fullSequence.start()277 def exitPreThrowProsecute(self):278 throwName = self.uniqueName('preThrowProsecute')279 if throwName in self.activeIntervals:280 self.activeIntervals[throwName].pause()281 del self.activeIntervals[throwName]282 def enterPostThrowProsecute(self):283 duration = ToontownGlobals.LawbotBossLawyerToPanTime284 throwName = self.uniqueName('postThrowProsecute')285 postThrowTrack, self.flyingEvidenceTrack = self.makePostThrowProsecuteTrack(self.prosecuteEvidence, duration, self.curTargetPt)286 fullSequence = Sequence(postThrowTrack, Func(self.requestStateIfNotInFlux, 'neutral'), name=throwName)287 self.activeIntervals[throwName] = fullSequence288 fullSequence.start()289 flyName = self.uniqueName('flyingEvidence')290 self.activeIntervals[flyName] = self.flyingEvidenceTrack291 self.flyingEvidenceTrack.append(Func(self.finishedWithFlying, 'prosecute'))292 self.flyingEvidenceTrack.start()293 def exitPostThrowProsecute(self):294 throwName = self.uniqueName('postThrowProsecute')295 if throwName in self.activeIntervals:296 self.activeIntervals[throwName].finish()297 del self.activeIntervals[throwName]298 def requestStateIfNotInFlux(self, state):299 if not self.fsm._ClassicFSM__internalStateInFlux:300 self.fsm.request(state)301 def enterPreThrowAttack(self):302 if self.attackEvidence == self.attackEvidenceA:303 self.attackEvidence = self.attackEvidenceB304 else:305 self.attackEvidence = self.attackEvidenceA306 duration = 3.0307 throwName = self.uniqueName('preThrowAttack')308 preThrowTrack = self.makePreThrowAttackTrack(self.attackEvidence, duration, self.curTargetPt)309 fullSequence = Sequence(preThrowTrack, Func(self.requestStateIfNotInFlux, 'PostThrowAttack'), name=throwName)310 self.activeIntervals[throwName] = fullSequence311 fullSequence.start()312 def exitPreThrowAttack(self):313 throwName = self.uniqueName('preThrowAttack')314 if throwName in self.activeIntervals:315 self.activeIntervals[throwName].pause()316 del self.activeIntervals[throwName]317 def enterPostThrowAttack(self):318 duration = 3.0319 throwName = self.uniqueName('postThrowAttack')320 postThrowTrack, self.flyingEvidenceTrack = self.makePostThrowAttackTrack(self.attackEvidence, duration, self.curTargetPt)321 fullSequence = Sequence(postThrowTrack, Func(self.requestStateIfNotInFlux, 'neutral'), name=throwName)322 self.notify.debug('duration of postThrowAttack = %f' % fullSequence.getDuration())323 self.activeIntervals[throwName] = fullSequence324 fullSequence.start()325 flyName = self.uniqueName('flyingEvidence')326 self.activeIntervals[flyName] = self.flyingEvidenceTrack327 self.flyingEvidenceTrack.append(Func(self.finishedWithFlying, 'attack'))328 self.flyingEvidenceTrack.start()329 def finishedWithFlying(self, str):330 self.notify.debug('finished flyingEvidenceTrack %s' % str)331 def exitPostThrowAttack(self):332 throwName = self.uniqueName('postThrowAttack')333 if throwName in self.activeIntervals:334 self.activeIntervals[throwName].finish()335 del self.activeIntervals[throwName]336 def enterStunned(self):337 stunSequence = MovieUtil.createSuitStunInterval(self, 0, ToontownGlobals.LawbotBossLawyerStunTime)338 seqName = stunSequence.getName()339 stunSequence.append(Func(self.fsm.request, 'neutral'))340 self.activeIntervals[seqName] = stunSequence341 stunSequence.start()342 def exitStunned(self):343 self.prosecuteEvidence.hide()...

Full Screen

Full Screen

CheckSpec.js

Source:CheckSpec.js Github

copy

Full Screen

1defineSuite([2 'Core/Check'3 ], function(4 Check) {5 'use strict';67 describe('type checks', function () {8 it('Check.typeOf.bool does not throw when passed a boolean', function () {9 expect(function () {10 Check.typeOf.bool('bool', true);11 }).not.toThrowDeveloperError();12 });1314 it('Check.typeOf.bool throws when passed a non-boolean', function () {15 expect(function () {16 Check.typeOf.bool('mockName', {});17 }).toThrowDeveloperError();18 expect(function () {19 Check.typeOf.bool('mockName', []);20 }).toThrowDeveloperError();21 expect(function () {22 Check.typeOf.bool('mockName', 1);23 }).toThrowDeveloperError();24 expect(function () {25 Check.typeOf.bool('mockName', 'snth');26 }).toThrowDeveloperError();27 expect(function () {28 Check.typeOf.bool('mockName', function () {return true;});29 }).toThrowDeveloperError();30 });3132 it('Check.typeOf.func does not throw when passed a function', function () {33 expect(function () {34 Check.typeOf.func('mockName', function () {return true;});35 }).not.toThrowDeveloperError();36 });3738 it('Check.typeOf.func throws when passed a non-function', function () {39 expect(function () {40 Check.typeOf.func('mockName', {});41 }).toThrowDeveloperError();42 expect(function () {43 Check.typeOf.func('mockName', [2]);44 }).toThrowDeveloperError();45 expect(function () {46 Check.typeOf.func('mockName', 1);47 }).toThrowDeveloperError();48 expect(function () {49 Check.typeOf.func('mockName', 'snth');50 }).toThrowDeveloperError();51 expect(function () {52 Check.typeOf.func('mockName', true);53 }).toThrowDeveloperError();54 });5556 it('Check.typeOf.object does not throw when passed object', function() {57 expect(function () {58 Check.typeOf.object('mockName', {});59 }).not.toThrowDeveloperError();60 });6162 it('Check.typeOf.object throws when passed non-object', function() {63 expect(function () {64 Check.typeOf.object('mockName', 'snth');65 }).toThrowDeveloperError();66 expect(function () {67 Check.typeOf.object('mockName', true);68 }).toThrowDeveloperError();69 expect(function () {70 Check.typeOf.object('mockName', 1);71 }).toThrowDeveloperError();72 expect(function () {73 Check.typeOf.object('mockName', function () {return true;});74 }).toThrowDeveloperError();75 });7677 it('Check.typeOf.number does not throw when passed number', function() {78 expect(function () {79 Check.typeOf.number('mockName', 2);80 }).not.toThrowDeveloperError();81 });8283 it('Check.typeOf.number throws when passed non-number', function() {84 expect(function () {85 Check.typeOf.number('mockName', 'snth');86 }).toThrowDeveloperError();87 expect(function () {88 Check.typeOf.number('mockName', true);89 }).toThrowDeveloperError();90 expect(function () {91 Check.typeOf.number('mockName', {});92 }).toThrowDeveloperError();93 expect(function () {94 Check.typeOf.number('mockName', [2]);95 }).toThrowDeveloperError();96 expect(function () {97 Check.typeOf.number('mockName', function () {return true;});98 }).toThrowDeveloperError();99 });100101 it('Check.typeOf.string does not throw when passed a string', function () {102 expect(function () {103 Check.typeOf.string('mockName', 's');104 }).not.toThrowDeveloperError();105 });106107 it('Check.typeOf.string throws on non-string', function () {108 expect(function () {109 Check.typeOf.string('mockName', {});110 }).toThrowDeveloperError();111 expect(function () {112 Check.typeOf.string('mockName', true);113 }).toThrowDeveloperError();114 expect(function () {115 Check.typeOf.string('mockName', 1);116 }).toThrowDeveloperError();117 expect(function () {118 Check.typeOf.string('mockName', [2]);119 }).toThrowDeveloperError();120 expect(function () {121 Check.typeOf.string('mockName', function () {return true;});122 }).toThrowDeveloperError();123 });124 });125126 describe('Check.defined', function () {127 it('does not throw unless passed value that is undefined or null', function () {128 expect(function () {129 Check.defined('mockName', {});130 }).not.toThrowDeveloperError();131 expect(function () {132 Check.defined('mockName', []);133 }).not.toThrowDeveloperError();134 expect(function () {135 Check.defined('mockName', 2);136 }).not.toThrowDeveloperError();137 expect(function () {138 Check.defined('mockName', function () {return true;});139 }).not.toThrowDeveloperError();140 expect(function () {141 Check.defined('mockName', 'snt');142 }).not.toThrowDeveloperError();143 });144145 it('throws when passed undefined', function () {146 expect(function () {147 Check.defined('mockName', undefined);148 }).toThrowDeveloperError();149 });150 });151152 describe('Check.typeOf.number.lessThan', function () {153 it('throws if test is equal to limit', function () {154 expect(function () {155 Check.typeOf.number.lessThan('mockName', 3, 3);156 }).toThrowDeveloperError();157 });158159 it('throws if test is greater than limit', function () {160 expect(function () {161 Check.typeOf.number.lessThan('mockName', 4, 3);162 }).toThrowDeveloperError();163 });164165 it('does not throw if test is less than limit', function () {166 expect(function () {167 Check.typeOf.number.lessThan('mockName', 2, 3);168 }).not.toThrowDeveloperError();169 });170 });171172 describe('Check.typeOf.number.lessThanOrEquals', function () {173 it('throws if test is greater than limit', function () {174 expect(function () {175 Check.typeOf.number.lessThanOrEquals('mockName', 4, 3);176 }).toThrowDeveloperError();177 });178179 it('does not throw if test is equal to limit', function () {180 expect(function () {181 Check.typeOf.number.lessThanOrEquals('mockName', 3, 3);182 }).not.toThrowDeveloperError();183 });184185 it('does not throw if test is less than limit', function () {186 expect(function () {187 Check.typeOf.number.lessThanOrEquals('mockName', 2, 3);188 }).not.toThrowDeveloperError();189 });190 });191192 describe('Check.typeOf.number.equals', function () {193 it('throws if either value is not a number', function () {194 expect(function () {195 Check.typeOf.number.equals('mockName1', 'mockname2', 'a', 3);196 }).toThrowDeveloperError();197 expect(function () {198 Check.typeOf.number.equals('mockName1', 'mockname2', 3, 'a');199 }).toThrowDeveloperError();200 expect(function () {201 Check.typeOf.number.equals('mockName1', 'mockname2', 'b', 'a');202 }).toThrowDeveloperError();203 });204205 it('throws if both the values are a number but not equal', function () {206 expect(function () {207 Check.typeOf.number.equals('mockName1', 'mockName2', 1, 4);208 }).toThrowDeveloperError();209 });210211 it('does not throw if both values are a number and are equal', function () {212 expect(function () {213 Check.typeOf.number.equal('mockName1', 'mockName2', 3, 3);214 }).not.toThrowDeveloperError();215 });216 });217218 describe('Check.typeOf.number.greaterThan', function () {219 it('throws if test is equal to limit', function () {220 expect(function () {221 Check.typeOf.number.greaterThan('mockName', 3, 3);222 }).toThrowDeveloperError();223 });224225 it('throws if test is less than limit', function () {226 expect(function () {227 Check.typeOf.number.greaterThan('mockName', 2, 3);228 }).toThrowDeveloperError();229 });230231 it('does not throw if test is greater than limit', function () {232 expect(function () {233 Check.typeOf.number.greaterThan('mockName', 4, 3);234 }).not.toThrowDeveloperError();235 });236 });237238 describe('Check.typeOf.number.greaterThanOrEquals', function () {239 it('throws if test is less than limit', function () {240 expect(function () {241 Check.typeOf.number.greaterThanOrEquals('mockName', 2, 3);242 }).toThrowDeveloperError();243 });244245 it('does not throw if test is equal to limit', function () {246 expect(function () {247 Check.typeOf.number.greaterThanOrEquals('mockName', 3, 3);248 }).not.toThrowDeveloperError();249 });250251 it('does not throw if test is greater than limit', function () {252 expect(function () {253 Check.typeOf.number.greaterThanOrEquals('mockName', 4, 3);254 }).not.toThrowDeveloperError();255 });256 }); ...

Full Screen

Full Screen

functions.py

Source:functions.py Github

copy

Full Screen

1import random as rd2import statistics3import numpy as np4#Proba Attack Dice5AttName = ['crit' , 'touche' , 'adre' , 'miss']6AttWhite = [1,1,1,5]7AttBlack = [1,3,1,3]8AttRed = [1,5,1,1]9#Proba Defence Dice10AttName = ['def' , 'adre' , 'miss']11DefWhite = [1,1,4]12DefRed = [3,1,2]13#Precalculation for easier code 14NumberHitsAttRed = 515NumberHitsAttBlack = 316NumberHitsAttWhite = 117NumberHitsDefRed = 318NumberHitsDefWhite = 119# 1 = CRIT 20# 2 = ADRE21# 3-x = TOUCHE22# ListThrow [crits,hits,Miss]23# 1 = ADRE24# 2 - x = TOUCHE25# ListThrow [Def,Miss]26# ListMiss [MissWhite, MissBlack, MissRed]27def oneThrow(ListThrow,NumberHits,AdreCrit,NumberCritical,NumberSurge,Adre):28 tmp=029 random = rd.randint(1,8)30 #CRITS31 if random == 1:32 ListThrow[0]+=133 return 1 ,NumberCritical,NumberSurge,ListThrow34 35 #HITS36 elif 3<= random <3+NumberHits:37 ListThrow[1]+=138 return 1,NumberCritical,NumberSurge,ListThrow39 40 #ADRE41 elif random ==2:42 if AdreCrit:43 ListThrow[0]+=144 return 1,NumberCritical,NumberSurge,ListThrow45 elif NumberCritical >0:46 ListThrow[0]+=147 NumberCritical-=148 return 1,NumberCritical,NumberSurge,ListThrow49 elif NumberSurge >0:50 ListThrow[0]+=151 NumberSurge-=152 return 1,NumberCritical,NumberSurge,ListThrow53 elif Adre:54 ListThrow[1]+=155 return 1,NumberCritical, NumberSurge,ListThrow56 else:57 ListThrow[2]+=158 return 0,NumberCritical,NumberSurge,ListThrow59 #MISS60 else :61 ListThrow[2]+=162 return 0,NumberCritical,NumberSurge,ListThrow63 64 65def throwDice(numberAttWhiteDice,numberAttBlackDice,numberAttRedDice,DefDiceUsed,fullArmor,adredef,manoimpro,AdreCrit=False ,\66 Adre=False,numberThrow=50000,attOrDef ='att',critiqueNumber=0,impactNumber=0,armorNumber=0,dodgeNumber=0,\67 couvertNumber=0,perforantNumber=0,dangersensNumber=0,coupdechanceNumber=0,surgeNumber=0,surgeDefNumber=0,\68 HauteVelocite=False,aimNumber=0,preciseNumber=0):69 70 print("numberAttWhiteDice : ",numberAttWhiteDice)71 print("numberAttBlackDice : ",numberAttBlackDice)72 print("numberAttRedDice : ",numberAttRedDice)73 print("AdreCrit : ",AdreCrit)74 print("Adre : ",Adre)75 print("critiqueNumber : ",critiqueNumber)76 print("dodgeNumber : ",dodgeNumber)77 listEsperance =[]78 listCrits = []79 listHits = []80 listMiss = []81 listWound = []82 listnumberOfSave = []83 84 if (attOrDef =='att'):85 86 #NUMBER OF THROW:87 for throw in range (numberThrow):88 89 NumberCritical = critiqueNumber90 NumberSurge = surgeNumber91 NumberSurgeDef = surgeDefNumber92 Numberdodge = dodgeNumber93 esperance=094 ListThrow=[0,0,0]95 ListMissPerDice = [0,0,0]96 for i in range(numberAttWhiteDice):97 result, NumberCritical,NumberSurge,ListThrow = oneThrow(ListThrow,NumberHitsAttWhite,AdreCrit,NumberCritical,NumberSurge,Adre)98 esperance += result99 ListMissPerDice[0]+=1-result100 101 for i in range(numberAttBlackDice):102 result, NumberCritical,NumberSurge, ListThrow= oneThrow(ListThrow,NumberHitsAttBlack,AdreCrit,NumberCritical,NumberSurge,Adre)103 esperance += result 104 ListMissPerDice[1]+=1-result105 106 for i in range(numberAttRedDice):107 result, NumberCritical,NumberSurge, ListThrow= oneThrow(ListThrow,NumberHitsAttRed,AdreCrit,NumberCritical,NumberSurge,Adre)108 esperance += result109 ListMissPerDice[2]+=1-result 110 111 #AIM 112 for i in range(aimNumber):113 rerolled=2+preciseNumber114 #RED115 for i in range(ListMissPerDice[2]):116 if (rerolled>0):117 result, NumberCritical,NumberSurge,ListThrow = oneThrow(ListThrow,NumberHitsAttRed,AdreCrit,NumberCritical,NumberSurge,Adre)118 esperance += result119 ListMissPerDice[2]-=result120 rerolled-=1121 ListThrow[2]=ListThrow[2] - 1122 #BLACK123 for i in range(ListMissPerDice[1]):124 if (rerolled>0):125 result, NumberCritical,NumberSurge,ListThrow = oneThrow(ListThrow,NumberHitsAttBlack,AdreCrit,NumberCritical,NumberSurge,Adre)126 esperance += result127 ListMissPerDice[1]-=result128 rerolled-=1129 ListThrow[2]=ListThrow[2] - 1130 131 #WHITE132 for i in range(ListMissPerDice[0]):133 if (rerolled>0):134 result, NumberCritical,NumberSurge,ListThrow = oneThrow(ListThrow,NumberHitsAttWhite,AdreCrit,NumberCritical,NumberSurge,Adre)135 esperance += result136 ListMissPerDice[0]-=result137 rerolled-=1138 ListThrow[2]=ListThrow[2] - 1139 #IMPACT 140 if (fullArmor or armorNumber>0):141 for i in range(impactNumber):142 if (ListThrow[1])>0:143 ListThrow[1]-=1144 ListThrow[0]+=1145 listEsperance.append(esperance)146 listCrits.append(ListThrow[0])147 listHits.append(ListThrow[1])148 listMiss.append(ListThrow[2])149 #################150 #DEFENCE 151 #################152 #Couvert153 if (couvertNumber>0):154 for i in range( min(couvertNumber,ListThrow[1])):155 ListThrow[1]-=1156 #Manoeures improbables 157 if (Numberdodge>0 and not(HauteVelocite) and manoimpro):158 159 for i in range (ListThrow[0]):160 if (Numberdodge>0):161 Numberdodge-=1162 ListThrow[0]-=1163 164 for i in range (ListThrow[1]):165 if (Numberdodge>0):166 Numberdodge-=1167 ListThrow[1]-=1168 #Dodge:169 if (Numberdodge>0 and not(HauteVelocite) and not(manoimpro)):170 for i in range( min(Numberdodge,ListThrow[1])):171 ListThrow[1]-=1172 #Tireur embusqué173 #Full Armor 174 if (fullArmor):175 ListThrow[1]=0176 #Armor Number 177 if (armorNumber>0):178 for i in range( min(armorNumber,ListThrow[1])):179 ListThrow[1]-=1180 numberOfSave=ListThrow[0]+ListThrow[1]181 listnumberOfSave.append(numberOfSave)182 sumResult=0183 #Danger Sens 184 #Dice def 185 if (DefDiceUsed=="rdef"):186 for i in range(numberOfSave+dangersensNumber):187 result, ListThrow,NumberSurgeDef= oneThrowDef(ListThrow,NumberHitsDefRed,adredef,NumberSurgeDef)188 sumResult+=result189 190 #Coup de chance 191 if (coupdechanceNumber>0):192 for j in range(coupdechanceNumber):193 if(sumResult<numberOfSave):194 result, ListThrow,NumberSurgeDef= oneThrowDef(ListThrow,NumberHitsDefRed,adredef,NumberSurgeDef)195 sumResult+=result196 if (DefDiceUsed=="wdef"):197 for i in range(numberOfSave+dangersensNumber):198 result, ListThrow,NumberSurgeDef = oneThrowDef(ListThrow,NumberHitsDefWhite,adredef,NumberSurgeDef)199 sumResult+=result200 #Coup de chance 201 if (coupdechanceNumber>0):202 for j in range(coupdechanceNumber):203 if(sumResult<numberOfSave):204 result, ListThrow,NumberSurgeDef= oneThrowDef(ListThrow,NumberHitsDefWhite,adredef,NumberSurgeDef)205 sumResult+=result206 207 208 #Perforant209 if (perforantNumber>0):210 for i in range( min(perforantNumber,sumResult)):211 sumResult-=1212 213 214 #Wound Total 215 if(sumResult>numberOfSave):216 listWound.append(0)217 else:218 listWound.append(numberOfSave-sumResult)219 220 221 222 #MEAN223 listEsperance = 1000*np.array(listEsperance)224 listCrits = 1000*np.array(listCrits)225 listHits = 1000*np.array(listHits)226 listMiss = 1000*np.array(listMiss)227 listWound = 1000*np.array(listWound)228 listnumberOfSave = 1000*np.array(listnumberOfSave)229 return statistics.mean(listEsperance)/1000,\230 statistics.mean(listCrits)/1000,\231 statistics.mean(listHits)/1000,\232 statistics.mean(listMiss)/1000,\233 statistics.mean(listWound)/1000,\234 statistics.mean(listnumberOfSave)/1000,\235 236 237def oneThrowDef(ListThrow,NumberHits,Adre,NumberSurgeDef):238 tmp=0239 random = rd.randint(1,6)240 if 2<= random <2+NumberHits:241 ListThrow[0]+=1242 return 1,ListThrow,NumberSurgeDef243 244 elif random ==1:245 246 if Adre:247 ListThrow[0]+=1248 return 1,ListThrow,NumberSurgeDef249 elif NumberSurgeDef>0:250 NumberSurgeDef-=1251 ListThrow[0]+=1252 return 1,ListThrow,NumberSurgeDef253 else:254 ListThrow[1]+=1255 return 0,ListThrow,NumberSurgeDef256 else :257 ListThrow[1]+=1258 return 0,ListThrow,NumberSurgeDef...

Full Screen

Full Screen

deepFreezeAndThrowOnMutationInDev-test.js

Source:deepFreezeAndThrowOnMutationInDev-test.js Github

copy

Full Screen

1/**2 * Copyright (c) Meta Platforms, Inc. and affiliates.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 *7 * @format8 * @emails oncall+react_native9 */10const deepFreezeAndThrowOnMutationInDev = require('../deepFreezeAndThrowOnMutationInDev');11describe('deepFreezeAndThrowOnMutationInDev', function () {12 it('should be a noop on non object values', () => {13 __DEV__ = true;14 expect(() => deepFreezeAndThrowOnMutationInDev('')).not.toThrow();15 expect(() => deepFreezeAndThrowOnMutationInDev(null)).not.toThrow();16 expect(() => deepFreezeAndThrowOnMutationInDev(false)).not.toThrow();17 expect(() => deepFreezeAndThrowOnMutationInDev(5)).not.toThrow();18 expect(() => deepFreezeAndThrowOnMutationInDev()).not.toThrow();19 __DEV__ = false;20 expect(() => deepFreezeAndThrowOnMutationInDev('')).not.toThrow();21 expect(() => deepFreezeAndThrowOnMutationInDev(null)).not.toThrow();22 expect(() => deepFreezeAndThrowOnMutationInDev(false)).not.toThrow();23 expect(() => deepFreezeAndThrowOnMutationInDev(5)).not.toThrow();24 expect(() => deepFreezeAndThrowOnMutationInDev()).not.toThrow();25 });26 it('should not throw on object without prototype', () => {27 __DEV__ = true;28 const o = Object.create(null);29 o.key = 'Value';30 expect(() => deepFreezeAndThrowOnMutationInDev(o)).not.toThrow();31 });32 it('should throw on mutation in dev with strict', () => {33 'use strict';34 __DEV__ = true;35 const o = {key: 'oldValue'};36 deepFreezeAndThrowOnMutationInDev(o);37 expect(() => {38 o.key = 'newValue';39 }).toThrowError(40 'You attempted to set the key `key` with the value `"newValue"` ' +41 'on an object that is meant to be immutable and has been frozen.',42 );43 expect(o.key).toBe('oldValue');44 });45 it('should throw on mutation in dev without strict', () => {46 __DEV__ = true;47 const o = {key: 'oldValue'};48 deepFreezeAndThrowOnMutationInDev(o);49 expect(() => {50 o.key = 'newValue';51 }).toThrowError(52 'You attempted to set the key `key` with the value `"newValue"` ' +53 'on an object that is meant to be immutable and has been frozen.',54 );55 expect(o.key).toBe('oldValue');56 });57 it('should throw on nested mutation in dev with strict', () => {58 'use strict';59 __DEV__ = true;60 const o = {key1: {key2: {key3: 'oldValue'}}};61 deepFreezeAndThrowOnMutationInDev(o);62 expect(() => {63 o.key1.key2.key3 = 'newValue';64 }).toThrowError(65 'You attempted to set the key `key3` with the value `"newValue"` ' +66 'on an object that is meant to be immutable and has been frozen.',67 );68 expect(o.key1.key2.key3).toBe('oldValue');69 });70 it('should throw on nested mutation in dev without strict', () => {71 __DEV__ = true;72 const o = {key1: {key2: {key3: 'oldValue'}}};73 deepFreezeAndThrowOnMutationInDev(o);74 expect(() => {75 o.key1.key2.key3 = 'newValue';76 }).toThrowError(77 'You attempted to set the key `key3` with the value `"newValue"` ' +78 'on an object that is meant to be immutable and has been frozen.',79 );80 expect(o.key1.key2.key3).toBe('oldValue');81 });82 it('should throw on insertion in dev with strict', () => {83 'use strict';84 __DEV__ = true;85 const o = {oldKey: 'value'};86 deepFreezeAndThrowOnMutationInDev(o);87 expect(() => {88 o.newKey = 'value';89 }).toThrowError(90 /(Cannot|Can't) add property newKey, object is not extensible/,91 );92 expect(o.newKey).toBe(undefined);93 });94 it('should not throw on insertion in dev without strict', () => {95 __DEV__ = true;96 const o = {oldKey: 'value'};97 deepFreezeAndThrowOnMutationInDev(o);98 expect(() => {99 o.newKey = 'value';100 }).not.toThrow();101 expect(o.newKey).toBe(undefined);102 });103 it('should mutate and not throw on mutation in prod', () => {104 'use strict';105 __DEV__ = false;106 const o = {key: 'oldValue'};107 deepFreezeAndThrowOnMutationInDev(o);108 expect(() => {109 o.key = 'newValue';110 }).not.toThrow();111 expect(o.key).toBe('newValue');112 });113 // This is a limitation of the technique unfortunately114 it('should not deep freeze already frozen objects', () => {115 'use strict';116 __DEV__ = true;117 const o = {key1: {key2: 'oldValue'}};118 Object.freeze(o);119 deepFreezeAndThrowOnMutationInDev(o);120 expect(() => {121 o.key1.key2 = 'newValue';122 }).not.toThrow();123 expect(o.key1.key2).toBe('newValue');124 });125 it("shouldn't recurse infinitely", () => {126 __DEV__ = true;127 const o = {};128 o.circular = o;129 deepFreezeAndThrowOnMutationInDev(o);130 });...

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 Sure 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