Best Python code snippet using tempest_python
test_decomp.py
Source:test_decomp.py
...223 assert len(decomp.polygons) == 2224 assert pd.get_last_polygon_changes() == (PolygonChange.shape, [outer.id], None)225 #plot_polygon_decomposition(decomp)226 # delete segment - split wire227 pd.delete_segment(sg_m)228 assert len(decomp.wires) == 4229 assert len(decomp.polygons) == 2230 #plot_polygon_decomposition(decomp)231 assert pd.get_last_polygon_changes() == (PolygonChange.shape, [outer.id], None)232 # other split wire233 pt_op = sg_p.vtxs[out_vtx]234 pd.delete_segment(sg_f)235 assert len(decomp.wires) == 5236 assert len(decomp.polygons) == 2237 #plot_polygon_decomposition(decomp)238 #test split_segment connected on both sides; split non outer polygon239 seg_y, = pd.add_line( (0,0.25), (0.25, 0.25))240 assert pd.get_last_polygon_changes() == (PolygonChange.split, 1, 2)241 # test _join_segments - _split_segment inversion242 seg1 = sg_e243 mid_point = seg1.vtxs[in_vtx]244 seg0 = sg_e.next[left_side][0]245 decomp.join_segments(mid_point, seg0, seg1)246 # print("Decomp:\n", decomp)247 pd.delete_point(pt_op)248 # plot_polygon_decomposition(decomp)249 # test join polygons250 pd.delete_segment(seg_y)251 assert pd.get_last_polygon_changes() == (PolygonChange.join, 1, 2)252 # test add_free_point253 pd.add_free_point(100, (3.0, 0.3), decomp.outer_polygon.id)254 pd.remove_free_point(100)255 def check_split_poly_structure(self, decomp, out_square, in_square):256 decomp.check_consistency()257 sg_a, sg_b, sg_c, sg_d = out_square258 sg_e, sg_f, sg_g, sg_h = in_square259 assert sg_b.wire == sg_a.wire260 assert sg_c.wire == sg_a.wire261 assert sg_d.wire == sg_a.wire262 assert sg_f.wire == sg_e.wire263 assert sg_g.wire == sg_e.wire264 assert sg_h.wire == sg_e.wire265 wire1 = decomp.outer_polygon.outer_wire266 wire2 = list(wire1.childs)[0]267 wire3 = list(wire2.childs)[0]268 assert sg_a.wire == [wire2, wire3]269 wire4 = list(wire3.childs)[0]270 wire5 = list(wire4.childs)[0]271 assert sg_e.wire == [wire4, wire5]272 assert len(wire5.childs) == 0273 def test_split_poly(self):274 pd = PolygonDecomposition()275 decomp = pd.decomp276 sg_a, = pd.add_line((0,0), (2,0))277 sg_b, = pd.add_line((2, 0), (2, 2))278 sg_c, = pd.add_line((2, 2), (0, 2))279 sg_d, = pd.add_line((0, 2), (0, 0))280 # closed outer polygon281 assert sg_a.next == [ (sg_d, 0), (sg_b, 1)]282 assert sg_b.next == [ (sg_a, 0), (sg_c, 1)]283 assert sg_c.next == [ (sg_b, 0), (sg_d, 1)]284 assert sg_d.next == [ (sg_c, 0), (sg_a, 1)]285 external_wire = list(decomp.outer_polygon.outer_wire.childs)[0]286 assert sg_a.wire[right_side] == external_wire287 assert sg_b.wire[right_side] == external_wire288 assert sg_c.wire[right_side] == external_wire289 assert sg_d.wire[right_side] == external_wire290 #plot_polygon_decomposition(decomp)291 assert len(decomp.polygons) == 2292 sg_e, = pd.add_line((0.5, 0.5), (1, 0.5))293 sg_f, = pd.add_line((1, 0.5), (1, 1))294 sg_g, = pd.add_line((1, 1), (0.5, 1))295 sg_h, = pd.add_line((0.5, 1), (0.5, 0.5))296 # closed inner polygon297 #plot_polygon_decomposition(decomp)298 print("Decomp:\n", pd)299 out_square = sg_a, sg_b, sg_c, sg_d300 in_square = sg_e, sg_f, sg_g, sg_h301 self.check_split_poly_structure(decomp, out_square, in_square)302 # join nested wires303 sg_x = pd.new_segment(sg_e.vtxs[out_vtx], sg_a.vtxs[out_vtx] )304 # split nested wires305 #plot_polygon_decomposition(decomp)306 pd.delete_segment(sg_x)307 self.check_split_poly_structure(decomp, out_square, in_square)308 # Join nested wires, oposite (other order of wires in _split_wires)309 sg_x = pd.new_segment(sg_a.vtxs[out_vtx], sg_e.vtxs[out_vtx])310 # split nested wires311 #plot_polygon_decomposition(decomp)312 pd.delete_segment(sg_x)313 self.check_split_poly_structure(decomp, out_square, in_square)314 # split polygon - balanced315 seg_y, = pd.add_line((0.5, 0.5), (1,1))316 # join polygons - balanced317 pd.delete_segment(seg_y)318 self.check_split_poly_structure(decomp, out_square, in_square)319 # join nested polygons320 pd.delete_segment(sg_h)321 #plot_polygon_decomposition(decomp)322 assert sg_b.wire == sg_a.wire323 assert sg_c.wire == sg_a.wire324 assert sg_d.wire == sg_a.wire325 assert sg_f.wire == sg_e.wire326 assert sg_g.wire == sg_e.wire327 assert sg_h.wire == sg_e.wire328 we_r, we_l = sg_e.wire329 assert we_r == we_l330 wire1 = decomp.outer_polygon.outer_wire331 wire2 = list(wire1.childs)[0]332 wire3 = list(wire2.childs)[0]333 assert sg_a.wire == [wire2, wire3]334 wire4 = list(wire3.childs)[0]335 assert we_r == wire4336 assert len(wire4.childs) == 0337 def test_main_polygon_with_childs(self):338 da = PolygonDecomposition()339 decomp = da.decomp340 seg_in, = da.add_line((0.1, 0.5), (0.9, 0.5))341 seg_out, = da.add_line((0.1, -0.5), (0.9, -0.5))342 da.add_line((0, 0), (1, 0))343 da.add_line((0, 0), (0, 1))344 da.add_line((1, 1), (1, 0))345 da.add_line((1, 1), (0, 1))346 assert seg_in.wire[0] == seg_in.wire[1]347 assert seg_in.wire[0].polygon != decomp.outer_polygon348 assert seg_out.wire[0] == seg_out.wire[1]349 assert seg_out.wire[0].polygon == decomp.outer_polygon350 def test_seg_add_remove(self):351 pd = PolygonDecomposition()352 decomp = pd.decomp353 pd.add_line((0, 1), (0,0))354 pd.add_line((0, 0), (1, 0))355 seg_c, = pd.add_line((1, 0), (0, 1))356 pd.add_line((1, 0), (2, 0))357 pd.add_line((2, 0), (2, 1))358 pd.add_line((1, 0), (2, 1) )359 #plot_polygon_decomposition(decomp)360 assert len(decomp.outer_polygon.outer_wire.childs) == 1361 assert len(decomp.outer_polygon.outer_wire.childs.pop().childs) == 2362 pd.delete_segment(seg_c)363 #plot_polygon_decomposition(decomp)364 def test_split_poly_1(self):365 # Test splitting of points and holes.366 pd = PolygonDecomposition()367 decomp = pd.decomp368 pd.add_line((0, 0), (1,0))369 pd.add_line((0, 0), (0, 1))370 pd.add_line((1, 1), (1, 0))371 pd.add_line((1, 1), (0, 1))372 pd.add_point( (0.2,0.2))373 pd.add_point( (0.8, 0.2))374 pd.add_line((0.2, 0.6), (0.3,0.6))375 pd.add_line((0.8, 0.6), (0.7, 0.6))376 #plot_polygon_decomposition(decomp)377 pd.add_line((0.5,0), (0.5,1))378 #plot_polygon_decomposition(decomp)379 def test_join_poly(self):380 pd = PolygonDecomposition()381 decomp = pd.decomp382 sg0, = pd.add_line((0, 0), (0, 2))383 pd.add_line((0, 0), (2, 0))384 sg2, = pd.add_line((0, 2), (2, 0))385 pd.delete_segment(sg2)386 def test_join_segments(self):387 pd = PolygonDecomposition()388 decomp = pd.decomp389 sg0, = pd.add_line((0,0), (1,0))390 mid_pt = sg0.vtxs[1]391 sg1, = pd.add_line((2,0), (1,0))392 sg2, = pd.add_line((2, 0), (3, 0))393 decomp.join_segments(sg0.vtxs[1], sg0, sg1)394 decomp.join_segments(sg0.vtxs[1], sg0, sg2)395 def test_join_polygons_embedded(self):396 pd = PolygonDecomposition()397 decomp = pd.decomp398 pd.add_line((0, 0), (3, 0))399 pd.add_line((0, 0), (0, 3))400 sg3, = pd.add_line((0, 3), (3, 0))401 pd.delete_segment(sg3)402 assert len(decomp.outer_polygon.outer_wire.childs) == 1403 wire = list(decomp.outer_polygon.outer_wire.childs)[0]404 assert len(wire.childs) == 0405 def test_polygon_childs_degenerate(self):406 pd = PolygonDecomposition()407 decomp = pd.decomp408 pd.add_line((0, 0), (3, 0))409 pd.add_line((0, 0), (0, 3))410 pd.add_line((0, 3), (3, 0))411 pd.add_line((1, 1), (2, 1))412 pd.add_line((1, 1), (1, 2))413 pd.add_line((1, 2), (2, 1))414 #plot_polygon_decomposition(decomp)415 pd.add_line((1, 1), (0, 0))416 pd.add_line((2, 1), (3, 0))417 pd.add_line((1, 2), (0, 3))418 #plot_polygon_decomposition(decomp)419 def test_polygon_childs(self):420 pd = PolygonDecomposition()421 decomp = pd.decomp422 pd.add_line((0, 0), (4, 0))423 pd.add_line((0, 0), (0, 4))424 pd.add_line((0, 4), (4, 0))425 pd.add_line((1, 1), (2, 1))426 pd.add_line((1, 1), (1, 2))427 pd.add_line((1, 2), (2, 1))428 #plot_polygon_decomposition(decomp)429 lst = list(pd.get_childs(0))430 assert lst == [0,1,2]431 pd.add_line((1, 1), (0, 0))432 pd.add_line((2, 1), (4, 0))433 pd.add_line((1, 2), (0, 4))434 #plot_polygon_decomposition(decomp)435 def test_add_dendrite(self):436 pd = PolygonDecomposition()437 decomp = pd.decomp438 pt0 = pd.add_point( (31.6, -40) )439 pt1 = pd.add_point( (32.4, -62.8) )440 pt2 = pd.add_point( (57.7, -37.4) )441 pd.new_segment(pt0, pt1)442 pd.new_segment(pt0, pt2)443 pd.new_segment(pt1, pt2)444 # print(decomp)445 pt3 = pd.add_free_point(4, (75.7, -35), 0 )446 pd.new_segment(pt2, pt3)447 #plot_polygon_decomposition(decomp)448 def test_complex_wire_remove(self):449 da = PolygonDecomposition()450 # outer triangle451 da.add_line((0, 4), (0,0))452 da.add_line((0, 0), (4, 0))453 da.add_line((4, 0), (0, 4))454 # inner triangle455 da.add_line((1, 2), (1, 1))456 da.add_line((1, 1), (2, 1))457 da.add_line((2, 1), (1, 2))458 # rugs459 sa, = da.add_line((2, 1), (4, 0))460 sb, = da.add_line((1, 2), (0, 4))461 #print("initial dc:\n", da)462 #plot_polygon_decomposition(da)463 da.delete_segment(sb)464 da.delete_segment(sa)465 #print("final dc:\n", da)466 def test_complex_join_polygons(self):467 da = PolygonDecomposition()468 # outer triangle469 da.add_line((0, 4), (0,0))470 da.add_line((0, 0), (4, 0))471 da.add_line((4, 0), (0, 4))472 # inner triangle473 da.add_line((1, 2), (1, 1))474 da.add_line((1, 1), (2, 1))475 seg, = da.add_line((2, 1), (1, 2))476 # inner triangle477 da.add_line((1.2, 1.6), (1.2, 1.2))478 da.add_line((1.2, 1.2), (1.6, 1.2))479 da.add_line((1.6, 1.2), (1.2, 1.6))480 da.decomp.check_consistency()481 #plot_polygon_decomposition(da)482 da.delete_segment(seg)...
interval_selection.py
Source:interval_selection.py
1#!/bin/python2"""3You are given a list of N intervals.4The challenge is to select the largest subset of intervals such that no three intervals in the subset share a common point?5Input:6The first line contains the number of cases T. T cases follow. Each case contains the number N on the first line followed by N lines containing integers ai and bi. The ith line denotes the starting and ending points of the ith interval.7Output:8Output T lines, one for each test case, containing the desired answer for the corresponding test case.9Constraints:101 <= T <= 100112 <= N <= 1000121 <= ai <= bi <= 1000000000 (10^9)13"""14test = int(raw_input())15for t in xrange(0, test):16 N = int(raw_input())17 A = []18 B = []19 segments = []20 for i in range(0, N):21 numbers = raw_input()22 a, b = [int(x) for x in numbers.split(' ')]23 segments.append((a,b)) 24 A.append(a)25 B.append(b)26 B = sorted(B)27 # check if more than 2 segments are covering it28 for i in B:29 num_covering = 030 delete_segment = -1,-131 for a,b in segments:32 if a<= i and i<=b:33 num_covering += 134 if delete_segment[1] < b:35 delete_segment = a, b36 if num_covering > 2:37 segments.remove(delete_segment)38 39 result = len(segments)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!