How to use get_st method in avocado

Best Python code snippet using avocado_python

test_casualty.py

Source:test_casualty.py Github

copy

Full Screen

...3 game = get_game_turn()4 team = game.get_agent_team(game.actor)5 team.state.rerolls = 06 attacker, defender = get_block_players(game, team)7 attacker.extra_st = defender.get_st() - attacker.get_st() + 1 # make this a 2 die block.8 attacker.extra_skills.append(Skill.BLOCK)9 defender_pos = Square(defender.position.x, defender.position.y)10 # it's a 2 dice block11 BBDie.clear_fixes()12 BBDie.fix_result(BBDieResult.BOTH_DOWN)13 BBDie.fix_result(BBDieResult.BOTH_DOWN)14 D6.FixedRolls.clear()15 # fix the armour roll16 D6.fix_result(5)17 D6.fix_result(5)18 # fix the injury roll to casualty19 D6.fix_result(5)20 D6.fix_result(5)21 # fix the casualty roll #1 (Gouged Eye / MNG)22 D6.fix_result(4)23 D8.fix_result(3)24 game.step(Action(ActionType.START_BLOCK, player=attacker))25 game.step(Action(ActionType.BLOCK, position=defender.position))26 game.step(Action(ActionType.SELECT_BOTH_DOWN))27 assert game.has_report_of_type(OutcomeType.CASUALTY)28 assert defender.state.injuries_gained[0] is CasualtyEffect.MNG29 assert not game.has_report_of_type(OutcomeType.SUCCESSFUL_REGENERATION)30 assert not game.has_report_of_type(OutcomeType.FAILED_REGENERATION)31def test_casualty_regeneration_success():32 game = get_game_turn()33 team = game.get_agent_team(game.actor)34 team.state.rerolls = 035 attacker, defender = get_block_players(game, team)36 attacker.extra_st = defender.get_st() - attacker.get_st() + 1 # make this a 2 die block.37 attacker.extra_skills.append(Skill.BLOCK)38 defender_pos = Square(defender.position.x, defender.position.y)39 defender.extra_skills.append(Skill.REGENERATION)40 # it's a 2 dice block41 BBDie.clear_fixes()42 BBDie.fix_result(BBDieResult.BOTH_DOWN)43 BBDie.fix_result(BBDieResult.BOTH_DOWN)44 D6.FixedRolls.clear()45 # fix the armour roll46 D6.fix_result(5)47 D6.fix_result(5)48 # fix the injury roll to casualty49 D6.fix_result(5)50 D6.fix_result(5)51 # add a value for casualty effect52 D6.fix_result(3)53 # fix the regeneration roll54 D6.fix_result(4)55 game.step(Action(ActionType.START_BLOCK, player=attacker))56 game.step(Action(ActionType.BLOCK, position=defender.position))57 game.step(Action(ActionType.SELECT_BOTH_DOWN))58 assert game.has_report_of_type(OutcomeType.CASUALTY)59 assert game.has_report_of_type(OutcomeType.SUCCESSFUL_REGENERATION)60 assert defender in game.get_reserves(defender.team)61 assert not defender.state.injuries_gained62def test_casualty_regeneration_fail():63 game = get_game_turn()64 team = game.get_agent_team(game.actor)65 team.state.rerolls = 066 attacker, defender = get_block_players(game, team)67 attacker.extra_st = defender.get_st() - attacker.get_st() + 1 # make this a 2 die block.68 attacker.extra_skills.append(Skill.BLOCK)69 defender_pos = Square(defender.position.x, defender.position.y)70 defender.extra_skills.append(Skill.REGENERATION)71 # it's a 2 dice block72 BBDie.clear_fixes()73 BBDie.fix_result(BBDieResult.BOTH_DOWN)74 BBDie.fix_result(BBDieResult.BOTH_DOWN)75 D6.FixedRolls.clear()76 # fix the armour roll77 D6.fix_result(5)78 D6.fix_result(5)79 # fix the injury roll to casualty80 D6.fix_result(5)81 D6.fix_result(5)82 # add a value for casualty effect83 D6.fix_result(4)84 # fix the regeneration roll85 D6.fix_result(3)86 game.step(Action(ActionType.START_BLOCK, player=attacker))87 game.step(Action(ActionType.BLOCK, position=defender.position))88 game.step(Action(ActionType.SELECT_BOTH_DOWN))89 assert game.has_report_of_type(OutcomeType.CASUALTY)90 assert game.has_report_of_type(OutcomeType.FAILED_REGENERATION)91 assert defender not in game.get_reserves(defender.team)92 assert defender.state.injuries_gained93def test_casualty_with_decay():94 game = get_game_turn()95 team = game.get_agent_team(game.actor)96 team.state.rerolls = 097 attacker, defender = get_block_players(game, team)98 attacker.extra_st = defender.get_st() - attacker.get_st() + 1 # make this a 2 die block.99 attacker.extra_skills.append(Skill.BLOCK)100 defender_pos = Square(defender.position.x, defender.position.y)101 defender.extra_skills.append(Skill.DECAY)102 # it's a 2 dice block103 BBDie.clear_fixes()104 BBDie.fix_result(BBDieResult.BOTH_DOWN)105 BBDie.fix_result(BBDieResult.BOTH_DOWN)106 D6.FixedRolls.clear()107 # fix the armour roll108 D6.fix_result(5)109 D6.fix_result(5)110 # fix the injury roll to casualty111 D6.fix_result(5)112 D6.fix_result(5)113 # fix the casualty roll #1 (Gouged Eye / MNG)114 D6.fix_result(4)115 D8.fix_result(3)116 # fix the casualty roll #2 (BH / none)117 D6.fix_result(3)118 D8.fix_result(1)119 game.step(Action(ActionType.START_BLOCK, player=attacker))120 game.step(Action(ActionType.BLOCK, position=defender.position))121 game.step(Action(ActionType.SELECT_BOTH_DOWN))122 assert game.has_report_of_type(OutcomeType.CASUALTY)123 assert defender.state.injuries_gained[0] is CasualtyEffect.MNG124 assert game.has_report_of_type(OutcomeType.MISS_NEXT_GAME)125 assert len(defender.state.injuries_gained) == 1126 assert game.has_report_of_type(OutcomeType.BADLY_HURT)127def test_casualty_with_decay_mng_twice_is_just_one():128 game = get_game_turn()129 team = game.get_agent_team(game.actor)130 team.state.rerolls = 0131 attacker, defender = get_block_players(game, team)132 attacker.extra_st = defender.get_st() - attacker.get_st() + 1 # make this a 2 die block.133 attacker.extra_skills.append(Skill.BLOCK)134 defender_pos = Square(defender.position.x, defender.position.y)135 defender.extra_skills.append(Skill.DECAY)136 # it's a 2 dice block137 BBDie.clear_fixes()138 BBDie.fix_result(BBDieResult.BOTH_DOWN)139 BBDie.fix_result(BBDieResult.BOTH_DOWN)140 D6.FixedRolls.clear()141 # fix the armour roll142 D6.fix_result(5)143 D6.fix_result(5)144 # fix the injury roll to casualty145 D6.fix_result(5)146 D6.fix_result(5)147 # fix the casualty roll #1 (Gouged Eye / MNG)148 D6.fix_result(4)149 D8.fix_result(3)150 # fix the casualty roll #2 (BH / none)151 D6.fix_result(4)152 D8.fix_result(4)153 game.step(Action(ActionType.START_BLOCK, player=attacker))154 game.step(Action(ActionType.BLOCK, position=defender.position))155 game.step(Action(ActionType.SELECT_BOTH_DOWN))156 assert game.has_report_of_type(OutcomeType.CASUALTY)157 assert defender.state.injuries_gained[0] is CasualtyEffect.MNG158 assert game.has_report_of_type(OutcomeType.MISS_NEXT_GAME)159 assert len(defender.state.injuries_gained) == 1160def test_casualty_regeneration_success():161 game = get_game_turn()162 team = game.get_agent_team(game.actor)163 team.state.rerolls = 0164 attacker, defender = get_block_players(game, team)165 attacker.extra_st = defender.get_st() - attacker.get_st() + 1 # make this a 2 die block.166 attacker.extra_skills.append(Skill.BLOCK)167 defender_pos = Square(defender.position.x, defender.position.y)168 defender.extra_skills.append(Skill.REGENERATION)169 defender.extra_skills.append(Skill.DECAY)170 # it's a 2 dice block171 BBDie.clear_fixes()172 BBDie.fix_result(BBDieResult.BOTH_DOWN)173 BBDie.fix_result(BBDieResult.BOTH_DOWN)174 D6.FixedRolls.clear()175 # fix the armour roll176 D6.fix_result(5)177 D6.fix_result(5)178 # fix the injury roll to casualty179 D6.fix_result(5)180 D6.fix_result(5)181 # add a value for casualty effect182 D6.fix_result(3)183 # fix the regeneration roll184 D6.fix_result(4)185 game.step(Action(ActionType.START_BLOCK, player=attacker))186 game.step(Action(ActionType.BLOCK, position=defender.position))187 game.step(Action(ActionType.SELECT_BOTH_DOWN))188 assert game.has_report_of_type(OutcomeType.CASUALTY)189 assert game.has_report_of_type(OutcomeType.SUCCESSFUL_REGENERATION)190 assert defender in game.get_reserves(defender.team)191 assert len(defender.state.injuries_gained) == 0192def test_casualty_regeneration_failure():193 game = get_game_turn()194 team = game.get_agent_team(game.actor)195 team.state.rerolls = 0196 attacker, defender = get_block_players(game, team)197 attacker.extra_st = defender.get_st() - attacker.get_st() + 1 # make this a 2 die block.198 attacker.extra_skills.append(Skill.BLOCK)199 defender_pos = Square(defender.position.x, defender.position.y)200 defender.extra_skills.append(Skill.REGENERATION)201 defender.extra_skills.append(Skill.DECAY)202 # it's a 2 dice block203 BBDie.clear_fixes()204 BBDie.fix_result(BBDieResult.BOTH_DOWN)205 BBDie.fix_result(BBDieResult.BOTH_DOWN)206 D6.FixedRolls.clear()207 # fix the armour roll208 D6.fix_result(5)209 D6.fix_result(5)210 # fix the injury roll to casualty211 D6.fix_result(5)...

Full Screen

Full Screen

DistanceMetric.py

Source:DistanceMetric.py Github

copy

Full Screen

...31 cl={}32 lines = trajectory.get_lines()33 for q in Q:34 lr = random.choice(lines)35 r = np.linalg.norm(q-lr.get_st())36 ql = []37 for l in lines:38 if(np.linalg.norm(q-l.get_st())<=r):39 ql.append(l)40 cl[q] = ql41 return cl42 43 def calc_landmarkdst_opt(self,Q,trajectory):44 D = []45 cl = filt_lines(Q,trajectory)46 #lines = trajectory.get_lines()47 for q in Q:48 min_dpt = None49 min_d = float('inf')50 51 for l in cl[q]:52 (d,pt) = l.get_dist(q) 53 if(min_d>d):54 min_d = d55 min_dpt = pt56 D.append((min_d,min_dpt))57 return D58 59 def calc_trajectorydst(self,Q,traj_a,traj_b):60 D_a = self.calc_landmarkdst(Q,traj_a)61 D_b = self.calc_landmarkdst(Q,traj_b)62 n = len(Q)63 dist_Q = 064 for i in range(n):65 dist_Q = dist_Q + (D_a[i][0]-D_b[i][0])**266 dist_Q = math.sqrt((1.0/n)*dist_Q)67 dist_Qpi = 068 for i in range(n):69 #print(D_a[i][1])70 #print(D_b[i][1])71 dist_Qpi = dist_Qpi + np.linalg.norm(D_a[i][1]-D_b[i][1])72 dist_Qpi = (1.0/n)*dist_Qpi73 return (dist_Q,dist_Qpi)74 75 def calc_trajectorydst_opt(self,Q,traj_a,traj_b):76 D_a = self.calc_landmarkdst_opt(Q,traj_a)77 D_b = self.calc_landmarkdst_opt(Q,traj_b)78 n = len(Q)79 dist_Q = 080 for i in range(n):81 dist_Q = dist_Q + (D_a[i][0]-D_b[i][0])**282 dist_Q = math.sqrt((1.0/n)*dist_Q)83 dist_Qpi = 084 for i in range(n):85 #print(D_a[i][1])86 #print(D_b[i][1])87 dist_Qpi = dist_Qpi + np.linalg.norm(D_a[i][1]-D_b[i][1])88 dist_Qpi = (1.0/n)*dist_Qpi89 return (dist_Q,dist_Qpi)90 91 def calc_euclideandst(self,traj_a,traj_b):92 lines_a = traj_a.get_lines()93 lines_b = traj_b.get_lines()94 l = min(len(lines_a),len(lines_b))95 ed = 096 for i in range(l):97 diff = lines_a[i].get_st()-lines_b[i].get_st()98 ed = ed + (1.0/l)*math.sqrt(np.dot(diff,np.transpose(diff)))99 return ed100 101# def calc_frechetdst(self,traj_a,traj_b):102# lines_a = traj_a.get_lines()103# lines_b = traj_b.get_lines()104# l = min(len(lines_a),len(lines_b))105# ed = 0106# for i in range(l):107# diff = lines_a[i].get_st()-lines_b[i].get_st()108# ed = ed + (1.0/l)*math.sqrt(np.dot(diff,np.transpose(diff)))109# return ed110 111 def DTW(i,j,c1,c2):112 if(i==0):113 v = np.linalg.norm(c1[0] - c2[j])114 self.D[j][i] = v115 return v116 if(j==0):117 v = np.linalg.norm(c1[i] - c2[0])118 self.D[j][i] = v119 return v120 if(self.D[j][i]!=-1):121 return self.D[j][i]122 v = np.linalg.norm(c1[i]-c2[j])+min(DTW(i-1,j,c1,c2),DTW(i-1,j-1,c1,c2),DTW(i,j-1,c1,c2))123 self.D[j][i] = v124 return v125 126 def calc_dtwdistance(self,traj_a,traj_b):127 lines_a = traj_a.get_lines()128 lines_b = traj_b.get_lines()129 k1 = len(lines_a)130 k2 = len(lines_b)131 c1 = []132 for l in lines_a:133 c1.append(l.get_st())134 c1.append(lines_a[-1].get_en())135 c2 = []136 for l in lines_b:137 c2.append(l.get_st())138 c2.append(lines_b[-1].get_en())139 self.D = [[-1 for i in range(k1+1)] for j in range(k2+1)]140 dst = DTW(k1,k2,c1,c2,self.D)141 return dst142 143 def _c(self,ca, i, j, p, q):144 if ca[i, j] > -1:145 return ca[i, j]146 elif i == 0 and j == 0:147 ca[i, j] = np.linalg.norm(p[i]-q[j])148 elif i > 0 and j == 0:149 ca[i, j] = max(self._c(ca, i-1, 0, p, q), np.linalg.norm(p[i]-q[j]))150 elif i == 0 and j > 0:151 ca[i, j] = max(self._c(ca, 0, j-1, p, q), np.linalg.norm(p[i]-q[j]))152 elif i > 0 and j > 0:153 ca[i, j] = max(154 min(155 self._c(ca, i-1, j, p, q),156 self._c(ca, i-1, j-1, p, q),157 self._c(ca, i, j-1, p, q)158 ),159 np.linalg.norm(p[i]-q[j])160 )161 else:162 ca[i, j] = float('inf')163 return ca[i, j]164 165 def calc_fretchetdistance(self,traj_a,traj_b):166 lines_a = traj_a.get_lines()167 lines_b = traj_b.get_lines()168 k1 = len(lines_a)169 k2 = len(lines_b)170 c1 = []171 for l in lines_a:172 c1.append(l.get_st())173 c1.append(lines_a[-1].get_en())174 c2 = []175 for l in lines_b:176 c2.append(l.get_st())177 c2.append(lines_b[-1].get_en())178 ca = (np.ones((k1, k2), dtype=np.float64) * -1)179 dist = _c(ca, k1-1, k2-1, c1, c2)...

Full Screen

Full Screen

sparse_vector.py

Source:sparse_vector.py Github

copy

Full Screen

...21 :type d: int22 """23 self._st = defaultdict(float)24 self._d = d25 def get_st(self):26 return self._st27 def get_d(self):28 return self._d29 def put(self, i, value):30 if i < 0 or i >= self.get_d():31 raise AttributeError('Illegal index')32 if value == 0.0:33 del self.get_st()[i]34 else:35 self.get_st()[i] = value36 def get(self, i):37 if i < 0 or i >= self.get_d():38 raise AttributeError('Illegal index')39 if i in self.get_st():40 return self.get_st()[i]41 else:42 return 0.043 # Returns the number of non zero entries in this vector44 def nnz(self):45 return len(self.get_st())46 def dimension(self):47 return self.get_d()48 # Returns the inner product of this vector with the specified vector.49 def dot_spv(self, that):50 if self.get_d() != that.get_d():51 raise AttributeError('Vector lengths disagree')52 _sum = 0.053 if len(self.get_st()) <= len(that.get_st()):54 for i in self.get_st().keys():55 if i in that.get_st():56 _sum += self.get(i) * that.get(i)57 else:58 for i in that.get_st().keys():59 if i in self.get_st():60 _sum += self.get(i) * that.get(i)61 return _sum62 # Returns the inner product of this vector with the specified list.63 def dot(self, that):64 _sum = 0.065 for i in self.get_st().keys():66 _sum += that[i] * self.get(i)67 return _sum68 def magnitude(self):69 return math.sqrt(self.dot_spv(self))70 def scale(self, alpha):71 c = SparseVector(self.get_d())72 for i in self.get_st().keys():73 c.put(i, alpha * self.get(i))74 return c75 def plus(self, that):76 if self.get_d() != that.get_d():77 raise AttributeError('Vector lengths disagree')78 c = SparseVector(self.get_d())79 for i in self.get_st().keys():80 c.put(i, self.get(i))81 for i in that.get_st().keys():82 c.put(i, that.get(i) + c.get(i))83 return c84 def __repr__(self):85 return f'<SparseVector(st={self.get_st()}, d={self.get_d()})>'86def main():87 a = SparseVector(10)88 b = SparseVector(10)89 a.put(3, 0.50)90 a.put(9, 0.75)91 a.put(6, 0.11)92 a.put(6, 0.00)93 b.put(3, 0.60)94 b.put(4, 0.90)95 print("a = ", a)96 print("b = ", b)97 print("a dot b = ", a.dot_spv(b))98 print("a + b = ", a.plus(b))99if __name__ == '__main__':...

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