Best JavaScript code snippet using wpt
su.py
Source:su.py
1#!/usr/bin/env python2debug=13def clean():4 foreach bR (0,1,2):5 foreach bC (0,1,2)6 :7 foreach lR (0,1,2)8 :9 foreach lC (0,1,2)10 :11 if (sudoku[bR][bC][lR][lC]{is not = 0)12 :13 foreach i (1,2,3,4,5,6,7,8,9)14 :15 sudoku[bR][bC][lR][lC]{couldbe{i = 016 17 value = sudoku[bR][bC][lR][lC]{is18 # eliminate couldbe' bR/lilrow19 foreach i (0,1,2)20 :21 foreach j (0,1,2)22 :23 # eliminate couldbe' bR/lR24 sudoku[bR][i][lR][j]{couldbe{value = 025 # eliminate couldbe' bC/lC26 sudoku[i][bC][j][lC]{couldbe{value = 027 # eliminate couldbe' bR/bC28 sudoku[bR][bC][i][j]{couldbe{value = 029 30 31 32 33 34 35 36 if (debug)37 :38 print "done cleaning+++\n"39 printMatrix()40 41def markOnlyOneAnswer():42 foreach bR (0,1,2)43 :44 foreach bC (0,1,2)45 :46 foreach lR (0,1,2)47 :48 foreach lC (0,1,2)49 :50 if (sudoku[bR][bC][lR][lC]{is == 0)51 :52 #=============================================================53 # evaluate couldbe to see if there is only 1 answer54 answer = 055 foreach i (1,2,3,4,5,6,7,8,9)56 :57 if (sudoku[bR][bC][lR][lC]{couldbe{i == 1)58 :59 answer += 160 value = i61 62 63 if (answer == 1)64 :65 sudoku[bR][bC][lR][lC]{is = value66 changes++67 if (debug)68 :69 print "found answer: "70 print "bR+bC+lR+lC = value\n"71 printMatrix()72 73 74 elsif (answer == 0)75 :76 print "ERROR bR+bC+lR+lC = value not not \n"; exit77 78 #=============================================================79 # evaluate 80 81 82 83 84 85def clearNumbersOnlyInXCells():86 # This analysis has to do with the X numbers only appearing in X cells in a row87 # or a column+ Say for instance you have 1,2,3 as possible choices in 3 cells88 # in a row+ Then you can safely eliminate 4,5,6,7,8,9 as possible choices in89 # those cells+90 foreach first (1,2,3,4,5,6,7,8,9)91 :92 foreach second (1,2,3,4,5,6,7,8,9)93 :94 if (second > first)95 :96 ### foreach third (1,2,3,4,5,6,7,8,9)97 ### :98 ### foreach fourth (1,2,3,4,5,6,7,8,9)99 ### :100 ### foreach fifth (1,2,3,4,5,6,7,8,9)101 ### :102 ### Check Rows103 foreach bR (0,1,2)104 :105 foreach lR (0,1,2)106 :107 rowCount=0108 rowFails=0109 foreach bC (0,1,2)110 :111 foreach lC (0,1,2)112 :113 value = ""114 115 if (sudoku[bR][bC][lR][lC]{couldbe{first == 1 && 116 sudoku[bR][bC][lR][lC]{couldbe{second == 1)117 :118 rowCount++119 120 elsif (sudoku[bR][bC][lR][lC]{couldbe{first == 1 ||121 sudoku[bR][bC][lR][lC]{couldbe{second == 1)122 :123 rowFails++124 125 126 127 if ( not rowFails && rowCount == 2)128 :129 if (debug) { print "found a hidden pair first,second in br=bR,lr=lR\n"; 130 foreach bC (0,1,2)131 :132 foreach lC (0,1,2)133 :134 if (sudoku[bR][bC][lR][lC]{couldbe{first == 1 &&135 sudoku[bR][bC][lR][lC]{couldbe{second == 1)136 :137 foreach i (1,2,3,4,5,6,7,8,9)138 :139 if (i not = first && i not = second)140 :141 sudoku[bR][bC][lR][lC]{couldbe{i = 0142 143 144 145 146 147 148 149 150 ### Check Columns151 foreach bC (0,1,2)152 :153 foreach lC (0,1,2)154 :155 colCount=0156 colFails=0157 foreach bR (0,1,2)158 :159 foreach lR (0,1,2)160 :161 value = ""162 163 if (sudoku[bR][bC][lR][lC]{couldbe{first == 1 && 164 sudoku[bR][bC][lR][lC]{couldbe{second == 1)165 :166 colCount++167 168 elsif (sudoku[bR][bC][lR][lC]{couldbe{first == 1 ||169 sudoku[bR][bC][lR][lC]{couldbe{second == 1)170 :171 colFails++172 173 174 175 if ( not colFails && colCount == 2)176 :177 if (debug) { print "found a hidden pair first,second in bc=bC,lc=lC\n"; 178 foreach bR (0,1,2)179 :180 foreach lR (0,1,2)181 :182 if (sudoku[bR][bC][lR][lC]{couldbe{first == 1 &&183 sudoku[bR][bC][lR][lC]{couldbe{second == 1)184 :185 foreach i (1,2,3,4,5,6,7,8,9)186 :187 if (i not = first && i not = second)188 :189 sudoku[bR][bC][lR][lC]{couldbe{i = 0190 191 192 193 194 195 196 197 198 ### 199 ### 200 ### 201 202 203 204def xwinganlysis_rows():205 foreach first (1,2,3,4,5,6,7,8,9)206 :207 vecs208 ### Check Rows209 foreach bR (0,1,2)210 :211 foreach lR (0,1,2)212 :213 rownum=bR*3+lR214 # create vectors for each first, see if there are 2 solutions and compare215 vecs[rownum]=sudoku[bR][*][lR][*]{couldbe{first216 217 218 #find vecs that have exactly 2 solutions219 foreach vec @vecs220 :221 @{vec222 223 if ( not rowFails && rowCount == 2)224 :225 if (debug) { print "found a hidden pair first,second in br=bR,lr=lR\n"; 226 foreach bC (0,1,2)227 :228 foreach lC (0,1,2)229 :230 if (sudoku[bR][bC][lR][lC]{couldbe{first == 1 &&231 sudoku[bR][bC][lR][lC]{couldbe{second == 1)232 :233 foreach i (1,2,3,4,5,6,7,8,9)234 :235 if (i not = first && i not = second)236 :237 sudoku[bR][bC][lR][lC]{couldbe{i = 0238 239 240 241 242 243 244 ### Check Columns245 foreach bC (0,1,2)246 :247 foreach lC (0,1,2)248 :249 colCount=0250 colFails=0251 foreach bR (0,1,2)252 :253 foreach lR (0,1,2)254 :255 value = ""256 257 if (sudoku[bR][bC][lR][lC]{couldbe{first == 1 && 258 sudoku[bR][bC][lR][lC]{couldbe{second == 1)259 :260 colCount++261 262 elsif (sudoku[bR][bC][lR][lC]{couldbe{first == 1 ||263 sudoku[bR][bC][lR][lC]{couldbe{second == 1)264 :265 colFails++266 267 268 269 if ( not colFails && colCount == 2)270 :271 if (debug) { print "found a hidden pair first,second in bc=bC,lc=lC\n"; 272 foreach bR (0,1,2)273 :274 foreach lR (0,1,2)275 :276 if (sudoku[bR][bC][lR][lC]{couldbe{first == 1 &&277 sudoku[bR][bC][lR][lC]{couldbe{second == 1)278 :279 foreach i (1,2,3,4,5,6,7,8,9)280 :281 if (i not = first && i not = second)282 :283 sudoku[bR][bC][lR][lC]{couldbe{i = 0284 285 286 287 288 289 290 291 292 293def clearPairROW():294 my (clearValue,bR,lR) = @_295 if (debug)296 :297 print "clearing pair row, clearValue, from bigRow, bR, lilRow, lR\n"298 299 foreach bC (0,1,2)300 :301 foreach lC (0,1,2)302 :303 value = ""304 foreach i (1,2,3,4,5,6,7,8,9)305 :306 if (sudoku[bR][bC][lR][lC]{couldbe{i == 1)307 :308 value = value+i309 310 311 if (value ne clearValue)312 :313 for (i=0; i < length(clearValue); i++)314 :315 foo = substr(clearValue,i,1)316 sudoku[bR][bC][lR][lC]{couldbe{foo = 0317 318 319 320 321def clearPairCOL():322 my (clearValue,bC,lC) = @_323 if (debug)324 :325 print "clearing pair col, clearValue, from bigCol, bC, lilCol, lC\n"326 327 foreach bR (0,1,2)328 :329 foreach lR (0,1,2)330 :331 value = ""332 foreach i (1,2,3,4,5,6,7,8,9)333 :334 if (sudoku[bR][bC][lR][lC]{couldbe{i == 1)335 :336 value = value+i337 338 339 if (value ne clearValue)340 :341 for (i=0; i < length(clearValue); i++)342 :343 foo = substr(clearValue,i,1)344 sudoku[bR][bC][lR][lC]{couldbe{foo = 0345 346 347 348 349def clearBlockExceptROW():350 my (clearValue,bR,bC,excludelR) = @_351 if (debug)352 :353 print "clearing block exept row, clearValue, from bigRow, bR, bigCol, "354 print "bC, lilRow, excludelR\n"355 356 foreach lR (0,1,2)357 :358 if (lR not = excludelR)359 :360 foreach lC (0,1,2)361 :362 for (i =0; i < length(clearValue); i++)363 :364 foo = substr(clearValue,i,1)365 sudoku[bR][bC][lR][lC]{couldbe{foo = 0366 367 368 369 370def clearBlockExceptCOL():371 my (clearValue,bR,bC,excludelC) = @_372 if (debug)373 :374 print "clearing block exept col, clearValue, from bigRow, bR, bigCol, "375 print "bC, lilCol, excludelC\n"376 377 foreach lR (0,1,2)378 :379 foreach lC (0,1,2)380 :381 if (lC not = excludelC)382 :383 for (i =0; i < length(clearValue); i++)384 :385 foo = substr(clearValue,i,1)386 sudoku[bR][bC][lR][lC]{couldbe{foo = 0387 388 389 390 391def printMatrix():392 my %numbersLeft393 394 if (debug)395 :396 foreach bR (0,1,2)397 :398 foreach lR (0,1,2)399 :400 for(i =0; i<3; i++)401 :402 foreach bC (0,1,2)403 :404 foreach lC (0,1,2)405 :406 if (sudoku[bR][bC][lR][lC]{is not = 0)407 :408 ### if (i == 0 || i == 2)409 ### :410 ### print "***"411 ### 412 ### elsif (i == 1)413 ### :414 ### print "*"+sudoku[bR][bC][lR][lC]{is+"*"415 ### 416 print sudoku[bR][bC][lR][lC]{is+sudoku[bR][bC][lR][lC]{is+sudoku[bR][bC][lR][lC]{is417 418 else419 :420 my @subset421 if (i == 0)422 :423 @subset = (1,2,3)424 425 elsif (i == 1)426 :427 @subset = (4,5,6)428 429 elsif (i == 2)430 :431 @subset = (7,8,9)432 433 foreach i (@subset)434 :435 if(sudoku[bR][bC][lR][lC]{couldbe{i)436 :437 print "i"438 numbersLeft{i++439 440 else441 :442 print "_"443 444 445 446 print " "447 448 449 print " "450 451 print "\n"452 453 print "\n"454 455 print "\n"456 457 foreach i (1,2,3,4,5,6,7,8,9)458 :459 print "i: numbersLeft{i\n"460 461 462 else463 :464 foreach bR (0,1,2)465 :466 foreach lR (0,1,2)467 :468 foreach bC (0,1,2)469 :470 foreach lC (0,1,2)471 :472 if (sudoku[bR][bC][lR][lC]{is not = 0)473 :474 print "sudoku[bR][bC][lR][lC]{is"475 476 else477 :478 print "?"479 480 481 print " "482 483 print " "484 485 print "\n"486 487 print "\n"488 489 490def puzzleSolved():491 # calculate whether the puzzle is solved or not492 if (debug)493 :494 print "checking if puzzle solved+++"495 496 foreach bR (0,1,2)497 :498 foreach bC (0,1,2)499 :500 foreach lR (0,1,2)501 :502 foreach lC (0,1,2)503 :504 foreach i (1,2,3,4,5,6,7,8,9)505 :506 if (sudoku[bR][bC][lR][lC]{couldbe{i not = 0)507 :508 if (debug)509 :510 print " nope\n"511 512 return 0513 514 515 516 517 518 519 if (debug)520 :521 print " YES not \n"522 523 return 1524#=======================525# START526#=======================527@input528foreach bR (0,1,2)529:530 foreach lR (0,1,2)531 :532 foreach bC (0,1,2)533 :534 foreach lC (0,1,2)535 :536 while (#input == -1 | 0)537 :538 chomp(entry = <>)539 @input = split(/ /,entry)540 541 sudoku[bR][bC][lR][lC]{is = shift(@input)542 543 544 545#=======================546# Initialize547#=======================548foreach bR (0,1,2)549:550 foreach bC (0,1,2)551 :552 foreach lR (0,1,2)553 :554 foreach lC (0,1,2)555 :556 if (sudoku[bR][bC][lR][lC]{is not = 0)557 :558 foreach i (1,2,3,4,5,6,7,8,9)559 :560 sudoku[bR][bC][lR][lC]{couldbe{i = 0561 562 563 else564 :565 foreach i (1,2,3,4,5,6,7,8,9)566 :567 sudoku[bR][bC][lR][lC]{couldbe{i = 1568 569 570 571 572 573while ( not puzzleSolved)574:575 iterations++576 changes = 0577 clean()578 # check each ROW for single values579 if (debug) { print "check each ROW for single values\n"; 580 foreach bR (0,1,2)581 :582 foreach lR (0,1,2)583 :584 foreach i (1,2,3,4,5,6,7,8,9)585 :586 answer = 0587 foreach bC (0,1,2)588 :589 foreach lC (0,1,2)590 :591 if (sudoku[bR][bC][lR][lC]{couldbe{i == 1)592 :593 answer += 1594 value = i595 valueBC = bC596 valueLC = lC597 598 599 600 if (answer == 1)601 :602 sudoku[bR][valueBC][lR][valueLC]{is = value603 changes++604 if (debug)605 { 606 print "found ROW answer: "607 print "bR+valueBC+lR+valueLC = value\n"608 printMatrix()609 610 clean()611 612 613 614 615 clean()616 # check each COL for single values617 if (debug) { print "check each COL for single values\n"; 618 foreach bC (0,1,2)619 :620 foreach lC (0,1,2)621 :622 foreach i (1,2,3,4,5,6,7,8,9)623 :624 answer = 0625 foreach bR (0,1,2)626 :627 foreach lR (0,1,2)628 :629 if (sudoku[bR][bC][lR][lC]{couldbe{i == 1)630 :631 answer += 1632 value = i633 valueBR = bR634 valueLR = lR635 636 637 638 if (answer == 1)639 :640 sudoku[valueBR][bC][valueLR][lC]{is = value641 changes++642 if (debug)643 { 644 print "found COL answer: "645 print "valueBR+bC+valueLR+lC = value\n"646 printMatrix()647 648 clean()649 650 651 652 653 # check each COL for BLOCK only values654 if (debug) { print "check each COL for BLOCK only values\n"; 655 foreach bC (0,1,2)656 :657 foreach lC (0,1,2)658 :659 foreach i (1,2,3,4,5,6,7,8,9)660 :661 my %colBlockOnly662 answer = 0663 foreach bR (0,1,2)664 :665 foreach lR (0,1,2)666 :667 if (sudoku[bR][bC][lR][lC]{couldbe{i == 1)668 :669 colBlockOnly{bR = 1670 671 672 673 my @foo = keys %colBlockOnly674 if (#foo == 0)675 :676 print "found COL for BLOCK only, i,foo[0],bC,lC\n"677 clearBlockExceptCOL(i,foo[0],bC,lC)678 clean()679 680 undef %colBlockOnly681 682 683 684 # check each ROW for BLOCK only values685 if (debug) { print "check each ROW for BLOCK only values\n"; 686 foreach bR (0,1,2)687 :688 foreach lR (0,1,2)689 :690 foreach i (1,2,3,4,5,6,7,8,9)691 :692 my %rowBlockOnly693 answer = 0694 foreach bC (0,1,2)695 :696 foreach lC (0,1,2)697 :698 if (sudoku[bR][bC][lR][lC]{couldbe{i == 1)699 :700 rowBlockOnly{bC = 1701 702 703 704 my @foo = keys %rowBlockOnly705 if (#foo == 0)706 :707 print "found ROW for BLOCK only, i,bR,foo[0],lR\n"708 clearBlockExceptROW(i,bR,foo[0],lR)709 clean()710 711 undef %rowBlockOnly712 713 714 715 # check each BLOCK for single values716 if (debug) { print "check each BLOCK for single values\n"; 717 foreach bR (0,1,2)718 :719 foreach bC (0,1,2)720 :721 foreach i (1,2,3,4,5,6,7,8,9)722 :723 answer = 0724 foreach lR (0,1,2)725 :726 foreach lC (0,1,2)727 :728 if (sudoku[bR][bC][lR][lC]{couldbe{i == 1)729 :730 answer += 1731 value = i732 valueLC = lC733 valueLR = lR734 735 736 737 if (answer == 1)738 :739 sudoku[bR][bC][valueLR][valueLC]{is = value740 changes++741 if (debug)742 { 743 print "found BLOCK answer: "744 print "bR+bC+valueLR+valueLC = value\n"745 printMatrix()746 747 clean()748 749 750 751 752 clean()753 markOnlyOneAnswer()754 if (debug) { print "check each ROW for pairs\n"; 755 foreach bR (0,1,2)756 :757 foreach lR (0,1,2)758 :759 my @savedValue760 count = 0761 foreach bC (0,1,2)762 :763 foreach lC (0,1,2)764 :765 answer = 0766 value = ""767 foreach i (1,2,3,4,5,6,7,8,9)768 :769 if (sudoku[bR][bC][lR][lC]{couldbe{i == 1)770 :771 answer += 1772 value = value+i773 774 775 if (answer == 2)776 :777 found = 0778 for (i=0; i <= #savedValue; i++)779 :780 if (value eq savedValue[i])781 :782print "FOUND: #savedValue savedValue[i] value\n"783 found = 1784 785 786 if (found == 0)787 :788 savedValue[count] = value789print "FOUND0: #savedValue savedValue[i] value\n"790 count++791 792 else793 :794 # we have found a "pair"795 if (debug) { print "ROW pair found: bR+bC+lR+lC = value\n"; printMatrix(); 796 clearPairROW(value,bR,lR)797 798 799 800 801 undef @savedValue802 803 804 clean()805 markOnlyOneAnswer()806 if (debug) { print "check each ROW for cell pairs\n"; 807 foreach bR (0,1,2)808 :809 foreach lR (0,1,2)810 :811 my @value812 foreach bC (0,1,2)813 :814 foreach lC (0,1,2)815 :816 answer = 0817 foreach i (1,2,3,4,5,6,7,8,9)818 :819 if (sudoku[bR][bC][lR][lC]{couldbe{i == 1)820 :821 value[i]++822 823 824 825 826 foreach i (1,2,3,4,5,6,7,8,9)827 :828 #### TODO ####829 830 831 832 if (debug) { print "check each COL for pairs\n"; 833 foreach bC (0,1,2)834 :835 foreach lC (0,1,2)836 :837 my @savedValueCOL838 count = 0839 foreach bR (0,1,2)840 :841 foreach lR (0,1,2)842 :843 answer = 0844 value = ""845 foreach i (1,2,3,4,5,6,7,8,9)846 :847 if (sudoku[bR][bC][lR][lC]{couldbe{i == 1)848 :849 answer += 1850 value = value+i851 852 853 if (answer == 2)854 :855 found = 0856 for (i=0; i <= #savedValueCOL; i++)857 :858 if (value eq savedValueCOL[i])859 :860 found = 1861 862 863 if (found == 0)864 :865 savedValueCOL[count] = value866 count++867 868 else869 :870 # we have found a "pair"871 if (debug) { print "COL pair found: bR+bC+lR+lC = value\n"; printMatrix(); 872 clearPairCOL(value,bC,lC)873 874 875 876 877 undef @savedValueCOL878 879 880 clearNumbersOnlyInXCells()881 if (debug)882 :883 printMatrix()884 print "================================================================================\n"885 886 if (changes == 0)887 :888 if (changeIterations++ == 40)889 :890 print "something's hosed+++\n"; exit891 892 893 else894 :895 changeIterations = 0896 897print "Solved in iterations Iterations \n"...
foreach.py
Source:foreach.py
1import json2import os3from collections import defaultdict4from zaf.component.decorator import requires5@requires(zk2='Zk2')6def test_foreach(zk2):7 result = zk2(8 [9 'runcommand',10 'testrunner',11 'testfinder',12 'testscheduler',13 'testresults',14 'textreport',15 'sut',16 ], 'run --suts-ids one --suts-ids two systest.data.suites.test_foreach')17 stdout = result.stdout18 assert (19 'systest.data.suites.test_foreach.'20 'test_foreach_config_entity[s=one]') in stdout, stdout21 assert (22 'systest.data.suites.test_foreach.'23 'test_foreach_config_entity[s=two]') in stdout, stdout24 assert 'systest.data.suites.test_foreach.test_foreach_format[s=_one_]' in stdout, stdout25 assert 'systest.data.suites.test_foreach.test_foreach_format[s=_two_]' in stdout, stdout26 assert (27 'systest.data.suites.test_foreach.'28 'test_foreach_mixed_list_data_with_config_entity[s=one, d=0]') in stdout, stdout29 assert (30 'systest.data.suites.test_foreach.'31 'test_foreach_mixed_list_data_with_config_entity[s=one, d=1]') in stdout, stdout32 assert (33 'systest.data.suites.test_foreach.'34 'test_foreach_mixed_list_data_with_config_entity[s=two, d=0]') in stdout, stdout35 assert (36 'systest.data.suites.test_foreach.'37 'test_foreach_mixed_list_data_with_config_entity[s=two, d=1]') in stdout, stdout38 assert (39 'systest.data.suites.test_foreach.'40 'test_dependency_on_foreached_entity[s=one]') in stdout, stdout41 assert (42 'systest.data.suites.test_foreach.'43 'test_dependency_on_foreached_entity[s=two]') in stdout, stdout44 assert (45 'systest.data.suites.test_foreach.'46 'test_foreached_component_depends_on_can_filtered_entity[scc=one_sut_component]'47 ) in stdout, stdout48 assert (49 'systest.data.suites.test_foreach.'50 'test_foreached_component_depends_on_can_filtered_entity[scc=two_sut_component]'51 ) in stdout, stdout52 assert (53 'systest.data.suites.test_foreach.'54 'test_foreach_argument_component[ac=arg_component1]') in stdout, stdout55 assert (56 'systest.data.suites.test_foreach.'57 'test_foreach_argument_component[ac=arg_component2]') in stdout, stdout58 assert ('systest.data.suites.test_foreach.' 'test_no_parameterization') in stdout, stdout59 assert 'Passed: 14' in stdout, stdout60 assert 'Failed: 1' in stdout, stdout61 assert 'Total: 15' in stdout, stdout62@requires(zk2='Zk2')63@requires(workspace='Workspace')64def test_foreach_with_logs_per_test_case(zk2, workspace):65 zk2(66 [67 'runcommand',68 'testrunner',69 'testfinder',70 'testscheduler',71 'testresults',72 'textreport',73 'sut',74 ],75 '--logdefaults-enabled true --log-dir {workspace} '76 'run --suts-ids one --suts-ids two systest.data.suites.test_foreach'.format(77 workspace=workspace.path))78 log_files = os.listdir(os.path.join(workspace.path, 'testrun'))79 assert 'systest.data.suites.test_foreach.test_foreach_config_entity-s_one.log' in log_files, log_files80 assert 'systest.data.suites.test_foreach.test_foreach_config_entity-s_two.log' in log_files, log_files81 assert 'systest.data.suites.test_foreach.test_foreach_format-s__one_.log' in log_files, log_files82 assert 'systest.data.suites.test_foreach.test_foreach_format-s__two_.log' in log_files, log_files83 assert (84 'systest.data.suites.test_foreach.'85 'test_foreach_mixed_list_data_with_config_entity-s_one-d_0.log') in log_files, log_files86 assert (87 'systest.data.suites.test_foreach.'88 'test_foreach_mixed_list_data_with_config_entity-s_one-d_1.log') in log_files, log_files89 assert (90 'systest.data.suites.test_foreach.'91 'test_foreach_mixed_list_data_with_config_entity-s_two-d_0.log') in log_files, log_files92 assert (93 'systest.data.suites.test_foreach.'94 'test_foreach_mixed_list_data_with_config_entity-s_two-d_1.log') in log_files, log_files95 assert (96 'systest.data.suites.test_foreach.'97 'test_dependency_on_foreached_entity-s_one.log') in log_files, log_files98 assert (99 'systest.data.suites.test_foreach.'100 'test_dependency_on_foreached_entity-s_two.log') in log_files, log_files101 assert (102 'systest.data.suites.test_foreach.'103 'test_foreached_component_depends_on_can_filtered_entity-scc_one_sut_component.log'104 ) in log_files, log_files105 assert (106 'systest.data.suites.test_foreach.'107 'test_foreached_component_depends_on_can_filtered_entity-scc_two_sut_component.log'108 ) in log_files, log_files109 assert (110 'systest.data.suites.test_foreach.'111 'test_foreach_argument_component-ac_arg_component1.log') in log_files, log_files112 assert (113 'systest.data.suites.test_foreach.'114 'test_foreach_argument_component-ac_arg_component2.log') in log_files, log_files115 assert 'systest.data.suites.test_foreach.test_no_parameterization.log' in log_files, log_files116@requires(zk2='Zk2')117@requires(workspace='Workspace')118def test_foreach_with_z2reporter(zk2, workspace):119 z2_report_file = os.path.join(workspace.path, 'report.json')120 zk2(121 [122 'runcommand', 'testrunner', 'testfinder', 'testscheduler', 'testresults', 'textreport',123 'sut', 'z2report'124 ],125 'run '126 '--reports-z2 true '127 '--reports-z2-file {z2_report_file} '128 '--suts-ids one --suts-ids two systest.data.suites.test_foreach'.format(129 z2_report_file=z2_report_file))130 with open(z2_report_file, 'r') as f:131 data = json.loads(f.read())132 params_data = defaultdict(list)133 for tc in data['testCases']:134 params_data[tc['name']].append(tc['params'])135 assert params_data[('systest.data.suites.test_foreach.'136 'test_foreach_config_entity')] == [['s=one'], ['s=two']]137 assert params_data['systest.data.suites.test_foreach.test_foreach_format'] == [138 ['s=_one_'], ['s=_two_']139 ]140 assert params_data[(141 'systest.data.suites.test_foreach.'142 'test_foreach_mixed_list_data_with_config_entity')] == [143 ['s=one', 'd=0'], ['s=one', 'd=1'], ['s=two', 'd=0'], ['s=two', 'd=1']144 ]145 assert params_data[('systest.data.suites.test_foreach.'146 'test_dependency_on_foreached_entity')] == [['s=one'], ['s=two']]147 assert params_data[(148 'systest.data.suites.test_foreach.'149 'test_foreached_component_depends_on_can_filtered_entity')] == [150 ['scc=one_sut_component'], ['scc=two_sut_component']151 ]152 assert params_data[('systest.data.suites.test_foreach.'153 'test_foreach_argument_component')] == [154 ['ac=arg_component1'], ['ac=arg_component2']155 ]...
ForEach.js
Source:ForEach.js
1define([2 '../../Core/defined'3 ], function(4 defined) {5 'use strict';67 /**8 * Contains traversal functions for processing elements of the glTF hierarchy.9 */10 var ForEach = {};1112 ForEach.object = function(arrayOfObjects, handler) {13 if (defined(arrayOfObjects)) {14 for (var i = 0; i < arrayOfObjects.length; i++) {15 var object = arrayOfObjects[i];16 var returnValue = handler(object, i);17 if (typeof returnValue === 'number') {18 i += returnValue;19 }20 else if (returnValue) {21 break;22 }23 }24 }25 };2627 ForEach.topLevel = function(gltf, name, handler) {28 var arrayOfObjects = gltf[name];29 ForEach.object(arrayOfObjects, handler);30 };3132 ForEach.accessor = function(gltf, handler) {33 ForEach.topLevel(gltf, 'accessors', handler);34 };3536 ForEach.accessorWithSemantic = function(gltf, semantic, handler) {37 ForEach.mesh(gltf, function(mesh) {38 ForEach.meshPrimitive(mesh, function(primitive) {39 ForEach.meshPrimitiveAttribute(primitive, function(accessorId, attributeSemantic) {40 if (attributeSemantic.indexOf(semantic) === 0) {41 handler(accessorId, attributeSemantic, primitive);42 }43 });44 });45 });46 };4748 ForEach.animation = function(gltf, handler) {49 ForEach.topLevel(gltf, 'animations', handler);50 };5152 ForEach.animationSampler = function(animation, handler) {53 var samplers = animation.samplers;54 if (defined(samplers)) {55 ForEach.object(samplers, handler);56 }57 };5859 ForEach.buffer = function(gltf, handler) {60 ForEach.topLevel(gltf, 'buffers', handler);61 };6263 ForEach.bufferView = function(gltf, handler) {64 ForEach.topLevel(gltf, 'bufferViews', handler);65 };6667 ForEach.camera = function(gltf, handler) {68 ForEach.topLevel(gltf, 'cameras', handler);69 };7071 ForEach.image = function(gltf, handler) {72 ForEach.topLevel(gltf, 'images', handler);73 };7475 ForEach.material = function(gltf, handler) {76 ForEach.topLevel(gltf, 'materials', handler);77 };7879 ForEach.materialValue = function(material, handler) {80 var values = material.values;81 if (defined(values)) {82 for (var name in values) {83 if (values.hasOwnProperty(name)) {84 handler(values[name], name);85 }86 }87 }88 };8990 ForEach.mesh = function(gltf, handler) {91 ForEach.topLevel(gltf, 'meshes', handler);92 };9394 ForEach.meshPrimitive = function(mesh, handler) {95 var primitives = mesh.primitives;96 if (defined(primitives)) {97 var primitivesLength = primitives.length;98 for (var i = 0; i < primitivesLength; i++) {99 var primitive = primitives[i];100 handler(primitive, i);101 }102 }103 };104105 ForEach.meshPrimitiveAttribute = function(primitive, handler) {106 var attributes = primitive.attributes;107 if (defined(attributes)) {108 for (var semantic in attributes) {109 if (attributes.hasOwnProperty(semantic)) {110 handler(attributes[semantic], semantic);111 }112 }113 }114 };115116 ForEach.meshPrimitiveTargetAttribute = function(primitive, handler) {117 var targets = primitive.targets;118 if (defined(targets)) {119 for (var targetId in targets) {120 if (targets.hasOwnProperty(targetId)) {121 var target = targets[targetId];122 for (var attributeId in target) {123 if (target.hasOwnProperty(attributeId) && attributeId !== 'extras') {124 handler(target[attributeId], attributeId);125 }126 }127 }128 }129 }130 };131132 ForEach.node = function(gltf, handler) {133 ForEach.topLevel(gltf, 'nodes', handler);134 };135136 ForEach.nodeInTree = function(gltf, nodeIds, handler) {137 var nodes = gltf.nodes;138 if (defined(nodes)) {139 for (var i = 0; i < nodeIds.length; i++) {140 var nodeId = nodeIds[i];141 var node = nodes[nodeId];142 if (defined(node)) {143 handler(node, nodeId);144 var children = node.children;145 if (defined(children)) {146 ForEach.nodeInTree(gltf, children, handler);147 }148 }149 }150 }151 };152153 ForEach.nodeInScene = function(gltf, scene, handler) {154 var sceneNodeIds = scene.nodes;155 if (defined(sceneNodeIds)) {156 ForEach.nodeInTree(gltf, sceneNodeIds, handler);157 }158 };159160 ForEach.program = function(gltf, handler) {161 ForEach.topLevel(gltf, 'programs', handler);162 };163164 ForEach.sampler = function(gltf, handler) {165 ForEach.topLevel(gltf, 'samplers', handler);166 };167168 ForEach.scene = function(gltf, handler) {169 ForEach.topLevel(gltf, 'scenes', handler);170 };171172 ForEach.shader = function(gltf, handler) {173 ForEach.topLevel(gltf, 'shaders', handler);174 };175176 ForEach.skin = function(gltf, handler) {177 ForEach.topLevel(gltf, 'skins', handler);178 };179180 ForEach.techniqueAttribute = function(technique, handler) {181 var attributes = technique.attributes;182 if (defined(attributes)) {183 for (var semantic in attributes) {184 if (attributes.hasOwnProperty(semantic)) {185 if (handler(attributes[semantic], semantic)) {186 break;187 }188 }189 }190 }191 };192193 ForEach.techniqueParameter = function(technique, handler) {194 var parameters = technique.parameters;195 if (defined(parameters)) {196 for (var parameterName in parameters) {197 if (parameters.hasOwnProperty(parameterName)) {198 if (handler(parameters[parameterName], parameterName)) {199 break;200 }201 }202 }203 }204 };205206 ForEach.technique = function(gltf, handler) {207 ForEach.topLevel(gltf, 'techniques', handler);208 };209210 ForEach.texture = function(gltf, handler) {211 ForEach.topLevel(gltf, 'textures', handler);212 };213214 return ForEach;
...
d3.node.js
Source:d3.node.js
...31var d3Transition = require('d3-transition');32var d3Voronoi = require('d3-voronoi');33var d3Zoom = require('d3-zoom');34var version = "5.7.0";35Object.keys(d3Array).forEach(function (key) { exports[key] = d3Array[key]; });36Object.keys(d3Axis).forEach(function (key) { exports[key] = d3Axis[key]; });37Object.keys(d3Brush).forEach(function (key) { exports[key] = d3Brush[key]; });38Object.keys(d3Chord).forEach(function (key) { exports[key] = d3Chord[key]; });39Object.keys(d3Collection).forEach(function (key) { exports[key] = d3Collection[key]; });40Object.keys(d3Color).forEach(function (key) { exports[key] = d3Color[key]; });41Object.keys(d3Contour).forEach(function (key) { exports[key] = d3Contour[key]; });42Object.keys(d3Dispatch).forEach(function (key) { exports[key] = d3Dispatch[key]; });43Object.keys(d3Drag).forEach(function (key) { exports[key] = d3Drag[key]; });44Object.keys(d3Dsv).forEach(function (key) { exports[key] = d3Dsv[key]; });45Object.keys(d3Ease).forEach(function (key) { exports[key] = d3Ease[key]; });46Object.keys(d3Fetch).forEach(function (key) { exports[key] = d3Fetch[key]; });47Object.keys(d3Force).forEach(function (key) { exports[key] = d3Force[key]; });48Object.keys(d3Format).forEach(function (key) { exports[key] = d3Format[key]; });49Object.keys(d3Geo).forEach(function (key) { exports[key] = d3Geo[key]; });50Object.keys(d3Hierarchy).forEach(function (key) { exports[key] = d3Hierarchy[key]; });51Object.keys(d3Interpolate).forEach(function (key) { exports[key] = d3Interpolate[key]; });52Object.keys(d3Path).forEach(function (key) { exports[key] = d3Path[key]; });53Object.keys(d3Polygon).forEach(function (key) { exports[key] = d3Polygon[key]; });54Object.keys(d3Quadtree).forEach(function (key) { exports[key] = d3Quadtree[key]; });55Object.keys(d3Random).forEach(function (key) { exports[key] = d3Random[key]; });56Object.keys(d3Scale).forEach(function (key) { exports[key] = d3Scale[key]; });57Object.keys(d3ScaleChromatic).forEach(function (key) { exports[key] = d3ScaleChromatic[key]; });58Object.keys(d3Selection).forEach(function (key) { exports[key] = d3Selection[key]; });59Object.keys(d3Shape).forEach(function (key) { exports[key] = d3Shape[key]; });60Object.keys(d3Time).forEach(function (key) { exports[key] = d3Time[key]; });61Object.keys(d3TimeFormat).forEach(function (key) { exports[key] = d3TimeFormat[key]; });62Object.keys(d3Timer).forEach(function (key) { exports[key] = d3Timer[key]; });63Object.keys(d3Transition).forEach(function (key) { exports[key] = d3Transition[key]; });64Object.keys(d3Voronoi).forEach(function (key) { exports[key] = d3Voronoi[key]; });65Object.keys(d3Zoom).forEach(function (key) { exports[key] = d3Zoom[key]; });66exports.version = version;...
test_foreach.py
Source:test_foreach.py
1from zaf.component.decorator import component, requires2from k2.runner.decorator import foreach3foreach_config_entity_called_with = []4@foreach(s='Sut')5def test_foreach_config_entity(s):6 assert s.entity in ['one', 'two']7 assert s.entity not in foreach_config_entity_called_with, \8 'Has already been called with {entity}'.format(entity=s.entity)9 foreach_config_entity_called_with.append(s.entity)10 if s.entity == 'one':11 assert False, 'Intentionally fail if sut one to illustrate failed tests.'12def format_fn(obj):13 return '_{val}_'.format(val=str(obj))14@foreach(s='Sut', format=format_fn)15def test_foreach_format(s):16 assert s.entity in ['one', 'two']17foreach_mixed_list_data_with_config_entity_called_with = []18@foreach(s='Sut')19@foreach(d=range(2))20def test_foreach_mixed_list_data_with_config_entity(s, d):21 assert d >= 0, d22 assert d < 2, d23 assert s.entity in ['one', 'two']24 assert (s.entity, d) not in foreach_mixed_list_data_with_config_entity_called_with, \25 'Has already been called with {entity} and {data}'.format(entity=s.entity, data=d)26 foreach_mixed_list_data_with_config_entity_called_with.append((s.entity, d))27@component(name='SutComponent')28@requires(sut='Sut')29def sut_component(sut):30 return sut.entity31dependency_on_foreached_entity_called_with = []32@foreach(s='Sut')33@requires(sc='SutComponent', uses=['s'])34def test_dependency_on_foreached_entity(s, sc):35 assert sc in ['one', 'two']36 assert sc not in dependency_on_foreached_entity_called_with, \37 'Has already been called with {entity}'.format(entity=sc)38 dependency_on_foreached_entity_called_with.append(sc)39 assert s not in dependency_on_foreached_entity_called_with, \40 'Has already been called with {sut}'.format(sut=s)41 dependency_on_foreached_entity_called_with.append(s)42@component(name='SutCanComponent')43@requires(s='Sut', can=['one'])44def one_sut_component(s):45 return s.entity46@component(name='SutCanComponent')47@requires(s='Sut', can=['two'])48def two_sut_component(s):49 return s.entity50foreached_component_depends_on_can_filtered_entity_called_with = []51@foreach(scc='SutCanComponent')52def test_foreached_component_depends_on_can_filtered_entity(scc):53 assert scc in ['one', 'two']54 assert scc not in foreached_component_depends_on_can_filtered_entity_called_with, \55 'Has already been called with {item}'.format(item=scc)56 foreached_component_depends_on_can_filtered_entity_called_with.append(scc)57@component(name='ArgumentComponent')58def arg_component1(arg):59 return arg * 160@component(name='ArgumentComponent')61def arg_component2(arg):62 return arg * 263foreach_argument_component_called_with = []64@foreach(ac='ArgumentComponent', args=[1])65def test_foreach_argument_component(ac):66 assert ac in [1, 2]67 assert ac not in foreach_argument_component_called_with, \68 'Has already been called with {ac}'.format(ac=ac)69 foreach_argument_component_called_with.append(ac)70def test_no_parameterization():71 """Plain test should still work."""...
Using AI Code Generation
1const wpt = require('wpt');2var arr = [1, 2, 3, 4, 5];3wpt.forEach(arr, function (element) {4 console.log(element);5});6const wpt = require('wpt');7var arr = [1, 2, 3, 4, 5];8var even = wpt.filter(arr, function (element) {9 return element % 2 == 0;10});11console.log(even);12const wpt = require('wpt');13var arr = [1, 2, 3, 4, 5];14var square = wpt.map(arr, function (element) {15 return element * element;16});17console.log(square);18const wpt = require('wpt');19var arr = [1, 2, 3, 4, 5];20var sum = wpt.reduce(arr, function (accumulator, element) {21 return accumulator + element;22});23console.log(sum);24const wpt = require('wpt');25var arr = [1, 2, 3, 4, 5];26var sum = wpt.reduceRight(arr, function (accumulator, element) {27 return accumulator + element;28});29console.log(sum);30const wpt = require('wpt');31var arr = [1, 2, 3, 4, 5];32if (wpt.includes(arr, 3)) {33 console.log('Array contains 3');34} else {35 console.log('Array does not contain 3');36}37const wpt = require('wpt');38var arr = [1, 2, 3, 4, 5];39var element = wpt.find(arr, function (element) {40 return element > 3;41});42console.log(element);
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3const path = require('path');4const file = fs.readFileSync(path.join(__dirname, 'titles.txt'), 'utf8');5const titles = file.split('\n');6titles.forEach(title => {7 .page(title)8 .get()9 .then(page => {10 const data = page.json();11 console.log(data);12 })13 .catch(err => console.log(err));14});15### wptools.page(title, options)
Using AI Code Generation
1const wptools = require('wptools');2var fs = require('fs');3var file = fs.createWriteStream('data.txt');4file.on('error', function(err) { /* error handling */ });5var pages = ['India','United States','United Kingdom','Australia','Canada','France','Germany','Italy','Japan','China'];6function queryPage(page){7 wptools.page(page)8 .then(function(page) {9 return page.get();10 })11 .then(function(page) {12 file.write(JSON.stringify(page.data));13 file.write('\n');14 })15 .catch(function(err) {16 console.log(err);17 });18}19pages.forEach(queryPage);20file.end();21{22 "extract": "India ( (listen) IN-dlee-ə; Hindustani: Bhārat (listen) [ˈbʱaːɽat̪] (About this soundlisten)), officially the Republic of India (Hindi: Bhārat Gaṇarājya; Urdu: Bhārat Gaṇarājya; Bengali: ভারত গণগণ্য; Tamil: இந்திய குடியரசு; Telugu: భారత గణరాజ్యం; Malayalam: ഭാരത ഗണരാജ്യം; Kannada: ಭಾರತ ಗಣರಾಜ್ಯ; Punjabi: ਭਾਰਤ ਗਣਰਾਜ; Marathi: भारत गणराज्य), is a country in South Asia. It is the seventh-largest country by area, the second-most populous country with over 1.2 billion people, and the most populous democracy in the world
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var category = 'Category:Members_of_the_United_States_House_of_Representatives_from_New_York';4var writeStream = fs.createWriteStream('test.txt');5var pages = [];6var pageIds = [];7wptools.category(category).get(function(err, resp) {8 if (err) {9 console.log(err);10 }11 resp.pages.forEach(function(page) {12 pages.push(page);13 pageIds.push(page.pageid);14 });15 writeStream.write(pageIds.join('\n'));16});
Using AI Code Generation
1var wptools = require('wptools');2var wiki = new wptools.page('Barack Obama');3wiki.get(function(err, data) {4 console.log(data);5});6var WikipediaJS = require('wikipedia-js');7var client = new WikipediaJS({8});9client.searchArticle({10}, function(err, data) {11 console.log(data);12});13{ title: 'Barack Obama',14 extract: 'Barack Hussein Obama II (/ˈbɑːrək huːˈseɪn oʊˈbɑːmə/ ( listen); born August 4, 1961) is an American politician who served as the 44th President of the United States from 2009 to 2017. A member of the Democratic Party, he was the first African American to be elected to the presidency. He previously served as a U.S. senator from Illinois from 2005 to 2008 and an Illinois state senator from 1997 to 2004. Born and raised in Honolulu, Hawaii, Obama is a graduate of Columbia University and Harvard Law School, where he was president of the Harvard Law Review. He was a community organizer in Chicago before earning his law degree. He worked as a civil rights attorney and taught constitutional law at the University of Chicago Law School from 1992 to 2004. He then served three terms representing the 13th District in the Illinois Senate from 1997 until 2004, when he ran for the U.S. Senate. He lost to Republican incumbent Alan Keyes, but won the subsequent election in 2004, defeating Republican nominee Jack Ryan by a narrow margin. He was re-elected to a second term in 2010, defeating Republican nominee and former Illinois Governor, state Treasurer, and U.S. Representative, Mark Kirk. Obama was elected president in 2008, defeating Republican nominee John McCain. Eight years later, in 2016, he became the first U.S. president to be elected to
Using AI Code Generation
1const wptools = require('wptools');2const pageName = 'Narendra Modi';3wptools.getImages(pageName, function (err, images) {4 if (err) {5 console.log(err);6 return;7 }8 console.log(images);9});
Using AI Code Generation
1var button = document.getElementById("addTask");2button.addEventListener("click", function(){3 var task = document.getElementById("task").value;4 wpt.addTask(task);5 wpt.displayTask(task);6});7var deleteButtons = document.getElementsByClassName("delete");8wpt.forEach(deleteButtons, function(button){9 button.addEventListener("click", function(){10 var task = this.getAttribute("data-task");11 wpt.removeTask(task);12 wpt.removeTaskFromPage(task);13 });14});15var editButtons = document.getElementsByClassName("edit");16wpt.forEach(editButtons, function(button){17 button.addEventListener("click", function(){18 var task = this.getAttribute("data-task");19 var taskInput = document.getElementById("task");20 taskInput.value = task;21 button.value = "Update";22 button.addEventListener("click", function(){23 var updatedTask = taskInput.value;24 wpt.removeTask(task);25 wpt.removeTaskFromPage(task);26 wpt.addTask(updatedTask);27 wpt.displayTask(updatedTask);
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!!