From 967d42561b37fee02480d5ce3c4da30fec3d2c02 Mon Sep 17 00:00:00 2001 From: xpetit <32063953+xpetit@users.noreply.github.com> Date: Sun, 4 Apr 2021 23:05:39 +0200 Subject: [PATCH] github.com/01-edu/public/test-go -> github.com/01-edu/go-tests --- test-go/Dockerfile | 24 - test-go/README.md | 22 - test-go/entrypoint.sh | 56 --- test-go/go.mod | 7 - test-go/go.sum | 2 - test-go/lib/base/base.go | 119 ----- test-go/lib/is/is.go | 37 -- test-go/lib/lib.go | 420 ------------------ test-go/solutions/addprimesum_prog/main.go | 29 -- test-go/solutions/alphamirror_prog/main.go | 22 - test-go/solutions/balancedstring_prog/main.go | 31 -- test-go/solutions/boolean_prog/main.go | 14 - test-go/solutions/brackets_prog/main.go | 51 --- test-go/solutions/brainfuck_prog/main.go | 66 --- test-go/solutions/btree.go | 252 ----------- test-go/solutions/cat_prog/main.go | 25 -- test-go/solutions/challenge.go | 190 -------- test-go/solutions/cleanstr_prog/main.go | 16 - test-go/solutions/comcheck_prog/main.go | 21 - test-go/solutions/costumeprofit_prog/main.go | 55 --- test-go/solutions/countdown_prog/main.go | 7 - test-go/solutions/displaya_prog/main.go | 7 - test-go/solutions/displayalpham_prog/main.go | 7 - test-go/solutions/displayalrevm_prog/main.go | 7 - test-go/solutions/displayfile_prog/main.go | 21 - .../solutions/displayfirstparam_prog/main.go | 12 - .../solutions/displaylastparam_prog/main.go | 13 - test-go/solutions/displayz_prog/main.go | 7 - test-go/solutions/doop_prog/main.go | 50 --- test-go/solutions/expandstr_prog/main.go | 24 - test-go/solutions/firstword_prog/main.go | 16 - test-go/solutions/fixthemain_prog/main.go | 47 -- test-go/solutions/flags_prog/main.go | 72 --- test-go/solutions/fprime_prog/main.go | 35 -- test-go/solutions/gcd_prog/main.go | 17 - test-go/solutions/grouping_prog/main.go | 60 --- test-go/solutions/hello_prog/main.go | 7 - test-go/solutions/hiddenp_prog/main.go | 51 --- test-go/solutions/inter_prog/main.go | 25 -- test-go/solutions/ispowerof2_prog/main.go | 19 - test-go/solutions/lastword_prog/main.go | 16 - test-go/solutions/listat.go | 23 - test-go/solutions/listclear.go | 13 - test-go/solutions/listfind.go | 19 - test-go/solutions/listforeach.go | 28 -- test-go/solutions/listforeachif.go | 43 -- test-go/solutions/listlast.go | 15 - test-go/solutions/listmerge.go | 10 - test-go/solutions/listpushback.go | 22 - test-go/solutions/listpushfront.go | 14 - test-go/solutions/listremoveif.go | 19 - test-go/solutions/listreverse.go | 15 - test-go/solutions/listsize.go | 11 - test-go/solutions/listsort.go | 28 -- .../solutions/nbrconvertalpha_prog/main.go | 32 -- test-go/solutions/nenokku_prog/main.go | 32 -- test-go/solutions/onlya_prog/main.go | 7 - test-go/solutions/onlyz_prog/main.go | 7 - test-go/solutions/options_prog/main.go | 50 --- test-go/solutions/paramcount_prog/main.go | 10 - test-go/solutions/piglatin_prog/main.go | 20 - test-go/solutions/pilot_prog/main.go | 22 - test-go/solutions/point_prog/main.go | 22 - test-go/solutions/printalphabet_prog/main.go | 7 - .../solutions/printalphabetalt2_prog/main.go | 8 - .../solutions/printalphabetalt_prog/main.go | 8 - test-go/solutions/printalphabetg_prog/main.go | 7 - test-go/solutions/printalt2_prog/main.go | 7 - test-go/solutions/printalt_prog/main.go | 7 - test-go/solutions/printaltu2_prog/main.go | 7 - test-go/solutions/printaltu_prog/main.go | 7 - test-go/solutions/printbits_prog/main.go | 18 - .../solutions/printchessboard_prog/main.go | 40 -- test-go/solutions/printdigits_prog/main.go | 7 - test-go/solutions/printhex_prog/main.go | 17 - test-go/solutions/printparams_prog/main.go | 12 - .../solutions/printprogramname_prog/main.go | 11 - test-go/solutions/printrevcomb_prog/main.go | 17 - .../printreversealphabet_prog/main.go | 7 - .../printreversealphabetalt2_prog/main.go | 8 - .../printreversealphabetalt_prog/main.go | 8 - .../printreversealphabetg_prog/main.go | 7 - test-go/solutions/printrot_prog/main.go | 33 -- test-go/solutions/raid3_prog/main.go | 87 ---- test-go/solutions/range_prog/main.go | 33 -- test-go/solutions/rectangle_prog/main.go | 64 --- test-go/solutions/repeatalpha_prog/main.go | 22 - test-go/solutions/reverserange_prog/main.go | 33 -- test-go/solutions/reversestrcap_prog/main.go | 21 - test-go/solutions/revparams_prog/main.go | 12 - test-go/solutions/revwstr_prog/main.go | 20 - test-go/solutions/robottoorigin_prog/main.go | 31 -- test-go/solutions/romannumbers_prog/main.go | 66 --- test-go/solutions/rostring_prog/main.go | 31 -- test-go/solutions/rot13_prog/main.go | 28 -- test-go/solutions/rotatevowels_prog/main.go | 37 -- test-go/solutions/rpncalc_prog/main.go | 67 --- test-go/solutions/searchreplace_prog/main.go | 18 - test-go/solutions/sortedlistmerge.go | 16 - test-go/solutions/sortlistinsert.go | 25 -- test-go/solutions/sortparams_prog/main.go | 15 - test-go/solutions/sudoku_prog/main.go | 164 ------- test-go/solutions/switchcase_prog/main.go | 21 - test-go/solutions/tabmult_prog/main.go | 25 -- .../solutions/tetrisoptimizer_prog/board.go | 62 --- .../solutions/tetrisoptimizer_prog/main.go | 26 -- .../tetrisoptimizer_prog/samples/bad00.txt | 4 - .../tetrisoptimizer_prog/samples/bad01.txt | 4 - .../tetrisoptimizer_prog/samples/bad02.txt | 5 - .../tetrisoptimizer_prog/samples/bad03.txt | 4 - .../tetrisoptimizer_prog/samples/bad04.txt | 5 - .../samples/badFormat.txt | 19 - .../samples/good_01-1-2-0.00.txt | 4 - .../samples/good_02-1-4-0.00.txt | 4 - .../samples/good_03-2-4-0.00.txt | 9 - .../samples/good_04-6-6-0.00.txt | 29 -- .../samples/good_05-21-10-0.00.txt | 104 ----- .../samples/good_06-22-10-0.00.txt | 109 ----- .../samples/good_07-26-11-0.00.txt | 129 ------ .../samples/good_08-24-10-0.03.txt | 119 ----- .../samples/good_09-11-7-0.07.txt | 54 --- .../samples/good_10-12-7-0.52.txt | 59 --- .../samples/good_11-12-8-0.83.txt | 59 --- .../samples/good_12-19-9-3.40.txt | 94 ---- .../samples/good_13-23-10-4.72.txt | 114 ----- .../samples/good_14-15-8-7.34.txt | 74 --- .../samples/good_15-26-11-72.22.txt | 129 ------ .../solutions/tetrisoptimizer_prog/solver.go | 35 -- .../tetrisoptimizer_prog/tetrimino.go | 69 --- .../tetrisoptimizer_prog/validation.go | 53 --- test-go/solutions/union_prog/main.go | 28 -- .../solutions/uniqueoccurences_prog/main.go | 27 -- test-go/solutions/wdmatch_prog/main.go | 31 -- test-go/solutions/ztail_prog/main.go | 58 --- test-go/tests/abort_test/main.go | 26 -- test-go/tests/activebits_test/main.go | 26 -- test-go/tests/addprimesum_test/main.go | 28 -- .../tests/advancedsortwordarr_test/main.go | 45 -- test-go/tests/alphacount_test/main.go | 34 -- test-go/tests/alphamirror_test/main.go | 20 - test-go/tests/any_test/main.go | 70 --- test-go/tests/appendrange_test/main.go | 60 --- test-go/tests/atoi_test/main.go | 42 -- test-go/tests/atoibase_test/main.go | 46 -- test-go/tests/balancedstring_test/main.go | 57 --- test-go/tests/basicatoi2_test/main.go | 36 -- test-go/tests/basicatoi_test/main.go | 32 -- test-go/tests/basicjoin_test/main.go | 28 -- test-go/tests/boolean_test/main.go | 15 - test-go/tests/brackets_test/main.go | 42 -- test-go/tests/brainfuck_test/main.go | 22 - test-go/tests/btreeapplybylevel_test/main.go | 23 - test-go/tests/btreeapplyinorder_test/main.go | 34 -- .../tests/btreeapplypostorder_test/main.go | 34 -- test-go/tests/btreeapplypreorder_test/main.go | 34 -- test-go/tests/btreedeletenode_test/main.go | 120 ----- test-go/tests/btreeinsertdata_test/main.go | 126 ------ test-go/tests/btreeisbinary_test/main.go | 110 ----- test-go/tests/btreelevelcount_test/main.go | 94 ---- test-go/tests/btreemax_test/main.go | 95 ---- test-go/tests/btreemin_test/main.go | 95 ---- test-go/tests/btreesearchitem_test/main.go | 87 ---- test-go/tests/btreetransplant_test/main.go | 141 ------ test-go/tests/capitalize_test/main.go | 41 -- test-go/tests/cat_test/main.go | 27 -- test-go/tests/chunk_test/main.go | 60 --- test-go/tests/cleanstr_test/main.go | 20 - test-go/tests/collatzcountdown_test/main.go | 37 -- test-go/tests/comcheck_test/main.go | 22 - test-go/tests/compact_test/main.go | 68 --- test-go/tests/compare_test/main.go | 51 --- test-go/tests/concat_test/main.go | 25 -- test-go/tests/concatparams_test/main.go | 25 -- test-go/tests/convertbase_test/main.go | 62 --- test-go/tests/costumeprofit_test/main.go | 20 - test-go/tests/countdown_test/main.go | 9 - test-go/tests/countif_test/main.go | 76 ---- test-go/tests/displaya_test/main.go | 20 - test-go/tests/displayalpham_test/main.go | 9 - test-go/tests/displayalrevm_test/main.go | 9 - test-go/tests/displayfile_test/main.go | 20 - test-go/tests/displayfirstparam_test/main.go | 19 - test-go/tests/displaylastparam_test/main.go | 19 - test-go/tests/displayz_test/main.go | 21 - test-go/tests/divmod_test/main.go | 25 -- test-go/tests/doop_test/main.go | 40 -- test-go/tests/doppelganger_test/main.go | 54 --- test-go/tests/eightqueens_test/main.go | 88 ---- test-go/tests/enigma_test/main.go | 77 ---- test-go/tests/expandstr_test/main.go | 20 - test-go/tests/fib_test/main.go | 32 -- test-go/tests/fibonacci_test/main.go | 31 -- test-go/tests/findnextprime_test/main.go | 40 -- test-go/tests/findprevprime_test/main.go | 25 -- test-go/tests/firstrune_test/main.go | 25 -- test-go/tests/firstword_test/main.go | 20 - test-go/tests/fixthemain_test/main.go | 9 - test-go/tests/flags_test/main.go | 49 -- test-go/tests/foldint_test/main.go | 66 --- test-go/tests/foreach_test/main.go | 60 --- test-go/tests/fprime_test/main.go | 30 -- test-go/tests/game23_test/main.go | 76 ---- test-go/tests/gcd_test/main.go | 25 -- test-go/tests/grouping_test/main.go | 39 -- test-go/tests/halfcontest_test/main.go | 42 -- test-go/tests/hello_test/main.go | 9 - test-go/tests/hiddenp_test/main.go | 24 - test-go/tests/index_test/main.go | 57 --- test-go/tests/inter_test/main.go | 31 -- test-go/tests/interestingnumber_test/main.go | 39 -- test-go/tests/isalpha_test/main.go | 36 -- test-go/tests/isanagram_test/main.go | 60 --- test-go/tests/islower_test/main.go | 45 -- test-go/tests/isnegative_test/main.go | 29 -- test-go/tests/isnumeric_test/main.go | 39 -- test-go/tests/ispowerof2_test/main.go | 27 -- test-go/tests/isprime_test/main.go | 33 -- test-go/tests/isprintable_test/main.go | 58 --- test-go/tests/issorted_test/main.go | 122 ----- test-go/tests/isupper_test/main.go | 47 -- test-go/tests/iterativefactorial_test/main.go | 33 -- test-go/tests/iterativepower_test/main.go | 29 -- test-go/tests/itoa_test/main.go | 15 - test-go/tests/itoabase_test/main.go | 31 -- test-go/tests/join_test/main.go | 32 -- test-go/tests/lastrune_test/main.go | 26 -- test-go/tests/lastword_test/main.go | 23 - test-go/tests/lcm_test/main.go | 39 -- test-go/tests/listat_test/main.go | 98 ---- test-go/tests/listclear_test/main.go | 85 ---- test-go/tests/listfind_test/main.go | 81 ---- test-go/tests/listforeach_test/main.go | 102 ----- test-go/tests/listforeachif_test/main.go | 149 ------- test-go/tests/listlast_test/main.go | 81 ---- test-go/tests/listmerge_test/main.go | 138 ------ test-go/tests/listpushback_test/main.go | 67 --- test-go/tests/listpushfront_test/main.go | 69 --- test-go/tests/listremoveif_test/main.go | 109 ----- test-go/tests/listreverse_test/main.go | 90 ---- test-go/tests/listsize_test/main.go | 63 --- test-go/tests/listsort_test/main.go | 96 ---- test-go/tests/makerange_test/main.go | 61 --- test-go/tests/map_test/main.go | 55 --- test-go/tests/max_test/main.go | 27 -- test-go/tests/nauuo_test/main.go | 59 --- test-go/tests/nbrconvertalpha_test/main.go | 31 -- test-go/tests/nenokku_test/main.go | 43 -- test-go/tests/nrune_test/main.go | 51 --- test-go/tests/onlya_test/main.go | 9 - test-go/tests/onlyz_test/main.go | 9 - test-go/tests/options_test/main.go | 34 -- test-go/tests/paramcount_test/main.go | 35 -- test-go/tests/piglatin_test/main.go | 20 - test-go/tests/pilot_test/main.go | 7 - test-go/tests/point_test/main.go | 9 - test-go/tests/pointone_test/main.go | 19 - test-go/tests/printalphabet_test/main.go | 9 - test-go/tests/printalphabetalt2_test/main.go | 9 - test-go/tests/printalphabetalt_test/main.go | 9 - test-go/tests/printalphabetg_test/main.go | 9 - test-go/tests/printalt2_test/main.go | 9 - test-go/tests/printalt_test/main.go | 9 - test-go/tests/printaltu2_test/main.go | 9 - test-go/tests/printaltu_test/main.go | 9 - test-go/tests/printbits_test/main.go | 26 -- test-go/tests/printchessboard_test/main.go | 30 -- test-go/tests/printcomb2_test/main.go | 25 -- test-go/tests/printcomb_test/main.go | 27 -- test-go/tests/printcombn_test/main.go | 77 ---- test-go/tests/printdigits_test/main.go | 9 - test-go/tests/printhex_test/main.go | 26 -- test-go/tests/printmemory_test/main.go | 100 ----- test-go/tests/printnbr_test/main.go | 24 - test-go/tests/printnbrbase_test/main.go | 71 --- test-go/tests/printnbrinorder_test/main.go | 47 -- test-go/tests/printparams_test/main.go | 14 - test-go/tests/printprogramname_test/main.go | 30 -- test-go/tests/printrevcomb_test/main.go | 9 - .../tests/printreversealphabet_test/main.go | 9 - .../printreversealphabetalt2_test/main.go | 9 - .../printreversealphabetalt_test/main.go | 9 - .../tests/printreversealphabetg_test/main.go | 9 - test-go/tests/printrot_test/main.go | 45 -- test-go/tests/printstr_test/main.go | 20 - test-go/tests/printwordstables_test/main.go | 28 -- test-go/tests/priorprime_test/main.go | 38 -- test-go/tests/quada_test/main.go | 73 --- test-go/tests/quadb_test/main.go | 73 --- test-go/tests/quadc_test/main.go | 73 --- test-go/tests/quadd_test/main.go | 73 --- test-go/tests/quade_test/main.go | 73 --- test-go/tests/raid3_test/main.go | 54 --- test-go/tests/range_test/main.go | 21 - test-go/tests/reachablenumber_test/main.go | 39 -- test-go/tests/rectangle_test/main.go | 9 - test-go/tests/recursivefactorial_test/main.go | 33 -- test-go/tests/recursivepower_test/main.go | 28 -- test-go/tests/reduceint_test/main.go | 52 --- test-go/tests/repeatalpha_test/main.go | 27 -- test-go/tests/reversebits_test/main.go | 40 -- test-go/tests/reverserange_test/main.go | 21 - test-go/tests/reversestrcap_test/main.go | 22 - test-go/tests/revivethreenums_test/main.go | 60 --- test-go/tests/revparams_test/main.go | 10 - test-go/tests/revwstr_test/main.go | 33 -- test-go/tests/robottoorigin_test/main.go | 20 - test-go/tests/romannumbers_test/main.go | 24 - test-go/tests/rostring_test/main.go | 22 - test-go/tests/rot13_test/main.go | 18 - test-go/tests/rot14_test/main.go | 47 -- test-go/tests/rotatevowels_test/main.go | 25 -- test-go/tests/rpncalc_test/main.go | 30 -- test-go/tests/searchreplace_test/main.go | 49 -- test-go/tests/slice_test/main.go | 86 ---- test-go/tests/sortedlistmerge_test/main.go | 111 ----- test-go/tests/sortintegertable_test/main.go | 34 -- test-go/tests/sortlistinsert_test/main.go | 141 ------ test-go/tests/sortparams_test/main.go | 9 - test-go/tests/sortwordarr_test/main.go | 40 -- test-go/tests/split_test/main.go | 46 -- test-go/tests/splitwhitespaces_test/main.go | 21 - test-go/tests/sqrt_test/main.go | 39 -- test-go/tests/strlen_test/main.go | 30 -- test-go/tests/strrev_test/main.go | 31 -- test-go/tests/sudoku_test/main.go | 298 ------------- test-go/tests/swap_test/main.go | 25 -- test-go/tests/swapbits_test/main.go | 39 -- test-go/tests/sweetproblem_test/main.go | 98 ---- test-go/tests/switchcase_test/main.go | 16 - test-go/tests/tabmult_test/main.go | 21 - test-go/tests/tetrisoptimizer_test/main.go | 166 ------- test-go/tests/tolower_test/main.go | 16 - test-go/tests/toupper_test/main.go | 16 - test-go/tests/trimatoi_test/main.go | 73 --- test-go/tests/twosum_test/main.go | 28 -- test-go/tests/ultimatedivmod_test/main.go | 27 -- test-go/tests/ultimatepointone_test/main.go | 17 - test-go/tests/union_test/main.go | 27 -- test-go/tests/uniqueoccurences_test/main.go | 22 - test-go/tests/unmatch_test/main.go | 43 -- test-go/tests/volumechanger_test/main.go | 36 -- test-go/tests/wdmatch_test/main.go | 21 - test-go/tests/ztail_test/main.go | 29 -- 343 files changed, 14185 deletions(-) delete mode 100644 test-go/Dockerfile delete mode 100644 test-go/README.md delete mode 100755 test-go/entrypoint.sh delete mode 100644 test-go/go.mod delete mode 100644 test-go/go.sum delete mode 100644 test-go/lib/base/base.go delete mode 100644 test-go/lib/is/is.go delete mode 100644 test-go/lib/lib.go delete mode 100644 test-go/solutions/addprimesum_prog/main.go delete mode 100644 test-go/solutions/alphamirror_prog/main.go delete mode 100644 test-go/solutions/balancedstring_prog/main.go delete mode 100644 test-go/solutions/boolean_prog/main.go delete mode 100644 test-go/solutions/brackets_prog/main.go delete mode 100644 test-go/solutions/brainfuck_prog/main.go delete mode 100644 test-go/solutions/btree.go delete mode 100644 test-go/solutions/cat_prog/main.go delete mode 100644 test-go/solutions/challenge.go delete mode 100644 test-go/solutions/cleanstr_prog/main.go delete mode 100644 test-go/solutions/comcheck_prog/main.go delete mode 100644 test-go/solutions/costumeprofit_prog/main.go delete mode 100644 test-go/solutions/countdown_prog/main.go delete mode 100644 test-go/solutions/displaya_prog/main.go delete mode 100644 test-go/solutions/displayalpham_prog/main.go delete mode 100644 test-go/solutions/displayalrevm_prog/main.go delete mode 100644 test-go/solutions/displayfile_prog/main.go delete mode 100644 test-go/solutions/displayfirstparam_prog/main.go delete mode 100644 test-go/solutions/displaylastparam_prog/main.go delete mode 100644 test-go/solutions/displayz_prog/main.go delete mode 100644 test-go/solutions/doop_prog/main.go delete mode 100644 test-go/solutions/expandstr_prog/main.go delete mode 100644 test-go/solutions/firstword_prog/main.go delete mode 100644 test-go/solutions/fixthemain_prog/main.go delete mode 100644 test-go/solutions/flags_prog/main.go delete mode 100644 test-go/solutions/fprime_prog/main.go delete mode 100644 test-go/solutions/gcd_prog/main.go delete mode 100644 test-go/solutions/grouping_prog/main.go delete mode 100644 test-go/solutions/hello_prog/main.go delete mode 100644 test-go/solutions/hiddenp_prog/main.go delete mode 100644 test-go/solutions/inter_prog/main.go delete mode 100644 test-go/solutions/ispowerof2_prog/main.go delete mode 100644 test-go/solutions/lastword_prog/main.go delete mode 100644 test-go/solutions/listat.go delete mode 100644 test-go/solutions/listclear.go delete mode 100644 test-go/solutions/listfind.go delete mode 100644 test-go/solutions/listforeach.go delete mode 100644 test-go/solutions/listforeachif.go delete mode 100644 test-go/solutions/listlast.go delete mode 100644 test-go/solutions/listmerge.go delete mode 100644 test-go/solutions/listpushback.go delete mode 100644 test-go/solutions/listpushfront.go delete mode 100644 test-go/solutions/listremoveif.go delete mode 100644 test-go/solutions/listreverse.go delete mode 100644 test-go/solutions/listsize.go delete mode 100644 test-go/solutions/listsort.go delete mode 100644 test-go/solutions/nbrconvertalpha_prog/main.go delete mode 100644 test-go/solutions/nenokku_prog/main.go delete mode 100644 test-go/solutions/onlya_prog/main.go delete mode 100644 test-go/solutions/onlyz_prog/main.go delete mode 100644 test-go/solutions/options_prog/main.go delete mode 100644 test-go/solutions/paramcount_prog/main.go delete mode 100644 test-go/solutions/piglatin_prog/main.go delete mode 100644 test-go/solutions/pilot_prog/main.go delete mode 100644 test-go/solutions/point_prog/main.go delete mode 100644 test-go/solutions/printalphabet_prog/main.go delete mode 100644 test-go/solutions/printalphabetalt2_prog/main.go delete mode 100644 test-go/solutions/printalphabetalt_prog/main.go delete mode 100644 test-go/solutions/printalphabetg_prog/main.go delete mode 100644 test-go/solutions/printalt2_prog/main.go delete mode 100644 test-go/solutions/printalt_prog/main.go delete mode 100644 test-go/solutions/printaltu2_prog/main.go delete mode 100644 test-go/solutions/printaltu_prog/main.go delete mode 100644 test-go/solutions/printbits_prog/main.go delete mode 100644 test-go/solutions/printchessboard_prog/main.go delete mode 100644 test-go/solutions/printdigits_prog/main.go delete mode 100644 test-go/solutions/printhex_prog/main.go delete mode 100644 test-go/solutions/printparams_prog/main.go delete mode 100644 test-go/solutions/printprogramname_prog/main.go delete mode 100644 test-go/solutions/printrevcomb_prog/main.go delete mode 100644 test-go/solutions/printreversealphabet_prog/main.go delete mode 100644 test-go/solutions/printreversealphabetalt2_prog/main.go delete mode 100644 test-go/solutions/printreversealphabetalt_prog/main.go delete mode 100644 test-go/solutions/printreversealphabetg_prog/main.go delete mode 100644 test-go/solutions/printrot_prog/main.go delete mode 100644 test-go/solutions/raid3_prog/main.go delete mode 100644 test-go/solutions/range_prog/main.go delete mode 100644 test-go/solutions/rectangle_prog/main.go delete mode 100644 test-go/solutions/repeatalpha_prog/main.go delete mode 100644 test-go/solutions/reverserange_prog/main.go delete mode 100644 test-go/solutions/reversestrcap_prog/main.go delete mode 100644 test-go/solutions/revparams_prog/main.go delete mode 100644 test-go/solutions/revwstr_prog/main.go delete mode 100644 test-go/solutions/robottoorigin_prog/main.go delete mode 100644 test-go/solutions/romannumbers_prog/main.go delete mode 100644 test-go/solutions/rostring_prog/main.go delete mode 100644 test-go/solutions/rot13_prog/main.go delete mode 100644 test-go/solutions/rotatevowels_prog/main.go delete mode 100644 test-go/solutions/rpncalc_prog/main.go delete mode 100644 test-go/solutions/searchreplace_prog/main.go delete mode 100644 test-go/solutions/sortedlistmerge.go delete mode 100644 test-go/solutions/sortlistinsert.go delete mode 100644 test-go/solutions/sortparams_prog/main.go delete mode 100644 test-go/solutions/sudoku_prog/main.go delete mode 100644 test-go/solutions/switchcase_prog/main.go delete mode 100644 test-go/solutions/tabmult_prog/main.go delete mode 100644 test-go/solutions/tetrisoptimizer_prog/board.go delete mode 100644 test-go/solutions/tetrisoptimizer_prog/main.go delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/bad00.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/bad01.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/bad02.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/bad03.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/bad04.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/badFormat.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_01-1-2-0.00.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_02-1-4-0.00.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_03-2-4-0.00.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_04-6-6-0.00.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_05-21-10-0.00.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_06-22-10-0.00.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_07-26-11-0.00.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_08-24-10-0.03.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_09-11-7-0.07.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_10-12-7-0.52.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_11-12-8-0.83.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_12-19-9-3.40.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_13-23-10-4.72.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_14-15-8-7.34.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/samples/good_15-26-11-72.22.txt delete mode 100644 test-go/solutions/tetrisoptimizer_prog/solver.go delete mode 100644 test-go/solutions/tetrisoptimizer_prog/tetrimino.go delete mode 100644 test-go/solutions/tetrisoptimizer_prog/validation.go delete mode 100644 test-go/solutions/union_prog/main.go delete mode 100644 test-go/solutions/uniqueoccurences_prog/main.go delete mode 100644 test-go/solutions/wdmatch_prog/main.go delete mode 100644 test-go/solutions/ztail_prog/main.go delete mode 100644 test-go/tests/abort_test/main.go delete mode 100644 test-go/tests/activebits_test/main.go delete mode 100644 test-go/tests/addprimesum_test/main.go delete mode 100644 test-go/tests/advancedsortwordarr_test/main.go delete mode 100644 test-go/tests/alphacount_test/main.go delete mode 100644 test-go/tests/alphamirror_test/main.go delete mode 100644 test-go/tests/any_test/main.go delete mode 100644 test-go/tests/appendrange_test/main.go delete mode 100644 test-go/tests/atoi_test/main.go delete mode 100644 test-go/tests/atoibase_test/main.go delete mode 100644 test-go/tests/balancedstring_test/main.go delete mode 100644 test-go/tests/basicatoi2_test/main.go delete mode 100644 test-go/tests/basicatoi_test/main.go delete mode 100644 test-go/tests/basicjoin_test/main.go delete mode 100644 test-go/tests/boolean_test/main.go delete mode 100644 test-go/tests/brackets_test/main.go delete mode 100644 test-go/tests/brainfuck_test/main.go delete mode 100644 test-go/tests/btreeapplybylevel_test/main.go delete mode 100644 test-go/tests/btreeapplyinorder_test/main.go delete mode 100644 test-go/tests/btreeapplypostorder_test/main.go delete mode 100644 test-go/tests/btreeapplypreorder_test/main.go delete mode 100644 test-go/tests/btreedeletenode_test/main.go delete mode 100644 test-go/tests/btreeinsertdata_test/main.go delete mode 100644 test-go/tests/btreeisbinary_test/main.go delete mode 100644 test-go/tests/btreelevelcount_test/main.go delete mode 100644 test-go/tests/btreemax_test/main.go delete mode 100644 test-go/tests/btreemin_test/main.go delete mode 100644 test-go/tests/btreesearchitem_test/main.go delete mode 100644 test-go/tests/btreetransplant_test/main.go delete mode 100644 test-go/tests/capitalize_test/main.go delete mode 100644 test-go/tests/cat_test/main.go delete mode 100644 test-go/tests/chunk_test/main.go delete mode 100644 test-go/tests/cleanstr_test/main.go delete mode 100644 test-go/tests/collatzcountdown_test/main.go delete mode 100644 test-go/tests/comcheck_test/main.go delete mode 100644 test-go/tests/compact_test/main.go delete mode 100644 test-go/tests/compare_test/main.go delete mode 100644 test-go/tests/concat_test/main.go delete mode 100644 test-go/tests/concatparams_test/main.go delete mode 100644 test-go/tests/convertbase_test/main.go delete mode 100644 test-go/tests/costumeprofit_test/main.go delete mode 100644 test-go/tests/countdown_test/main.go delete mode 100644 test-go/tests/countif_test/main.go delete mode 100644 test-go/tests/displaya_test/main.go delete mode 100644 test-go/tests/displayalpham_test/main.go delete mode 100644 test-go/tests/displayalrevm_test/main.go delete mode 100644 test-go/tests/displayfile_test/main.go delete mode 100644 test-go/tests/displayfirstparam_test/main.go delete mode 100644 test-go/tests/displaylastparam_test/main.go delete mode 100644 test-go/tests/displayz_test/main.go delete mode 100644 test-go/tests/divmod_test/main.go delete mode 100644 test-go/tests/doop_test/main.go delete mode 100644 test-go/tests/doppelganger_test/main.go delete mode 100644 test-go/tests/eightqueens_test/main.go delete mode 100644 test-go/tests/enigma_test/main.go delete mode 100644 test-go/tests/expandstr_test/main.go delete mode 100644 test-go/tests/fib_test/main.go delete mode 100644 test-go/tests/fibonacci_test/main.go delete mode 100644 test-go/tests/findnextprime_test/main.go delete mode 100644 test-go/tests/findprevprime_test/main.go delete mode 100644 test-go/tests/firstrune_test/main.go delete mode 100644 test-go/tests/firstword_test/main.go delete mode 100644 test-go/tests/fixthemain_test/main.go delete mode 100644 test-go/tests/flags_test/main.go delete mode 100644 test-go/tests/foldint_test/main.go delete mode 100644 test-go/tests/foreach_test/main.go delete mode 100644 test-go/tests/fprime_test/main.go delete mode 100644 test-go/tests/game23_test/main.go delete mode 100644 test-go/tests/gcd_test/main.go delete mode 100644 test-go/tests/grouping_test/main.go delete mode 100644 test-go/tests/halfcontest_test/main.go delete mode 100644 test-go/tests/hello_test/main.go delete mode 100644 test-go/tests/hiddenp_test/main.go delete mode 100644 test-go/tests/index_test/main.go delete mode 100644 test-go/tests/inter_test/main.go delete mode 100644 test-go/tests/interestingnumber_test/main.go delete mode 100644 test-go/tests/isalpha_test/main.go delete mode 100644 test-go/tests/isanagram_test/main.go delete mode 100644 test-go/tests/islower_test/main.go delete mode 100644 test-go/tests/isnegative_test/main.go delete mode 100644 test-go/tests/isnumeric_test/main.go delete mode 100644 test-go/tests/ispowerof2_test/main.go delete mode 100644 test-go/tests/isprime_test/main.go delete mode 100644 test-go/tests/isprintable_test/main.go delete mode 100644 test-go/tests/issorted_test/main.go delete mode 100644 test-go/tests/isupper_test/main.go delete mode 100644 test-go/tests/iterativefactorial_test/main.go delete mode 100644 test-go/tests/iterativepower_test/main.go delete mode 100644 test-go/tests/itoa_test/main.go delete mode 100644 test-go/tests/itoabase_test/main.go delete mode 100644 test-go/tests/join_test/main.go delete mode 100644 test-go/tests/lastrune_test/main.go delete mode 100644 test-go/tests/lastword_test/main.go delete mode 100644 test-go/tests/lcm_test/main.go delete mode 100644 test-go/tests/listat_test/main.go delete mode 100644 test-go/tests/listclear_test/main.go delete mode 100644 test-go/tests/listfind_test/main.go delete mode 100644 test-go/tests/listforeach_test/main.go delete mode 100644 test-go/tests/listforeachif_test/main.go delete mode 100644 test-go/tests/listlast_test/main.go delete mode 100644 test-go/tests/listmerge_test/main.go delete mode 100644 test-go/tests/listpushback_test/main.go delete mode 100644 test-go/tests/listpushfront_test/main.go delete mode 100644 test-go/tests/listremoveif_test/main.go delete mode 100644 test-go/tests/listreverse_test/main.go delete mode 100644 test-go/tests/listsize_test/main.go delete mode 100644 test-go/tests/listsort_test/main.go delete mode 100644 test-go/tests/makerange_test/main.go delete mode 100644 test-go/tests/map_test/main.go delete mode 100644 test-go/tests/max_test/main.go delete mode 100644 test-go/tests/nauuo_test/main.go delete mode 100644 test-go/tests/nbrconvertalpha_test/main.go delete mode 100644 test-go/tests/nenokku_test/main.go delete mode 100644 test-go/tests/nrune_test/main.go delete mode 100644 test-go/tests/onlya_test/main.go delete mode 100644 test-go/tests/onlyz_test/main.go delete mode 100644 test-go/tests/options_test/main.go delete mode 100644 test-go/tests/paramcount_test/main.go delete mode 100644 test-go/tests/piglatin_test/main.go delete mode 100644 test-go/tests/pilot_test/main.go delete mode 100644 test-go/tests/point_test/main.go delete mode 100644 test-go/tests/pointone_test/main.go delete mode 100644 test-go/tests/printalphabet_test/main.go delete mode 100644 test-go/tests/printalphabetalt2_test/main.go delete mode 100644 test-go/tests/printalphabetalt_test/main.go delete mode 100644 test-go/tests/printalphabetg_test/main.go delete mode 100644 test-go/tests/printalt2_test/main.go delete mode 100644 test-go/tests/printalt_test/main.go delete mode 100644 test-go/tests/printaltu2_test/main.go delete mode 100644 test-go/tests/printaltu_test/main.go delete mode 100644 test-go/tests/printbits_test/main.go delete mode 100644 test-go/tests/printchessboard_test/main.go delete mode 100644 test-go/tests/printcomb2_test/main.go delete mode 100644 test-go/tests/printcomb_test/main.go delete mode 100644 test-go/tests/printcombn_test/main.go delete mode 100644 test-go/tests/printdigits_test/main.go delete mode 100644 test-go/tests/printhex_test/main.go delete mode 100644 test-go/tests/printmemory_test/main.go delete mode 100644 test-go/tests/printnbr_test/main.go delete mode 100644 test-go/tests/printnbrbase_test/main.go delete mode 100644 test-go/tests/printnbrinorder_test/main.go delete mode 100644 test-go/tests/printparams_test/main.go delete mode 100644 test-go/tests/printprogramname_test/main.go delete mode 100644 test-go/tests/printrevcomb_test/main.go delete mode 100644 test-go/tests/printreversealphabet_test/main.go delete mode 100644 test-go/tests/printreversealphabetalt2_test/main.go delete mode 100644 test-go/tests/printreversealphabetalt_test/main.go delete mode 100644 test-go/tests/printreversealphabetg_test/main.go delete mode 100644 test-go/tests/printrot_test/main.go delete mode 100644 test-go/tests/printstr_test/main.go delete mode 100644 test-go/tests/printwordstables_test/main.go delete mode 100644 test-go/tests/priorprime_test/main.go delete mode 100644 test-go/tests/quada_test/main.go delete mode 100644 test-go/tests/quadb_test/main.go delete mode 100644 test-go/tests/quadc_test/main.go delete mode 100644 test-go/tests/quadd_test/main.go delete mode 100644 test-go/tests/quade_test/main.go delete mode 100644 test-go/tests/raid3_test/main.go delete mode 100644 test-go/tests/range_test/main.go delete mode 100644 test-go/tests/reachablenumber_test/main.go delete mode 100644 test-go/tests/rectangle_test/main.go delete mode 100644 test-go/tests/recursivefactorial_test/main.go delete mode 100644 test-go/tests/recursivepower_test/main.go delete mode 100644 test-go/tests/reduceint_test/main.go delete mode 100644 test-go/tests/repeatalpha_test/main.go delete mode 100644 test-go/tests/reversebits_test/main.go delete mode 100644 test-go/tests/reverserange_test/main.go delete mode 100644 test-go/tests/reversestrcap_test/main.go delete mode 100644 test-go/tests/revivethreenums_test/main.go delete mode 100644 test-go/tests/revparams_test/main.go delete mode 100644 test-go/tests/revwstr_test/main.go delete mode 100644 test-go/tests/robottoorigin_test/main.go delete mode 100644 test-go/tests/romannumbers_test/main.go delete mode 100644 test-go/tests/rostring_test/main.go delete mode 100644 test-go/tests/rot13_test/main.go delete mode 100644 test-go/tests/rot14_test/main.go delete mode 100644 test-go/tests/rotatevowels_test/main.go delete mode 100644 test-go/tests/rpncalc_test/main.go delete mode 100644 test-go/tests/searchreplace_test/main.go delete mode 100644 test-go/tests/slice_test/main.go delete mode 100644 test-go/tests/sortedlistmerge_test/main.go delete mode 100644 test-go/tests/sortintegertable_test/main.go delete mode 100644 test-go/tests/sortlistinsert_test/main.go delete mode 100644 test-go/tests/sortparams_test/main.go delete mode 100644 test-go/tests/sortwordarr_test/main.go delete mode 100644 test-go/tests/split_test/main.go delete mode 100644 test-go/tests/splitwhitespaces_test/main.go delete mode 100644 test-go/tests/sqrt_test/main.go delete mode 100644 test-go/tests/strlen_test/main.go delete mode 100644 test-go/tests/strrev_test/main.go delete mode 100644 test-go/tests/sudoku_test/main.go delete mode 100644 test-go/tests/swap_test/main.go delete mode 100644 test-go/tests/swapbits_test/main.go delete mode 100644 test-go/tests/sweetproblem_test/main.go delete mode 100644 test-go/tests/switchcase_test/main.go delete mode 100644 test-go/tests/tabmult_test/main.go delete mode 100644 test-go/tests/tetrisoptimizer_test/main.go delete mode 100644 test-go/tests/tolower_test/main.go delete mode 100644 test-go/tests/toupper_test/main.go delete mode 100644 test-go/tests/trimatoi_test/main.go delete mode 100644 test-go/tests/twosum_test/main.go delete mode 100644 test-go/tests/ultimatedivmod_test/main.go delete mode 100644 test-go/tests/ultimatepointone_test/main.go delete mode 100644 test-go/tests/union_test/main.go delete mode 100644 test-go/tests/uniqueoccurences_test/main.go delete mode 100644 test-go/tests/unmatch_test/main.go delete mode 100644 test-go/tests/volumechanger_test/main.go delete mode 100644 test-go/tests/wdmatch_test/main.go delete mode 100644 test-go/tests/ztail_test/main.go diff --git a/test-go/Dockerfile b/test-go/Dockerfile deleted file mode 100644 index 0c3199a46..000000000 --- a/test-go/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -FROM docker.01-edu.org/golang:1.16.3-alpine3.13 - -ENV GIT_TERMINAL_PROMPT=0 -RUN apk add --no-cache git - -RUN go get golang.org/x/tools/cmd/goimports -RUN go get github.com/01-edu/rc - -WORKDIR /piscine-go -RUN go mod init piscine-go -RUN go get github.com/01-edu/z01@v0.1.0 - -WORKDIR /public/test-go -COPY go.* ./ -RUN go mod download -COPY lib lib -COPY solutions solutions -COPY tests tests -RUN go install $(grep -rl ChallengeMain ./tests | rev | cut -d/ -f2- | rev) - -RUN rm -rf /piscine-go - -COPY entrypoint.sh /usr/local/bin -ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/test-go/README.md b/test-go/README.md deleted file mode 100644 index c9e11c485..000000000 --- a/test-go/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# Tests - -To run the tests make sure the two repositories are right next to each other: - -- github.com/01-edu/piscine-go -- github.com/01-edu/public - -To test an exercise, run this command in this folder (`public/test-go`): - -``` -go run github.com/01-edu/public/test-go/tests/isnegative_test -``` - -Relative paths work anywhere in `public/test-go`: - -``` -go run ./tests/printalphabet_test -cd tests -go run ./isnegative_test -``` - -No output means success. diff --git a/test-go/entrypoint.sh b/test-go/entrypoint.sh deleted file mode 100755 index f22ba75d6..000000000 --- a/test-go/entrypoint.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh - -set -e - -cp -r /public . -cp -a student piscine-go -cd piscine-go - -if test "$EXAM_MODE"; then - go mod init main 2>/dev/null - GOSUMDB=off go get github.com/01-edu/z01@v0.1.0 2>/dev/null -fi - -if test "$EXAM_RUN_ONLY" = true; then - go build -o exe "./$EXERCISE" - ./exe "$@" - exit -fi - -if ! test "$EXAM_MODE"; then - s=$(goimports -d .) - if test "$s"; then - echo 'Your Go files are not correctly formatted :' - echo - echo '$ goimports -d .' - echo "$s" - exit 1 - fi -fi - -if ! find . -type f -name '*.go' | grep -q .; then - echo "Missing Go file: $FILE" - exit 1 -fi - -if find . -type f -name '*.go' -exec grep -qE 'print(ln)?\(' {} +; then - echo "Your Go files cannot use print & println builtins" - exit 1 -fi - -# Check restrictions -if test "$ALLOWED_FUNCTIONS" && test "$FILE"; then - # shellcheck disable=SC2086 - rc "$FILE" $ALLOWED_FUNCTIONS -fi - -cd ~/public/test-go - -# Compile and run test -if command -v "${EXERCISE}_test" >/dev/null 2>&1; then - # The exercise is a program - "${EXERCISE}_test" -else - # The exercise is a function - go run "./tests/${EXERCISE}_test" -fi diff --git a/test-go/go.mod b/test-go/go.mod deleted file mode 100644 index 414ddaec1..000000000 --- a/test-go/go.mod +++ /dev/null @@ -1,7 +0,0 @@ -module github.com/01-edu/public/test-go - -go 1.16 - -require student v0.0.0 - -replace student => ../../piscine-go diff --git a/test-go/go.sum b/test-go/go.sum deleted file mode 100644 index 5789f5c36..000000000 --- a/test-go/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/01-edu/z01 v0.1.0 h1:Rr1p92CKYXUgVFw872iGDABXpdkuKf2jmS+KV6r1034= -github.com/01-edu/z01 v0.1.0/go.mod h1:BH7t35JaNFuP83rTJDc5nkSfgmC/HYVcJsUcdFqYZNo= diff --git a/test-go/lib/base/base.go b/test-go/lib/base/base.go deleted file mode 100644 index 4a74a43cd..000000000 --- a/test-go/lib/base/base.go +++ /dev/null @@ -1,119 +0,0 @@ -package base - -import ( - "math/rand" - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func uniqueChar(s string) bool { - m := map[rune]struct{}{} - for _, r := range s { - if _, ok := m[r]; ok { - return false - } - m[r] = struct{}{} - } - return true -} - -func IsValid(base string) bool { - return len(base) >= 2 && !strings.ContainsAny(base, "+-") && uniqueChar(base) -} - -func power(nbr int, pwr int) int { - if pwr == 0 { - return 1 - } - if pwr == 1 { - return nbr - } - return nbr * power(nbr, pwr-1) -} - -func Atoi(s string, base string) int { - var result int - var i int - sign := 1 - lengthBase := len(base) - lengths := len(s) - - if !IsValid(base) { - return 0 - } - if s[i] == '-' { - sign = -1 - } - if s[i] == '-' || s[i] == '+' { - i++ - } - for i < len(s) { - result += strings.Index(base, string(s[i])) * power(lengthBase, lengths-1) - i++ - lengths-- - } - return result * sign -} - -func Valid() string { - valid := []string{ - "01", - "CHOUMIisDAcat!", - "choumi", - "0123456789", - "abc", - "Zone01", - "0123456789ABCDEF", - "WhoAmI?", - } - i := rand.Intn(len(valid)) - return valid[i] -} - -func Invalid() string { - invalid := []string{ - "0", - "1", - "CHOUMIisdacat!", - "choumiChoumi", - "01234567890", - "abca", - "Zone01Zone01", - "0123456789ABCDEF0", - "WhoAmI?IamWhoIam", - } - i := rand.Intn(len(invalid)) - return invalid[i] -} - -func StringFrom(base string) string { - letters := []rune(base) - size := lib.RandIntBetween(1, 10) - runes := make([]rune, size) - for i := range runes { - runes[i] = letters[rand.Intn(len(letters))] - } - return string(runes) -} - -func ConvertNbr(n int, base string) string { - var result string - length := len(base) - - for n >= length { - result = string(base[(n%length)]) + result - n = n / length - } - result = string(base[n]) + result - - return result -} - -func Convert(nbr, baseFrom, baseTo string) string { - resultIntermediary := Atoi(nbr, baseFrom) - - resultFinal := ConvertNbr(resultIntermediary, baseTo) - - return resultFinal -} diff --git a/test-go/lib/is/is.go b/test-go/lib/is/is.go deleted file mode 100644 index 09fb18939..000000000 --- a/test-go/lib/is/is.go +++ /dev/null @@ -1,37 +0,0 @@ -package is - -import ( - "math/big" - "unicode" -) - -func Digit(s string) bool { - for _, r := range s { - if !unicode.IsDigit(r) { - return false - } - } - return true -} - -func Lower(s string) bool { - for _, r := range s { - if !unicode.IsLower(r) { - return false - } - } - return true -} - -func Upper(s string) bool { - for _, r := range s { - if !unicode.IsUpper(r) { - return false - } - } - return true -} - -func Prime(i int) bool { - return big.NewInt(int64(i)).ProbablyPrime(0) -} diff --git a/test-go/lib/lib.go b/test-go/lib/lib.go deleted file mode 100644 index ea72c5764..000000000 --- a/test-go/lib/lib.go +++ /dev/null @@ -1,420 +0,0 @@ -package lib - -import ( - "bytes" - "fmt" - "io" - "math/big" - "math/rand" - "os" - "os/exec" - "path" - "reflect" - "strconv" - "strings" - "time" - "unicode" - "unicode/utf8" -) - -const ( - MinInt = ^MaxInt - MaxInt = 1<<63 - 1 - - StrLen = 13 // Default length of random strings - SliceLen = 8 // Default length of slices -) - -var ( - nsSince1970 = time.Now().UnixNano() - bigRand = rand.New(rand.NewSource(nsSince1970)) - - // charsets - Digit = RuneRange('0', '9') // Decimal digit characters - Lower = RuneRange('a', 'z') // Lowercase latin alphabet characters - Upper = RuneRange('A', 'Z') // Uppercase latin alphabet characters - ASCII = RuneRange(' ', '~') // ASCII printable characters - Space = strings.Repeat(" ", StrLen) // Spaces characters - Basic = Lower + Upper // Lower and Upper characters - Alnum = Basic + Digit // Basic and Digit characters - Words = Alnum + Space // Alnum and Space characters -) - -func init() { - rand.Seed(nsSince1970) -} - -// RuneRange returns a string containing all the valid runes from a to b. -func RuneRange(a, b rune) string { - var s []rune - for { - if utf8.ValidRune(a) { - s = append(s, a) - } - if a == b { - return string(s) - } - if a < b { - a++ - } else { - a-- - } - } -} - -// IntRange returns a slice containing all the int from a to b. -func IntRange(a, b int) (s []int) { - for { - s = append(s, a) - if a == b { - return - } - if a < b { - a++ - } else { - a-- - } - } -} - -// RandIntBetween returns a random int between a and b included. -func RandIntBetween(a, b int) int { - if a > b { - a, b = b, a - } - n := big.NewInt(int64(b)) // b - n.Sub(n, big.NewInt(int64(a))) // b-a - n.Add(n, big.NewInt(1)) // b-a+1 - n.Rand(bigRand, n) // 0 <= n <= b-a - n.Add(n, big.NewInt(int64(a))) // a <= n <= b - return int(n.Int64()) -} - -// RandPosZ returns a random int between 0 and MaxInt included. -func RandPosZ() int { return RandIntBetween(0, MaxInt) } - -// RandPos returns a random int between 1 and MaxInt included. -func RandPos() int { return RandIntBetween(1, MaxInt) } - -// RandInt returns a random int between MinInt and MaxInt included. -func RandInt() int { return RandIntBetween(MinInt, MaxInt) } - -// RandNeg returns a random int between MinInt and 1 included. -func RandNeg() int { return RandIntBetween(MinInt, 1) } - -// RandNegZ returns a random int between MinInt and 0 included. -func RandNegZ() int { return RandIntBetween(MinInt, 0) } - -// MakeIntFunc returns a slice of ints created by f. -func MakeIntFunc(f func() int) (s []int) { - i := 0 - for i < SliceLen { - s = append(s, f()) - i++ - } - return -} - -// MultRandPosZ returns a slice of random ints between 0 and MaxInt included. -func MultRandPosZ() []int { return MakeIntFunc(RandPosZ) } - -// MultRandPos returns a slice of random ints between 1 and MaxInt included. -func MultRandPos() []int { return MakeIntFunc(RandPos) } - -// MultRandInt returns a slice of random ints between MinInt and MaxInt included. -func MultRandInt() []int { return MakeIntFunc(RandInt) } - -// MultRandNeg returns a slice of random ints between MinInt and 1 included. -func MultRandNeg() []int { return MakeIntFunc(RandNeg) } - -// MultRandNegZ returns a slice of random ints between MinInt and 0 included. -func MultRandNegZ() []int { return MakeIntFunc(RandNegZ) } - -// MultRandIntBetween returns a slice of random ints between a and b included. -func MultRandIntBetween(a, b int) []int { - return MakeIntFunc(func() int { return RandIntBetween(a, b) }) -} - -// RandRune returns a random printable rune -// (although you may not have the corresponding glyph). -// One-in-ten chance to get a rune higher than 0x10000 (1<<16). -func RandRune() rune { - ranges := unicode.PrintRanges - table := ranges[rand.Intn(len(ranges))] - if rand.Intn(10) == 0 { - r := table.R32[rand.Intn(len(table.R32))] - n := uint32(rand.Intn(int((r.Hi-r.Lo)/r.Stride) + 1)) - return rune(r.Lo + n*r.Stride) - } - r := table.R16[rand.Intn(len(table.R16))] - n := uint16(rand.Intn(int((r.Hi-r.Lo)/r.Stride) + 1)) - return rune(r.Lo + n*r.Stride) -} - -// RandStr returns a string with l random characters taken from chars. -// If chars is empty, the characters are random printable runes. -func RandStr(l int, chars string) string { - if l <= 0 { - return "" - } - dst := make([]rune, l) - if chars == "" { - for i := range dst { - dst[i] = RandRune() - } - } else { - src := []rune(chars) - for i := range dst { - r := rand.Intn(len(src)) - dst[i] = src[r] - } - } - return string(dst) -} - -// RandDigit returns a string containing random decimal digit characters. -func RandDigit() string { return RandStr(StrLen, Digit) } - -// RandLower returns a string containing random lowercase latin alphabet characters. -func RandLower() string { return RandStr(StrLen, Lower) } - -// RandUpper returns a string containing random uppercase latin alphabet characters. -func RandUpper() string { return RandStr(StrLen, Upper) } - -// RandASCII returns a string containing random ASCII printable characters. -func RandASCII() string { return RandStr(StrLen, ASCII) } - -// RandSpace returns a string containing random spaces characters. -func RandSpace() string { return RandStr(StrLen, Space) } - -// RandBasic returns a string containing random lower and upper characters. -func RandBasic() string { return RandStr(StrLen, Basic) } - -// RandAlnum returns a string containing random basic and digit characters. -func RandAlnum() string { return RandStr(StrLen, Alnum) } - -// RandWords returns a string containing random alphanumeric and space characters. -func RandWords() string { return RandStr(StrLen, Words) } - -// MakeStrFunc returns a slice of strings created by f. -func MakeStrFunc(f func() string) (s []string) { - i := 0 - for i < StrLen { - s = append(s, f()) - i++ - } - return -} - -// MultRandDigit returns a slice of strings containing random Decimal digit characters. -func MultRandDigit() []string { return MakeStrFunc(RandDigit) } - -// MultRandLower returns a slice of strings containing random Lowercase latin alphabet. -func MultRandLower() []string { return MakeStrFunc(RandLower) } - -// MultRandUpper returns a slice of strings containing random Uppercase latin alphabet. -func MultRandUpper() []string { return MakeStrFunc(RandUpper) } - -// MultRandASCII returns a slice of strings containing random ASCII printable characters. -func MultRandASCII() []string { return MakeStrFunc(RandASCII) } - -// MultRandSpace returns a slice of strings containing random Spaces characters. -func MultRandSpace() []string { return MakeStrFunc(RandSpace) } - -// MultRandBasic returns a slice of strings containing random Lower and Upper characters. -func MultRandBasic() []string { return MakeStrFunc(RandBasic) } - -// MultRandAlnum returns a slice of strings containing random Basic and Digit characters. -func MultRandAlnum() []string { return MakeStrFunc(RandAlnum) } - -// MultRandWords returns a slice of strings containing random Alnum and Space characters. -func MultRandWords() []string { return MakeStrFunc(RandWords) } - -func Format(a ...interface{}) string { - ss := make([]string, len(a)) - for i, v := range a { - switch v.(type) { - case nil: - ss[i] = "nil" // instead of "" - case - string, - byte, // uint8 - rune: // int32 - - // string : a double-quoted string safely escaped with Go syntax - // byte, rune : a single-quoted character literal safely escaped with Go syntax - ss[i] = fmt.Sprintf("%q", v) - default: - // a Go-syntax representation of the value - ss[i] = fmt.Sprintf("%#v", v) - } - } - return strings.Join(ss, ", ") -} - -var valueOf = reflect.ValueOf - -func Call(fn interface{}, args []interface{}) []interface{} { - // Convert args from []interface{} to []reflect.Value - vals := make([]reflect.Value, len(args)) - for i, v := range args { - if v != nil { - vals[i] = valueOf(v) - } else { - vals[i] = reflect.Zero(reflect.TypeOf((*interface{})(nil)).Elem()) - } - } - - vals = valueOf(fn).Call(vals) - - // Convert the return values from []reflect.Value to []interface{} - result := make([]interface{}, len(vals)) - for i, v := range vals { - result[i] = v.Interface() - } - return result -} - -type Output struct { - Results []interface{} - Stdout string -} - -func Monitor(fn interface{}, args []interface{}) (out Output) { - old := os.Stdout - r, w, err := os.Pipe() - panicIfNotNil(err) - os.Stdout = w - out.Results = Call(fn, args) - outC := make(chan string) - var buf strings.Builder - go func() { - io.Copy(&buf, r) - outC <- buf.String() - }() - os.Stdout = old - w.Close() - out.Stdout = <-outC - return out -} - -func Challenge(name string, fn1, fn2 interface{}, args ...interface{}) { - st1 := Monitor(fn1, args) - st2 := Monitor(fn2, args) - if !reflect.DeepEqual(st1.Results, st2.Results) { - Fatalf("%s(%s) == %s instead of %s\n", - name, - Format(args...), - Format(st1.Results...), - Format(st2.Results...), - ) - } - if !reflect.DeepEqual(st1.Stdout, st2.Stdout) { - Fatalf("%s(%s) prints:\n%s\ninstead of:\n%s\n", - name, - Format(args...), - Format(st1.Stdout), - Format(st2.Stdout), - ) - } -} - -func Fatal(a ...interface{}) { - fmt.Fprint(os.Stderr, a...) - os.Exit(1) -} - -func Fatalln(a ...interface{}) { - fmt.Fprintln(os.Stderr, a...) - os.Exit(1) -} - -func Fatalf(format string, a ...interface{}) { - fmt.Fprintf(os.Stderr, format, a...) - os.Exit(1) -} - -func panicIfNotNil(err error) { - if err != nil { - panic(err) - } -} - -func ChallengeMainStdin(exercise, input string, args ...string) { - run := func(pkg string) (string, int) { - binaryPath := path.Join(os.TempDir(), "binaries", path.Base(pkg)) - panicIfNotNil(exec.Command("go", "build", "-o", binaryPath, pkg).Run()) - cmd := exec.Command(binaryPath, args...) - if input != "" { - cmd.Stdin = bytes.NewBufferString(input) - } - b, err := cmd.CombinedOutput() - if err != nil { - if ee, ok := err.(*exec.ExitError); ok { - return string(b), ee.ExitCode() - } - panic(err) - } - return string(b), 0 - } - console := func(out string) string { - var quotedArgs []string - for _, arg := range args { - quotedArgs = append(quotedArgs, strconv.Quote(arg)) - } - s := "\n$ " - if input != "" { - s += "echo -ne " + strconv.Quote(input) + " | " - } - return fmt.Sprintf(s+"./%s %s\n%s$ ", exercise, strings.Join(quotedArgs, " "), out) - } - code := func(code int) string { - return fmt.Sprintf("echo $?\n%d\n$", code) - } - student, studentCode := run(path.Join("student", exercise)) - solution, solutionCode := run(path.Join("github.com/01-edu/public/test-go/solutions", exercise+"_prog")) - if solutionCode == 0 { - if studentCode != 0 { - Fatalln("Your program fails (non-zero exit status) when it should not :\n" + - console(student) + - code(studentCode) + "\n\n" + - "Expected :\n" + - console(solution) + - code(solutionCode)) - } - } else { - if studentCode == 0 { - Fatalln("Your program does not fail when it should (with a non-zero exit status) :" + "\n" + - console(student) + - code(studentCode) + "\n\n" + - "Expected :\n" + - console(solution) + - code(solutionCode)) - } - } - if student != solution { - Fatalln("Your program output is not correct :\n" + - console(student) + "\n\n" + - "Expected :\n" + - console(solution)) - } -} - -// GCD returns greatest common divisor of a and b. -func GCD(a, b int) int { - for a != b { - if a > b { - a -= b - } else { - b -= a - } - } - return a -} - -func ChallengeMain(exercise string, args ...string) { - ChallengeMainStdin(exercise, "", args...) -} - -// TODO: check unhandled errors on all solutions (it should contains "ERROR" on the first line to prove we correctly handle the error) -// TODO: remove the number of rand functions, refactor test cases (aka "table") diff --git a/test-go/solutions/addprimesum_prog/main.go b/test-go/solutions/addprimesum_prog/main.go deleted file mode 100644 index 9c39008d3..000000000 --- a/test-go/solutions/addprimesum_prog/main.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" - - "github.com/01-edu/public/test-go/lib/is" -) - -func main() { - if len(os.Args) != 2 { - fmt.Println("0") - } else { - argument, _ := strconv.Atoi(os.Args[1]) - - if argument < 0 { - fmt.Println("0") - } else { - result := 0 - for ; argument >= 0; argument-- { - if is.Prime(argument) { - result += argument - } - } - fmt.Println(result) - } - } -} diff --git a/test-go/solutions/alphamirror_prog/main.go b/test-go/solutions/alphamirror_prog/main.go deleted file mode 100644 index e9db50422..000000000 --- a/test-go/solutions/alphamirror_prog/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func main() { - if len(os.Args) == 2 { - arg := []rune(os.Args[1]) - for i, ch := range arg { - if ch >= 'a' && ch <= 'z' { - arg[i] = 'z' - ch + 'a' - } else if ch >= 'A' && ch <= 'Z' { - arg[i] = 'Z' - ch + 'A' - } - } - fmt.Print(string(arg)) - } - - fmt.Println() -} diff --git a/test-go/solutions/balancedstring_prog/main.go b/test-go/solutions/balancedstring_prog/main.go deleted file mode 100644 index ae540cd76..000000000 --- a/test-go/solutions/balancedstring_prog/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func solve(s string) int { - var count, countC, countD int - for _, r := range s { - if r == 'C' { - countC++ - } else if r == 'D' { - countD++ - } - if countC == countD { - count++ - countC = 0 - countD = 0 - } - } - return count -} - -func main() { - args := os.Args[1:] - if len(args) == 1 { - result := solve(args[0]) - fmt.Println(result) - } -} diff --git a/test-go/solutions/boolean_prog/main.go b/test-go/solutions/boolean_prog/main.go deleted file mode 100644 index e94d966b5..000000000 --- a/test-go/solutions/boolean_prog/main.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func main() { - if len(os.Args[1:])%2 == 0 { - fmt.Println("I have an even number of arguments") - } else { - fmt.Println("I have an odd number of arguments") - } -} diff --git a/test-go/solutions/brackets_prog/main.go b/test-go/solutions/brackets_prog/main.go deleted file mode 100644 index 544032164..000000000 --- a/test-go/solutions/brackets_prog/main.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func matchBrackets(exp string) bool { - runes := []rune(exp) - var opened []rune - ptr := -1 - for _, c := range runes { - if c == '(' || c == '[' || c == '{' { - opened = append(opened, c) - ptr++ - } else if c == ')' { - if ptr < 0 || opened[ptr] != '(' { - return false - } - opened = opened[:len(opened)-1] - ptr-- - } else if c == ']' { - if ptr < 0 || opened[ptr] != '[' { - return false - } - opened = opened[:len(opened)-1] - ptr-- - } else if c == '}' { - if ptr < 0 || opened[ptr] != '{' { - return false - } - opened = opened[:len(opened)-1] - ptr-- - } - } - return len(opened) == 0 -} - -func main() { - if len(os.Args) == 1 { - fmt.Println() - } else { - for _, v := range os.Args[1:] { - if matchBrackets(v) { - fmt.Println("OK") - } else { - fmt.Println("Error") - } - } - } -} diff --git a/test-go/solutions/brainfuck_prog/main.go b/test-go/solutions/brainfuck_prog/main.go deleted file mode 100644 index d1afa1766..000000000 --- a/test-go/solutions/brainfuck_prog/main.go +++ /dev/null @@ -1,66 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -const SIZE = 2048 - -func main() { - if len(os.Args) != 2 { - return - } - progpoint := []byte(os.Args[1]) - var arby [SIZE]byte - pos := 0 - openBr := 0 // opened brackets - i := 0 // iterates through the source code passed in the argument - N := len(progpoint) // length of the source code - for i >= 0 && i < N { - switch progpoint[i] { - case '>': - // Increment the pointer - pos++ - case '<': - // decrement the pointes - pos-- - case '+': - // increment the pointed byte - arby[pos]++ - case '-': - // decrement the pointed byte - arby[pos]-- - case '.': - // print the pointed byte on std output - fmt.Printf("%c", rune(arby[pos])) - case '[': - // go to the matching ']' if the pointed byte is 0 (while start) - openBr = 0 - if arby[pos] == 0 { - for i < N && (progpoint[i] != byte(']') || openBr > 1) { - if progpoint[i] == byte('[') { - openBr++ - } else if progpoint[i] == byte(']') { - openBr-- - } - i++ - } - } - case ']': - // go to the matching '[' if the pointed byte is not 0 (while end) - openBr = 0 - if arby[pos] != 0 { - for i >= 0 && (progpoint[i] != byte('[') || openBr > 1) { - if progpoint[i] == byte(']') { - openBr++ - } else if progpoint[i] == byte('[') { - openBr-- - } - i-- - } - } - } - i++ - } -} diff --git a/test-go/solutions/btree.go b/test-go/solutions/btree.go deleted file mode 100644 index 1ed44c865..000000000 --- a/test-go/solutions/btree.go +++ /dev/null @@ -1,252 +0,0 @@ -package solutions - -type TreeNode struct { - Left, Right, Parent *TreeNode - Data string -} - -func BTreeInsertData(bt *TreeNode, elem string) *TreeNode { - if bt == nil { - return &TreeNode{Data: elem} - } - - if elem < bt.Data { - bt.Left = BTreeInsertData(bt.Left, elem) - bt.Left.Parent = bt - } else if elem >= bt.Data { - bt.Right = BTreeInsertData(bt.Right, elem) - bt.Right.Parent = bt - } - return bt -} - -func BTreeApplyInorder(root *TreeNode, f func(...interface{}) (int, error)) { - if root != nil { - BTreeApplyInorder(root.Left, f) - f(root.Data) - BTreeApplyInorder(root.Right, f) - } -} - -func BTreeApplyPreorder(root *TreeNode, f func(...interface{}) (int, error)) { - if root != nil { - f(root.Data) - BTreeApplyPreorder(root.Left, f) - BTreeApplyPreorder(root.Right, f) - } -} - -func BTreeApplyPostorder(root *TreeNode, f func(...interface{}) (int, error)) { - if root != nil { - BTreeApplyPostorder(root.Left, f) - BTreeApplyPostorder(root.Right, f) - f(root.Data) - } -} - -func BTreeSearchItem(root *TreeNode, elem string) *TreeNode { - if root == nil { - return nil - } - - if root.Data == elem { - return root - } - - if elem < root.Data { - return BTreeSearchItem(root.Left, elem) - } - - return BTreeSearchItem(root.Right, elem) -} - -func BTreeLevelCount(root *TreeNode) int { - if root == nil { - return 0 - } - - left := BTreeLevelCount(root.Left) - right := BTreeLevelCount(root.Right) - - if left > right { - return left + 1 - } - - return right + 1 -} - -func BTreeIsBinary(root *TreeNode) bool { - condLeft := true - condRight := true - - if root == nil { - return true - } - - if root.Left != nil { - condLeft = BTreeIsBinary(root.Left) && root.Data >= root.Left.Data - } - - if root.Right != nil { - condRight = BTreeIsBinary(root.Right) && root.Data <= root.Right.Data - } - - return condLeft && condRight -} - -func applyGivenOrder(root *TreeNode, level int, f func(...interface{}) (int, error)) { - if root == nil { - return - } - - if level == 0 { - arg := interface{}(root.Data) - f(arg) - } else if level > 0 { - applyGivenOrder(root.Left, level-1, f) - applyGivenOrder(root.Right, level-1, f) - } -} - -// Apply the function f level by level -func BTreeApplyByLevel(root *TreeNode, f func(...interface{}) (int, error)) { - h := BTreeLevelCount(root) - for i := 0; i < h; i++ { - applyGivenOrder(root, i, f) - } -} - -/*----------------------------------- -* node-> (A) (B) -* / / \ -* temp-> (B) --------> (C) (A) -* / \ / -* (C) [z] [z] -*------------------------------------*/ -func BTreeRotateRight(node *TreeNode) *TreeNode { - if node == nil { - return nil - } - - if node.Left == nil { - return node - } - - temp := node.Left - - node.Left = temp.Right - - if temp.Right != nil { - temp.Right.Parent = node - } - - if node.Parent != nil { - if node == node.Parent.Left { - node.Parent.Left = temp - } else { - node.Parent.Right = temp - } - } - - temp.Right = node - temp.Parent = node.Parent - node.Parent = temp - return temp -} - -/*------------------------------------ -* node->(A) (B) -* \ / \ -* temp-> (B) -------> (A) (C) -* / \ \ -* [z] (C) [z] -*------------------------------------- */ -func BTreeRotateLeft(node *TreeNode) *TreeNode { - if node == nil { - return nil - } - - if node.Right == nil { - return node - } - - temp := node.Right - node.Right = temp.Left - - if temp.Left != nil { - temp.Left.Parent = node - } - if node.Parent != nil { - if node == node.Parent.Left { - node.Parent.Left = temp - } else { - node.Parent.Right = temp - } - } - - temp.Left = node - temp.Parent = node.Parent - - node.Parent = temp - return temp -} - -// Returns the maximum node in the subtree started by root -func BTreeMax(root *TreeNode) *TreeNode { - if root == nil || root.Right == nil { - return root - } - - return BTreeMax(root.Right) -} - -// Returns the minimum value in the subtree started by root -func BTreeMin(root *TreeNode) *TreeNode { - if root == nil || root.Left == nil { - return root - } - - return BTreeMin(root.Left) -} - -func BTreeTransplant(root, node, repla *TreeNode) *TreeNode { - if root == nil { - return nil - } - - replacement := node - if node.Parent == nil { - root = repla - } else if node == node.Parent.Left { - replacement.Parent.Left = repla - } else { - replacement.Parent.Right = repla - } - if repla != nil { - repla.Parent = node.Parent - } - - return root -} - -func BTreeDeleteNode(root, node *TreeNode) *TreeNode { - if node != nil { - if node.Left == nil { - root = BTreeTransplant(root, node, node.Right) - } else if node.Right == nil { - root = BTreeTransplant(root, node, node.Left) - } else { - y := BTreeMin(node.Right) - if y != nil && y.Parent != node { - root = BTreeTransplant(root, y, y.Right) - - y.Right = node.Right - y.Right.Parent = y - } - root = BTreeTransplant(root, node, y) - y.Left = node.Left - y.Left.Parent = y - } - } - return root -} diff --git a/test-go/solutions/cat_prog/main.go b/test-go/solutions/cat_prog/main.go deleted file mode 100644 index 76260e737..000000000 --- a/test-go/solutions/cat_prog/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "io" - "io/ioutil" - "os" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - if len(os.Args) == 1 { - if _, err := io.Copy(os.Stdout, os.Stdin); err != nil { - panic(err) - } - } else { - for _, arg := range os.Args[1:] { - b, err := ioutil.ReadFile(arg) - if err != nil { - lib.Fatalln("ERROR:", err) - } - os.Stdout.Write(b) - } - } -} diff --git a/test-go/solutions/challenge.go b/test-go/solutions/challenge.go deleted file mode 100644 index 0857cd291..000000000 --- a/test-go/solutions/challenge.go +++ /dev/null @@ -1,190 +0,0 @@ -package solutions - -import ( - "reflect" - "runtime" - "strconv" - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func FormatTree(root *TreeNode) string { - if root == nil { - return "" - } - res := root.Data + "\n" - res += formatSubTree(root, "") - return res -} - -func formatSubTree(root *TreeNode, prefix string) string { - if root == nil { - return "" - } - - var res string - - hasLeft := root.Left != nil - hasRight := root.Right != nil - - if !hasLeft && !hasRight { - return res - } - - res += prefix - if hasLeft && hasRight { - res += "├── " - } - - if !hasLeft && hasRight { - res += "└── " - } - - if hasRight { - printStrand := (hasLeft && hasRight && (root.Right.Right != nil || root.Right.Left != nil)) - newPrefix := prefix - if printStrand { - newPrefix += "│ " - } else { - newPrefix += " " - } - res += root.Right.Data + "\n" - res += formatSubTree(root.Right, newPrefix) - } - - if hasLeft { - if hasRight { - res += prefix - } - res += "└── " + root.Left.Data + "\n" - res += formatSubTree(root.Left, prefix+" ") - } - return res -} - -func ParentList(root *TreeNode) string { - if root == nil { - return "" - } - - var parent string - - if root.Parent == nil { - parent = "nil" - } else { - parent = root.Parent.Data - } - - r := "Node: " + root.Data + " Parent: " + parent + "\n" - r += ParentList(root.Left) + ParentList(root.Right) - return r -} - -func ChallengeTree( - name string, - fn1, fn2 interface{}, - arg1 *TreeNode, arg2 interface{}, - args ...interface{}, -) { - args1 := []interface{}{arg1} - args2 := []interface{}{arg2} - - if args != nil { - for _, v := range args { - args1 = append(args1, v) - args2 = append(args2, v) - } - } - st1 := lib.Monitor(fn1, args1) - st2 := lib.Monitor(fn2, args2) - - if st1.Stdout != st2.Stdout { - lib.Fatalf("%s(\n%s)\n prints %s instead of %s\n", - name, - FormatTree(arg1), - lib.Format(st2.Stdout), - lib.Format(st1.Stdout), - ) - } -} - -func PrintList(n *NodeI) string { - var res string - it := n - for it != nil { - res += strconv.Itoa(it.Data) + "-> " - it = it.Next - } - res += "" - return res -} - -func ListToString(n *NodeL) string { - var res string - it := n - for it != nil { - switch it.Data.(type) { - case int: - res += strconv.Itoa(it.Data.(int)) + "-> " - case string: - res += it.Data.(string) + "-> " - } - it = it.Next - } - res += "" - return res -} - -func ConvertIntToInterface(t []int) []interface{} { - RandLen := lib.RandIntBetween(0, len(t)) - s := make([]interface{}, RandLen) - for j := 0; j < RandLen; j++ { - for i := 0; i < lib.RandIntBetween(1, len(t)); i++ { - s[j] = t[i] - } - } - return s -} - -func ConvertIntToStringface(t []string) []interface{} { - RandLen := lib.RandIntBetween(0, len(t)) - s := make([]interface{}, RandLen) - for j := 0; j < RandLen; j++ { - for i := 0; i < lib.RandIntBetween(1, len(t)); i++ { - s[j] = t[i] - } - } - return s -} - -type NodeTest struct { - Data []interface{} -} - -func ElementsToTest(table []NodeTest) []NodeTest { - table = append(table, - NodeTest{ - Data: []interface{}{}, - }, - ) - for i := 0; i < 3; i++ { - val := NodeTest{ - Data: ConvertIntToInterface(lib.MultRandInt()), - } - table = append(table, val) - } - for i := 0; i < 3; i++ { - val := NodeTest{ - Data: ConvertIntToStringface(lib.MultRandWords()), - } - table = append(table, val) - } - return table -} - -// GetName gets the function name -func GetName(f interface{}) string { - pathFuncUsed := strings.Split(runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name(), "/") - return pathFuncUsed[len(pathFuncUsed)-1] -} diff --git a/test-go/solutions/cleanstr_prog/main.go b/test-go/solutions/cleanstr_prog/main.go deleted file mode 100644 index 3135382a9..000000000 --- a/test-go/solutions/cleanstr_prog/main.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import ( - "fmt" - "os" - "regexp" - "strings" -) - -func main() { - if len(os.Args) == 2 { - re := regexp.MustCompile(`( +)`) - fmt.Print(re.ReplaceAllString(strings.Trim(os.Args[1], " "), " ")) - } - fmt.Println() -} diff --git a/test-go/solutions/comcheck_prog/main.go b/test-go/solutions/comcheck_prog/main.go deleted file mode 100644 index 1ba7c1e93..000000000 --- a/test-go/solutions/comcheck_prog/main.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func main() { - safeWords := []string{"01", "galaxy", "galaxy 01"} - count := 0 - for _, arg := range os.Args[1:] { - for _, s := range safeWords { - if s == arg { - count++ - } - } - } - if count == 1 || count == 2 { - fmt.Println("Alert!!!") - } -} diff --git a/test-go/solutions/costumeprofit_prog/main.go b/test-go/solutions/costumeprofit_prog/main.go deleted file mode 100644 index 0202d20be..000000000 --- a/test-go/solutions/costumeprofit_prog/main.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" -) - -func min(numbers ...int) int { - min := numbers[0] - for _, i := range numbers { - if i < min { - min = i - } - } - return min -} - -func max(numbers ...int) int { - max := numbers[0] - for _, i := range numbers { - if i > max { - max = i - } - } - return max -} - -func costumeProfit(a, b, c, d, e, f int) int { - if d == min(a, b, c, d) { - return d * max(e, f) - } - if e > f { - ans := min(a, d) * e - d -= min(a, d) - ans += min(d, b, c) * f - return ans - } - ans := min(b, c, d) * f - d -= min(b, c, d) - ans += min(a, d) * e - return ans -} - -func main() { - args := os.Args[1:] - a, _ := strconv.Atoi(args[0]) - b, _ := strconv.Atoi(args[1]) - c, _ := strconv.Atoi(args[2]) - d, _ := strconv.Atoi(args[3]) - e, _ := strconv.Atoi(args[4]) - f, _ := strconv.Atoi(args[5]) - - fmt.Println(costumeProfit(a, b, c, d, e, f)) -} diff --git a/test-go/solutions/countdown_prog/main.go b/test-go/solutions/countdown_prog/main.go deleted file mode 100644 index ecb2baf73..000000000 --- a/test-go/solutions/countdown_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println(9876543210) -} diff --git a/test-go/solutions/displaya_prog/main.go b/test-go/solutions/displaya_prog/main.go deleted file mode 100644 index b62cea25d..000000000 --- a/test-go/solutions/displaya_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("a") -} diff --git a/test-go/solutions/displayalpham_prog/main.go b/test-go/solutions/displayalpham_prog/main.go deleted file mode 100644 index a10580a2b..000000000 --- a/test-go/solutions/displayalpham_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("aBcDeFgHiJkLmNoPqRsTuVwXyZ") -} diff --git a/test-go/solutions/displayalrevm_prog/main.go b/test-go/solutions/displayalrevm_prog/main.go deleted file mode 100644 index 248906a6a..000000000 --- a/test-go/solutions/displayalrevm_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("zYxWvUtSrQpOnMlKjIhGfEdCbA") -} diff --git a/test-go/solutions/displayfile_prog/main.go b/test-go/solutions/displayfile_prog/main.go deleted file mode 100644 index d6eccb982..000000000 --- a/test-go/solutions/displayfile_prog/main.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "os" -) - -func main() { - if len(os.Args) < 2 { - fmt.Println("File name missing") - } else if len(os.Args) > 2 { - fmt.Println("Too many arguments") - } else { - b, err := ioutil.ReadFile(os.Args[1]) - if err != nil { - panic(err) - } - os.Stdout.Write(b) - } -} diff --git a/test-go/solutions/displayfirstparam_prog/main.go b/test-go/solutions/displayfirstparam_prog/main.go deleted file mode 100644 index 0555cf902..000000000 --- a/test-go/solutions/displayfirstparam_prog/main.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func main() { - if len(os.Args) > 1 { - fmt.Println(os.Args[1]) - } -} diff --git a/test-go/solutions/displaylastparam_prog/main.go b/test-go/solutions/displaylastparam_prog/main.go deleted file mode 100644 index 6c52acc23..000000000 --- a/test-go/solutions/displaylastparam_prog/main.go +++ /dev/null @@ -1,13 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func main() { - size := len(os.Args) - if size > 1 { - fmt.Println(os.Args[size-1]) - } -} diff --git a/test-go/solutions/displayz_prog/main.go b/test-go/solutions/displayz_prog/main.go deleted file mode 100644 index 9fe2f6259..000000000 --- a/test-go/solutions/displayz_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("z") -} diff --git a/test-go/solutions/doop_prog/main.go b/test-go/solutions/doop_prog/main.go deleted file mode 100644 index b882bacbe..000000000 --- a/test-go/solutions/doop_prog/main.go +++ /dev/null @@ -1,50 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" -) - -func main() { - if len(os.Args) == 4 { - a, err := strconv.Atoi(os.Args[1]) - if err != nil { - return - } - b, err := strconv.Atoi(os.Args[3]) - if err != nil { - return - } - operator := os.Args[2] - switch operator { - case "+": - result := a + b - if (result > a) == (b > 0) { - fmt.Println(result) - } - case "-": - result := a - b - if (result < a) == (b > 0) { - fmt.Println(result) - } - case "*": - result := a * b - if a == 0 || (result/a == b) { - fmt.Println(result) - } - case "/": - if b == 0 { - fmt.Println("No division by 0") - } else { - fmt.Println(a / b) - } - case "%": - if b == 0 { - fmt.Println("No modulo by 0") - } else { - fmt.Println(a % b) - } - } - } -} diff --git a/test-go/solutions/expandstr_prog/main.go b/test-go/solutions/expandstr_prog/main.go deleted file mode 100644 index 9752d4046..000000000 --- a/test-go/solutions/expandstr_prog/main.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" -) - -func deleteExtraSpaces(a []string) (res []string) { - for _, v := range a { - if v != "" { - res = append(res, v) - } - } - return -} - -func main() { - if len(os.Args) == 2 { - arg := strings.Split(os.Args[1], " ") - arg = deleteExtraSpaces(arg) - fmt.Println(strings.Join(arg, " ")) - } -} diff --git a/test-go/solutions/firstword_prog/main.go b/test-go/solutions/firstword_prog/main.go deleted file mode 100644 index 34474f8f7..000000000 --- a/test-go/solutions/firstword_prog/main.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" -) - -func main() { - if len(os.Args) == 2 { - s := strings.Split(strings.TrimSpace(os.Args[1]), " ")[0] - if s != "" { - fmt.Println(s) - } - } -} diff --git a/test-go/solutions/fixthemain_prog/main.go b/test-go/solutions/fixthemain_prog/main.go deleted file mode 100644 index d4d3bf924..000000000 --- a/test-go/solutions/fixthemain_prog/main.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import "fmt" - -const ( - CLOSE = iota - OPEN -) - -type Door struct { - State int -} - -func CloseDoor(ptrDoor *Door) { - fmt.Println("Door Closing...") - ptrDoor.State = CLOSE -} - -func OpenDoor(ptrdoor *Door) { - fmt.Println("Door Opening...") - ptrdoor.State = OPEN -} - -func IsDoorOpened(ptrDoor *Door) bool { - fmt.Println("is the Door opened ?") - return ptrDoor.State == OPEN -} - -func IsDoorClosed(ptrDoor *Door) bool { - fmt.Println("is the Door closed ?") - return ptrDoor.State == CLOSE -} - -func main() { - var door Door - - OpenDoor(&door) - if IsDoorClosed(&door) { - OpenDoor(&door) - } - if IsDoorOpened(&door) { - CloseDoor(&door) - } - if door.State == OPEN { - CloseDoor(&door) - } -} diff --git a/test-go/solutions/flags_prog/main.go b/test-go/solutions/flags_prog/main.go deleted file mode 100644 index f9632b05a..000000000 --- a/test-go/solutions/flags_prog/main.go +++ /dev/null @@ -1,72 +0,0 @@ -package main - -import ( - "fmt" - "os" - "sort" - "strings" -) - -type helpMs struct { - flag string - shortenFlag string - handler string -} - -func obtainValues(value, strsplit string) string { - values := strings.Split(value, "=") - return values[len(values)-1] -} - -func setMs(flag, shortenFlag, handler string) *helpMs { - helpMs := &helpMs{ - flag: flag, - shortenFlag: shortenFlag, - handler: handler, - } - return helpMs -} - -func main() { - size := len(os.Args) - - if size == 1 || os.Args[1] == "-h" || os.Args[1] == "--help" { - table := []helpMs{} - - helpMs := setMs("--insert", "-i", "This flag inserts the string into the string passed as argument.") - table = append(table, *helpMs) - helpMs = setMs("--order", "-o", "This flag will behave like a boolean, if it is called it will order the argument.") - table = append(table, *helpMs) - - for _, v := range table { - fmt.Println(v.flag) - fmt.Println(" ", v.shortenFlag) - fmt.Println(" ", v.handler) - } - } else if size <= 4 { - var runes []rune - strToInsert := "" - var order bool - - for i := 1; i < size; i++ { - if strings.Contains(os.Args[i], "--insert") || strings.Contains(os.Args[i], "-i") { - strToInsert = obtainValues(os.Args[i], "=") - } else if strings.Contains(os.Args[i], "--order") || strings.Contains(os.Args[i], "-o") { - order = true - } else { - runes = []rune(os.Args[i]) - } - } - if strToInsert != "" { - concatStr := string(runes) + strToInsert - runes = []rune(concatStr) - } - if order { - sort.Slice(runes, func(i, j int) bool { - return runes[i] < runes[j] - }) - } - - fmt.Println(string(runes)) - } -} diff --git a/test-go/solutions/fprime_prog/main.go b/test-go/solutions/fprime_prog/main.go deleted file mode 100644 index 9f28f5833..000000000 --- a/test-go/solutions/fprime_prog/main.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" -) - -func fprime(value int) { - if value == 1 { - return - } - divisionIterator := 2 - for value > 1 { - if value%divisionIterator == 0 { - fmt.Print(divisionIterator) - value = value / divisionIterator - - if value > 1 { - fmt.Print("*") - } - divisionIterator-- - } - divisionIterator++ - } - fmt.Println() -} - -func main() { - if len(os.Args) == 2 { - if i, err := strconv.Atoi(os.Args[1]); err == nil { - fprime(i) - } - } -} diff --git a/test-go/solutions/gcd_prog/main.go b/test-go/solutions/gcd_prog/main.go deleted file mode 100644 index 4939f9131..000000000 --- a/test-go/solutions/gcd_prog/main.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - if len(os.Args) == 3 { - a, _ := strconv.Atoi(os.Args[1]) - b, _ := strconv.Atoi(os.Args[2]) - fmt.Println(lib.GCD(a, b)) - } -} diff --git a/test-go/solutions/grouping_prog/main.go b/test-go/solutions/grouping_prog/main.go deleted file mode 100644 index b6691f230..000000000 --- a/test-go/solutions/grouping_prog/main.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" - "unicode" -) - -func singleSearch(exp []string, text string) []string { - items := strings.Split(text, " ") - var result []string - - for _, item := range items { - for _, word := range exp { - if strings.Contains(item, word) { - result = append(result, item) - } - } - } - return result -} - -func simpleSearch(runes []rune, text string) []string { - exp := string(runes) - - var result []string - if !strings.ContainsRune(exp, '|') { - helper := []string{exp} - result = append(singleSearch(helper, text)) - } else { - expWords := strings.Split(exp, "|") - result = append(result, singleSearch(expWords, text)...) - } - return result -} - -func brackets(regexp, text string) { - if text == "" || regexp == "" { - return - } - runes := []rune(regexp) - - if runes[0] == '(' && runes[len(runes)-1] == ')' { - runes = runes[1 : len(runes)-1] - result := simpleSearch(runes, text) - for i, s := range result { - if !unicode.IsLetter(rune(s[len(s)-1])) { - s = s[0 : len(s)-1] - } - fmt.Printf("%d: %s\n", i+1, s) - } - } -} - -func main() { - if len(os.Args) == 3 { - brackets(os.Args[1], os.Args[2]) - } -} diff --git a/test-go/solutions/hello_prog/main.go b/test-go/solutions/hello_prog/main.go deleted file mode 100644 index b1b14d0c7..000000000 --- a/test-go/solutions/hello_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("Hello World!") -} diff --git a/test-go/solutions/hiddenp_prog/main.go b/test-go/solutions/hiddenp_prog/main.go deleted file mode 100644 index 0888e02d4..000000000 --- a/test-go/solutions/hiddenp_prog/main.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func main() { - if len(os.Args) != 3 { - return - } - - first := os.Args[1] - second := os.Args[2] - - if first == "" { - fmt.Println("1") - return - } - if second == "" { - fmt.Println("0") - return - } - - i := 0 - j := 0 - count := 0 - - firstA := []rune(first) - secondA := []rune(second) - - for i < len(first) { - for j < len(second) { - if firstA[i] == secondA[j] { - count++ - i++ - } - if i == len(first) { - break - } - j++ - } - i++ - } - - if count == len(first) { - fmt.Println("1") - } else { - fmt.Println("0") - } -} diff --git a/test-go/solutions/inter_prog/main.go b/test-go/solutions/inter_prog/main.go deleted file mode 100644 index 3c8c67ba7..000000000 --- a/test-go/solutions/inter_prog/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" -) - -func result(s1 string, s2 string) string { - var rest []rune - for _, a := range s1 { - for _, b := range s2 { - if a == b && !strings.ContainsRune(string(rest), a) { - rest = append(rest, a) - } - } - } - return string(rest) -} - -func main() { - if len(os.Args) == 3 { - fmt.Println(result(os.Args[1], os.Args[2])) - } -} diff --git a/test-go/solutions/ispowerof2_prog/main.go b/test-go/solutions/ispowerof2_prog/main.go deleted file mode 100644 index d844f62ad..000000000 --- a/test-go/solutions/ispowerof2_prog/main.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" -) - -// computes the logical bitwise AND of its operands. -func isPowerOf2(n int) bool { - return n != 0 && ((n & (n - 1)) == 0) -} - -func main() { - if len(os.Args) == 2 { - nbr, _ := strconv.Atoi(os.Args[1]) - fmt.Println(isPowerOf2(nbr)) - } -} diff --git a/test-go/solutions/lastword_prog/main.go b/test-go/solutions/lastword_prog/main.go deleted file mode 100644 index 711b13408..000000000 --- a/test-go/solutions/lastword_prog/main.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" -) - -func main() { - if len(os.Args) == 2 { - words := strings.Fields(os.Args[1]) - if len(words) > 0 { - fmt.Println(words[len(words)-1]) - } - } -} diff --git a/test-go/solutions/listat.go b/test-go/solutions/listat.go deleted file mode 100644 index 0070a413f..000000000 --- a/test-go/solutions/listat.go +++ /dev/null @@ -1,23 +0,0 @@ -package solutions - -// returs the node in a given position -func ListAt(l *NodeL, nbr int) *NodeL { - index := 0 - count := 0 - head := l - - for head != nil { - index++ - head = head.Next - } - if nbr <= index { - for l != nil { - if count == nbr { - return l - } - count++ - l = l.Next - } - } - return nil -} diff --git a/test-go/solutions/listclear.go b/test-go/solutions/listclear.go deleted file mode 100644 index fc7997997..000000000 --- a/test-go/solutions/listclear.go +++ /dev/null @@ -1,13 +0,0 @@ -package solutions - -func ListClear(l *List) { - temp := l.Head - next := l.Head - for temp != nil { - next = temp.Next - temp = nil - temp = next - } - - l.Head = nil -} diff --git a/test-go/solutions/listfind.go b/test-go/solutions/listfind.go deleted file mode 100644 index 6c392d208..000000000 --- a/test-go/solutions/listfind.go +++ /dev/null @@ -1,19 +0,0 @@ -package solutions - -// finds the element and returns the first data from the node that is a string -func ListFind(l *List, ref interface{}, comp func(a, b interface{}) bool) *interface{} { - iterator := l.Head - for iterator != nil { - if comp(iterator.Data, ref) { - return &iterator.Data - } - - iterator = iterator.Next - } - return nil -} - -// defines for two elements the equality criteria -func CompStr(a, b interface{}) bool { - return a == b -} diff --git a/test-go/solutions/listforeach.go b/test-go/solutions/listforeach.go deleted file mode 100644 index dd69bc787..000000000 --- a/test-go/solutions/listforeach.go +++ /dev/null @@ -1,28 +0,0 @@ -package solutions - -// applies a function in argument to each element of the linked list -func ListForEach(l *List, f func(*NodeL)) { - it := l.Head - for it != nil { - f(it) - it = it.Next - } -} - -func Add2_node(node *NodeL) { - switch node.Data.(type) { - case int: - node.Data = node.Data.(int) + 2 - case string: - node.Data = node.Data.(string) + "2" - } -} - -func Subtract3_node(node *NodeL) { - switch node.Data.(type) { - case int: - node.Data = node.Data.(int) - 3 - case string: - node.Data = node.Data.(string) + "-3" - } -} diff --git a/test-go/solutions/listforeachif.go b/test-go/solutions/listforeachif.go deleted file mode 100644 index 6aaea655b..000000000 --- a/test-go/solutions/listforeachif.go +++ /dev/null @@ -1,43 +0,0 @@ -package solutions - -// compare each element of the linked list to see if it is a String -func IsPositive_node(node *NodeL) bool { - switch node.Data.(type) { - case int, float32, float64, byte: - return node.Data.(int) > 0 - case string, rune: - return false - } - return false -} - -func IsNegative_node(node *NodeL) bool { - switch node.Data.(type) { - case int, float32, float64, byte: - return node.Data.(int) > 0 - case string, rune: - return false - } - return false -} - -func IsNumeric_node(node *NodeL) bool { - switch node.Data.(type) { - case int, float32, float64, byte: - return true - case string, rune: - return false - } - return false -} - -// applies the function f on each string if the boolean function comp returns true -func ListForEachIf(l *List, f func(*NodeL), comp func(*NodeL) bool) { - it := l.Head - for it != nil { - if comp(it) { - f(it) - } - it = it.Next - } -} diff --git a/test-go/solutions/listlast.go b/test-go/solutions/listlast.go deleted file mode 100644 index ea12ae040..000000000 --- a/test-go/solutions/listlast.go +++ /dev/null @@ -1,15 +0,0 @@ -package solutions - -// gives the last element of the list -func ListLast(l *List) interface{} { - if l.Head == nil { - return nil - } - for l.Head != nil { - if l.Head.Next == nil { - return l.Head.Data - } - l.Head = l.Head.Next - } - return l.Head.Data -} diff --git a/test-go/solutions/listmerge.go b/test-go/solutions/listmerge.go deleted file mode 100644 index f85862d15..000000000 --- a/test-go/solutions/listmerge.go +++ /dev/null @@ -1,10 +0,0 @@ -package solutions - -// merges the 2 lists in one (in the end of the first list) -func ListMerge(l1 *List, l2 *List) { - if l1.Head == nil { - l1.Head, l1.Tail = l2.Head, l2.Tail - return - } - l1.Tail.Next = l2.Head -} diff --git a/test-go/solutions/listpushback.go b/test-go/solutions/listpushback.go deleted file mode 100644 index e45ecf406..000000000 --- a/test-go/solutions/listpushback.go +++ /dev/null @@ -1,22 +0,0 @@ -package solutions - -type NodeL struct { - Data interface{} - Next *NodeL -} - -type List struct { - Head *NodeL - Tail *NodeL -} - -func ListPushBack(l *List, data interface{}) { - n := &NodeL{Data: data} - - if l.Head == nil { - l.Head = n - } else { - l.Tail.Next = n - } - l.Tail = n -} diff --git a/test-go/solutions/listpushfront.go b/test-go/solutions/listpushfront.go deleted file mode 100644 index 6ae0c5c6c..000000000 --- a/test-go/solutions/listpushfront.go +++ /dev/null @@ -1,14 +0,0 @@ -package solutions - -// inserts node on the first position of the list -func ListPushFront(l *List, data interface{}) { - n := &NodeL{Data: data} - - if l.Head == nil { - l.Head = n - return - } - - n.Next = l.Head - l.Head = n -} diff --git a/test-go/solutions/listremoveif.go b/test-go/solutions/listremoveif.go deleted file mode 100644 index cd464d647..000000000 --- a/test-go/solutions/listremoveif.go +++ /dev/null @@ -1,19 +0,0 @@ -package solutions - -// removes all elements that are equal to the data_ref -func ListRemoveIf(l *List, data_ref interface{}) { - temp := l.Head - prev := l.Head - - for temp != nil && temp.Data == data_ref { - l.Head = temp.Next - temp = l.Head - } - for temp != nil { - if temp.Data != data_ref { - prev = temp - } - prev.Next = temp.Next - temp = prev.Next - } -} diff --git a/test-go/solutions/listreverse.go b/test-go/solutions/listreverse.go deleted file mode 100644 index aee535c7c..000000000 --- a/test-go/solutions/listreverse.go +++ /dev/null @@ -1,15 +0,0 @@ -package solutions - -func ListReverse(l *List) { - current := l.Head - prev := l.Head - prev = nil - - for current != nil { - next := current.Next - current.Next = prev - prev = current - current = next - } - l.Head = prev -} diff --git a/test-go/solutions/listsize.go b/test-go/solutions/listsize.go deleted file mode 100644 index 7b1f497f4..000000000 --- a/test-go/solutions/listsize.go +++ /dev/null @@ -1,11 +0,0 @@ -package solutions - -func ListSize(l *List) int { - count := 0 - iterator := l.Head - for iterator != nil { - count++ - iterator = iterator.Next - } - return count -} diff --git a/test-go/solutions/listsort.go b/test-go/solutions/listsort.go deleted file mode 100644 index abd893b2f..000000000 --- a/test-go/solutions/listsort.go +++ /dev/null @@ -1,28 +0,0 @@ -package solutions - -func ListSort(l *NodeI) *NodeI { - head := l - if head == nil { - return nil - } - head.Next = ListSort(head.Next) - - if head.Next != nil && head.Data > head.Next.Data { - head = move(head) - } - return head -} - -func move(l *NodeI) *NodeI { - p := l - n := l.Next - ret := n - - for n != nil && l.Data > n.Data { - p = n - n = n.Next - } - p.Next = l - l.Next = n - return ret -} diff --git a/test-go/solutions/nbrconvertalpha_prog/main.go b/test-go/solutions/nbrconvertalpha_prog/main.go deleted file mode 100644 index 952fba16d..000000000 --- a/test-go/solutions/nbrconvertalpha_prog/main.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" -) - -func main() { - args := os.Args[1:] - if len(args) == 0 { - return - } - var upper bool - if args[0] == "--upper" { - upper = true - args = args[1:] - } - for _, arg := range args { - if nb, err := strconv.Atoi(arg); err != nil || nb < 1 || nb > 26 { - fmt.Print(" ") - } else { - if upper { - nb += 'A' - 1 - } else { - nb += 'a' - 1 - } - fmt.Printf("%c", rune(nb)) - } - } - fmt.Println() -} diff --git a/test-go/solutions/nenokku_prog/main.go b/test-go/solutions/nenokku_prog/main.go deleted file mode 100644 index 4f5176e26..000000000 --- a/test-go/solutions/nenokku_prog/main.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" -) - -func main() { - var big string - args := os.Args[1:] - - for _, arg := range args { - split := strings.Split(arg, " ") - ch := split[0] - small := split[1] - - if ch == "x" { - break - } - if ch == "A" { - big += small - } - if ch == "?" { - if strings.Contains(big, small) { - fmt.Println("YES") - } else { - fmt.Println("NO") - } - } - } -} diff --git a/test-go/solutions/onlya_prog/main.go b/test-go/solutions/onlya_prog/main.go deleted file mode 100644 index 712c47599..000000000 --- a/test-go/solutions/onlya_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Print("a") -} diff --git a/test-go/solutions/onlyz_prog/main.go b/test-go/solutions/onlyz_prog/main.go deleted file mode 100644 index e80f2923c..000000000 --- a/test-go/solutions/onlyz_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Print("z") -} diff --git a/test-go/solutions/options_prog/main.go b/test-go/solutions/options_prog/main.go deleted file mode 100644 index f717be9b8..000000000 --- a/test-go/solutions/options_prog/main.go +++ /dev/null @@ -1,50 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func printOptions(op [32]int, i int) { - for _, v := range op { - if i == 8 { - fmt.Print(" ") - i = 0 - } - fmt.Print(v) - i++ - } - fmt.Println() -} - -func main() { - var options [32]int - pos := 1 - size := len(os.Args) - if size < 2 { - fmt.Println("options: abcdefghijklmnopqrstuvwxyz") - } else { - for pos < size { - j := 1 - if os.Args[pos][0] == '-' { - if os.Args[pos][1] == 'h' { - fmt.Println("options: abcdefghijklmnopqrstuvwxyz") - return - } - for j < len(os.Args[pos]) && os.Args[pos][j] >= 'a' && os.Args[pos][j] <= 'z' { - posOption := 'z' - os.Args[pos][j] + 6 - options[posOption] = 1 - j++ - } - - if j < len(os.Args[pos]) && os.Args[pos][j] <= 'a' && os.Args[pos][j] <= 'z' { - fmt.Println("Invalid Option") - return - } - j++ - } - pos++ - } - printOptions(options, 0) - } -} diff --git a/test-go/solutions/paramcount_prog/main.go b/test-go/solutions/paramcount_prog/main.go deleted file mode 100644 index 66746a0d3..000000000 --- a/test-go/solutions/paramcount_prog/main.go +++ /dev/null @@ -1,10 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func main() { - fmt.Println(len(os.Args) - 1) -} diff --git a/test-go/solutions/piglatin_prog/main.go b/test-go/solutions/piglatin_prog/main.go deleted file mode 100644 index 70d166300..000000000 --- a/test-go/solutions/piglatin_prog/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" -) - -func main() { - if len(os.Args) != 2 || os.Args[1] == "" { - return - } - s := os.Args[1] - vowel := strings.IndexAny(s, "aeiouAEIOU") - if vowel == -1 { - fmt.Println("No vowels") - } else { - fmt.Println(string(s[vowel:]) + string(s[:vowel]) + "ay") - } -} diff --git a/test-go/solutions/pilot_prog/main.go b/test-go/solutions/pilot_prog/main.go deleted file mode 100644 index 1e52594cc..000000000 --- a/test-go/solutions/pilot_prog/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import "fmt" - -type Pilot struct { - Name string - Life float32 - Age int - Aircraft int -} - -const Aircraft1 = 1 - -func main() { - donnie := Pilot{ - Name: "Donnie", - Life: 100.0, - Age: 24, - Aircraft: Aircraft1, - } - fmt.Println(donnie) -} diff --git a/test-go/solutions/point_prog/main.go b/test-go/solutions/point_prog/main.go deleted file mode 100644 index bf9b809cd..000000000 --- a/test-go/solutions/point_prog/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import "fmt" - -type point struct { - x int - y int -} - -func setPoint(ptr *point) { - ptr.x = 42 - ptr.y = 21 -} - -func main() { - points := &point{} - - setPoint(points) - - fmt.Printf("x = %d, y = %d", points.x, points.y) - fmt.Println() -} diff --git a/test-go/solutions/printalphabet_prog/main.go b/test-go/solutions/printalphabet_prog/main.go deleted file mode 100644 index 7927c0f4b..000000000 --- a/test-go/solutions/printalphabet_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("abcdefghijklmnopqrstuvwxyz") -} diff --git a/test-go/solutions/printalphabetalt2_prog/main.go b/test-go/solutions/printalphabetalt2_prog/main.go deleted file mode 100644 index e5bea2b5d..000000000 --- a/test-go/solutions/printalphabetalt2_prog/main.go +++ /dev/null @@ -1,8 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("AbCdEfGhIjKlMnOpQrStUvWxYz") - fmt.Println("ZyXwVuTsRqPoNmLkJiHgFeDcBa") -} diff --git a/test-go/solutions/printalphabetalt_prog/main.go b/test-go/solutions/printalphabetalt_prog/main.go deleted file mode 100644 index 5d2fc0c96..000000000 --- a/test-go/solutions/printalphabetalt_prog/main.go +++ /dev/null @@ -1,8 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("aBcDeFgHiJkLmNoPqRsTuVwXyZ") - fmt.Println("zYxWvUtSrQpOnMlKjIhGfEdCbA") -} diff --git a/test-go/solutions/printalphabetg_prog/main.go b/test-go/solutions/printalphabetg_prog/main.go deleted file mode 100644 index 9a0b41821..000000000 --- a/test-go/solutions/printalphabetg_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("abcdefg") -} diff --git a/test-go/solutions/printalt2_prog/main.go b/test-go/solutions/printalt2_prog/main.go deleted file mode 100644 index 93d1cff8e..000000000 --- a/test-go/solutions/printalt2_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("zaybxcwdveuftgshriqjpkolnm") -} diff --git a/test-go/solutions/printalt_prog/main.go b/test-go/solutions/printalt_prog/main.go deleted file mode 100644 index d6a2a44ae..000000000 --- a/test-go/solutions/printalt_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("azbycxdwevfugthsirjqkplomn") -} diff --git a/test-go/solutions/printaltu2_prog/main.go b/test-go/solutions/printaltu2_prog/main.go deleted file mode 100644 index 3cf5a9cc8..000000000 --- a/test-go/solutions/printaltu2_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("ZAYBXCWDVEUFTGSHRIQJPKOLNM") -} diff --git a/test-go/solutions/printaltu_prog/main.go b/test-go/solutions/printaltu_prog/main.go deleted file mode 100644 index a9cd212cb..000000000 --- a/test-go/solutions/printaltu_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("AZBYCXDWEVFUGTHSIRJQKPLOMN") -} diff --git a/test-go/solutions/printbits_prog/main.go b/test-go/solutions/printbits_prog/main.go deleted file mode 100644 index a3fef1363..000000000 --- a/test-go/solutions/printbits_prog/main.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" -) - -func main() { - if len(os.Args) == 2 { - nbr, _ := strconv.Atoi(os.Args[1]) - printBits(byte(nbr)) - } -} - -func printBits(octe byte) { - fmt.Printf("%08b", octe) -} diff --git a/test-go/solutions/printchessboard_prog/main.go b/test-go/solutions/printchessboard_prog/main.go deleted file mode 100644 index 3915fc94c..000000000 --- a/test-go/solutions/printchessboard_prog/main.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" -) - -func solve(x, y int) { - for i := 0; i < x; i++ { - line := "" - for j := 0; j < y; j++ { - if i%2 == 0 && j%2 == 0 { - line += "#" - } else if i%2 == 0 && j%2 == 1 { - line += " " - } else if i%2 == 1 && j%2 == 1 { - line += "#" - } else { - line += " " - } - } - fmt.Println(line) - } -} - -func main() { - args := os.Args[1:] - if len(args) != 2 { - fmt.Println("Error") - return - } - x, _ := strconv.Atoi(args[1]) - y, _ := strconv.Atoi(args[0]) - if x <= 0 || y <= 0 { - fmt.Println("Error") - } else { - solve(x, y) - } -} diff --git a/test-go/solutions/printdigits_prog/main.go b/test-go/solutions/printdigits_prog/main.go deleted file mode 100644 index 872307c12..000000000 --- a/test-go/solutions/printdigits_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("0123456789") -} diff --git a/test-go/solutions/printhex_prog/main.go b/test-go/solutions/printhex_prog/main.go deleted file mode 100644 index 0c0cf2788..000000000 --- a/test-go/solutions/printhex_prog/main.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" -) - -func main() { - if len(os.Args) == 2 { - if i, err := strconv.Atoi(os.Args[1]); err == nil && i > 0 { - fmt.Printf("%x\n", i) - } else { - fmt.Println("ERROR") - } - } -} diff --git a/test-go/solutions/printparams_prog/main.go b/test-go/solutions/printparams_prog/main.go deleted file mode 100644 index 4468610f9..000000000 --- a/test-go/solutions/printparams_prog/main.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func main() { - for _, a := range os.Args[1:] { - fmt.Println(a) - } -} diff --git a/test-go/solutions/printprogramname_prog/main.go b/test-go/solutions/printprogramname_prog/main.go deleted file mode 100644 index aab99c63d..000000000 --- a/test-go/solutions/printprogramname_prog/main.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "fmt" - "os" - "path/filepath" -) - -func main() { - fmt.Println(filepath.Base(os.Args[0])) -} diff --git a/test-go/solutions/printrevcomb_prog/main.go b/test-go/solutions/printrevcomb_prog/main.go deleted file mode 100644 index 0ca625b4f..000000000 --- a/test-go/solutions/printrevcomb_prog/main.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import "fmt" - -func main() { - for a := 9; a >= 2; a-- { - for b := a - 1; b >= 1; b-- { - for c := b - 1; c >= 0; c-- { - fmt.Printf("%d%d%d", a, b, c) - if a+b+c != 3 { - fmt.Print(", ") - } - } - } - } - fmt.Println() -} diff --git a/test-go/solutions/printreversealphabet_prog/main.go b/test-go/solutions/printreversealphabet_prog/main.go deleted file mode 100644 index 5ef689aa3..000000000 --- a/test-go/solutions/printreversealphabet_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("zyxwvutsrqponmlkjihgfedcba") -} diff --git a/test-go/solutions/printreversealphabetalt2_prog/main.go b/test-go/solutions/printreversealphabetalt2_prog/main.go deleted file mode 100644 index 1a2055215..000000000 --- a/test-go/solutions/printreversealphabetalt2_prog/main.go +++ /dev/null @@ -1,8 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("ZyXwVuTsRqPoNmLkJiHgFeDcBa") - fmt.Println("AbCdEfGhIjKlMnOpQrStUvWxYz") -} diff --git a/test-go/solutions/printreversealphabetalt_prog/main.go b/test-go/solutions/printreversealphabetalt_prog/main.go deleted file mode 100644 index be5bf53f5..000000000 --- a/test-go/solutions/printreversealphabetalt_prog/main.go +++ /dev/null @@ -1,8 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("zYxWvUtSrQpOnMlKjIhGfEdCbA") - fmt.Println("aBcDeFgHiJkLmNoPqRsTuVwXyZ") -} diff --git a/test-go/solutions/printreversealphabetg_prog/main.go b/test-go/solutions/printreversealphabetg_prog/main.go deleted file mode 100644 index 8bf734bf5..000000000 --- a/test-go/solutions/printreversealphabetg_prog/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("gfedcba") -} diff --git a/test-go/solutions/printrot_prog/main.go b/test-go/solutions/printrot_prog/main.go deleted file mode 100644 index 7d845890e..000000000 --- a/test-go/solutions/printrot_prog/main.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func printAnswer(letter rune) { - answer := []rune{} - for i := letter; i <= 'z'; i++ { - answer = append(answer, i) - } - for j := 'a'; j < letter; j++ { - answer = append(answer, j) - } - fmt.Println(string(answer)) -} - -func main() { - if len(os.Args) == 2 { - letter := os.Args[1] - if len(letter) == 1 { - letterConverted := []rune(letter) - if letterConverted[0] >= 'a' && letterConverted[0] <= 'z' { - printAnswer(letterConverted[0]) - } - } else { - fmt.Println() - } - } else { - fmt.Println() - } -} diff --git a/test-go/solutions/raid3_prog/main.go b/test-go/solutions/raid3_prog/main.go deleted file mode 100644 index 936ff0e7e..000000000 --- a/test-go/solutions/raid3_prog/main.go +++ /dev/null @@ -1,87 +0,0 @@ -package main - -import ( - "bufio" - "fmt" - "os" - "strconv" - "strings" -) - -// counts in the Cartesian coordinates x and y -func countXY(output []rune) (x, y int) { - countX := 0 - countY := 0 - flag := false - for _, s := range output { - if s == '\n' { - countY++ - flag = true - } else if !flag { - countX++ - } - } - return countX, countY -} - -func determineInput(output []rune) { - x, y := countXY(output) - // the leftC and rightC -> position of the corners - // this will be to see what raid1 is being used - // for the lower left corner - leftC := ((x * y) + y - 1) - x - // for the lower right corner - rightC := (x * y) + y - 2 - // for the upper right corner - rightUpC := x - 1 - - X := strconv.Itoa(x) - Y := strconv.Itoa(y) - result := isPipedWith(output, leftC, rightC, rightUpC, X, Y) - fmt.Println(strings.Join(result, " || ")) -} - -func isPipedWith(output []rune, leftC, rightC, rightUpC int, x, y string) []string { - result := []string{} - - if output[0] == 'o' { - result = append(result, "[raid1a] ["+x+"] ["+y+"]") - } else if output[0] == '/' { - result = append(result, "[raid1b] ["+x+"] ["+y+"]") - } else if output[0] == 'A' { - if (output[rightUpC] == 'A' && output[rightC] == 'C') || - (output[rightUpC] == 'A' && y == "1") || - (x == "1" && y == "1") { - result = append(result, "[raid1c] ["+x+"] ["+y+"]") - } - if (output[rightUpC] == 'C' && output[leftC] == 'A') || - (output[leftC] == 'A' && x == "1") || - (x == "1" && y == "1") { - result = append(result, "[raid1d] ["+x+"] ["+y+"]") - } - if (output[leftC] == 'C' && x == "1") || - (output[rightUpC] == 'C' && y == "1") || - (output[rightUpC] == 'C' && output[leftC] == 'C') || - (x == "1" && y == "1") { - result = append(result, "[raid1e] ["+x+"] ["+y+"]") - } - } - return result -} - -func main() { - reader := bufio.NewReader(os.Stdin) - var output []rune - for { - input, _, err := reader.ReadRune() - if err != nil { - break - } - output = append(output, input) - } - if output[0] != 'o' && output[0] != '/' && output[0] != 'A' { - fmt.Println("Not a Raid function") - return - } - determineInput(output) -} diff --git a/test-go/solutions/range_prog/main.go b/test-go/solutions/range_prog/main.go deleted file mode 100644 index 500658423..000000000 --- a/test-go/solutions/range_prog/main.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" -) - -func main() { - if len(os.Args) != 3 { - return - } - a, err := strconv.Atoi(os.Args[1]) - if err != nil { - fmt.Println(err) - return - } - b, err := strconv.Atoi(os.Args[2]) - if err != nil { - fmt.Println(err) - return - } - fmt.Print(a) - for b != a { - if a < b { - a++ - } else { - a-- - } - fmt.Print(" ", a) - } - fmt.Println() -} diff --git a/test-go/solutions/rectangle_prog/main.go b/test-go/solutions/rectangle_prog/main.go deleted file mode 100644 index ea66623ed..000000000 --- a/test-go/solutions/rectangle_prog/main.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import "fmt" - -type point struct { - x int - y int -} - -type rectangle struct { - upLeft point - downRight point -} - -func defineRectangle(vPoint []point, n int) *rectangle { - xmin := vPoint[0].x - xmax := vPoint[0].x - ymin := vPoint[0].y - ymax := vPoint[0].y - - ptr := &rectangle{} - - for i := 0; i < n; i++ { - if vPoint[i].x < xmin { - xmin = vPoint[i].x - } - if vPoint[i].x > xmax { - xmax = vPoint[i].x - } - if vPoint[i].y < ymin { - ymin = vPoint[i].y - } - if vPoint[i].y > ymax { - ymax = vPoint[i].y - } - } - ptr.upLeft.x = xmin - ptr.upLeft.y = ymax - ptr.downRight.x = xmax - ptr.downRight.y = ymin - - return ptr -} - -func calcArea(ptr *rectangle) int { - return (ptr.upLeft.x - ptr.downRight.x) * (ptr.downRight.y - ptr.upLeft.y) -} - -func main() { - vPoint := []point{} - rectangle := &rectangle{} - n := 7 - - for i := 0; i < n; i++ { - val := point{ - x: i%2 + 1, - y: i + 2, - } - vPoint = append(vPoint, val) - } - - rectangle = defineRectangle(vPoint, n) - fmt.Println("area of the rectangle:", calcArea(rectangle)) -} diff --git a/test-go/solutions/repeatalpha_prog/main.go b/test-go/solutions/repeatalpha_prog/main.go deleted file mode 100644 index d2ec0712b..000000000 --- a/test-go/solutions/repeatalpha_prog/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "fmt" - "os" - "unicode" -) - -func main() { - if len(os.Args) == 2 { - for _, r := range os.Args[1] { - fmt.Printf("%c", r) - if unicode.IsLetter(r) { - rep := unicode.ToLower(r) - 'a' - for i := 0; i < int(rep); i++ { - fmt.Printf("%c", r) - } - } - } - fmt.Println() - } -} diff --git a/test-go/solutions/reverserange_prog/main.go b/test-go/solutions/reverserange_prog/main.go deleted file mode 100644 index 621cb0515..000000000 --- a/test-go/solutions/reverserange_prog/main.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" -) - -func main() { - if len(os.Args) != 3 { - return - } - a, err := strconv.Atoi(os.Args[1]) - if err != nil { - fmt.Println(err) - return - } - b, err := strconv.Atoi(os.Args[2]) - if err != nil { - fmt.Println(err) - return - } - fmt.Print(b) - for a != b { - if b < a { - b++ - } else { - b-- - } - fmt.Print(" ", b) - } - fmt.Println() -} diff --git a/test-go/solutions/reversestrcap_prog/main.go b/test-go/solutions/reversestrcap_prog/main.go deleted file mode 100644 index 3b2b11f2d..000000000 --- a/test-go/solutions/reversestrcap_prog/main.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "fmt" - "os" - "unicode" -) - -func main() { - for _, arg := range os.Args[1:] { - arg := []rune(arg) - for j, r := range arg { - if j+1 == len(arg) || arg[j+1] == ' ' { - arg[j] = unicode.ToUpper(r) - } else { - arg[j] = unicode.ToLower(r) - } - } - fmt.Println(string(arg)) - } -} diff --git a/test-go/solutions/revparams_prog/main.go b/test-go/solutions/revparams_prog/main.go deleted file mode 100644 index 722d8a36b..000000000 --- a/test-go/solutions/revparams_prog/main.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func main() { - for i := len(os.Args) - 1; i >= 1; i-- { - fmt.Println(os.Args[i]) - } -} diff --git a/test-go/solutions/revwstr_prog/main.go b/test-go/solutions/revwstr_prog/main.go deleted file mode 100644 index 0ffae714c..000000000 --- a/test-go/solutions/revwstr_prog/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" -) - -func main() { - if len(os.Args) == 2 { - a := strings.Split(os.Args[1], " ") - for i := len(a) - 1; i >= 0; i-- { - fmt.Print(a[i]) - if i != 0 { - fmt.Print(" ") - } - } - fmt.Println() - } -} diff --git a/test-go/solutions/robottoorigin_prog/main.go b/test-go/solutions/robottoorigin_prog/main.go deleted file mode 100644 index 90a1e6301..000000000 --- a/test-go/solutions/robottoorigin_prog/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func solve(s string) bool { - x := 0 - y := 0 - - for _, r := range s { - switch r { - case 'L': - x-- - case 'R': - x++ - case 'U': - y++ - case 'D': - y-- - } - } - return x == 0 && y == 0 -} - -func main() { - if len(os.Args) == 2 { - fmt.Println(solve(os.Args[1])) - } -} diff --git a/test-go/solutions/romannumbers_prog/main.go b/test-go/solutions/romannumbers_prog/main.go deleted file mode 100644 index bc2319e85..000000000 --- a/test-go/solutions/romannumbers_prog/main.go +++ /dev/null @@ -1,66 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" - "strings" -) - -type roman struct { - num int - romanDigit string -} - -func main() { - if len(os.Args) == 2 { - nbr, err := strconv.Atoi(os.Args[1]) - if err != nil || nbr >= 4000 || nbr == 0 { - fmt.Println("ERROR: can not convert to roman digit") - return - } - patter := []roman{ - {num: 1000, romanDigit: "M"}, - {num: 900, romanDigit: "CM"}, - {num: 500, romanDigit: "D"}, - {num: 400, romanDigit: "CD"}, - {num: 100, romanDigit: "C"}, - {num: 90, romanDigit: "XC"}, - {num: 50, romanDigit: "L"}, - {num: 40, romanDigit: "XL"}, - {num: 10, romanDigit: "X"}, - {num: 9, romanDigit: "IX"}, - {num: 5, romanDigit: "V"}, - {num: 4, romanDigit: "IV"}, - {num: 1, romanDigit: "I"}, - } - sumRoman, romandigit := print(nbr, patter) - fmt.Println(strings.TrimSuffix(sumRoman, "+")) - fmt.Println(romandigit) - } -} - -func print(nbr int, patter []roman) (string, string) { - var sumRomanDigit, result string - for _, v := range patter { - for nbr >= v.num { - sumRomanDigit += v.romanDigit + "+" - result += v.romanDigit - nbr -= v.num - } - } - sumRomanDigit = formatsum(sumRomanDigit, patter) - return sumRomanDigit, result -} - -func formatsum(a string, patter []roman) string { - result2 := strings.Split(a, "+") - - for i, v := range result2 { - if len(v) == 2 { - result2[i] = fmt.Sprintf("(%s-%s)", string(result2[i][1]), string(result2[i][0])) - } - } - a = strings.Join(result2, "+") - return a -} diff --git a/test-go/solutions/rostring_prog/main.go b/test-go/solutions/rostring_prog/main.go deleted file mode 100644 index 896c44af3..000000000 --- a/test-go/solutions/rostring_prog/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" -) - -func deleteExtraSpaces(a []string) []string { - var res []string - for _, v := range a { - if v != "" { - res = append(res, v) - } - } - return res -} - -func main() { - if len(os.Args) == 2 { - words := strings.Split(os.Args[1], " ") - words = deleteExtraSpaces(words) - if len(words) >= 1 { - for _, v := range words[1:] { - fmt.Print(v, " ") - } - fmt.Print(words[0]) - } - } - fmt.Println() -} diff --git a/test-go/solutions/rot13_prog/main.go b/test-go/solutions/rot13_prog/main.go deleted file mode 100644 index fdcfb4bd4..000000000 --- a/test-go/solutions/rot13_prog/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func main() { - if len(os.Args) == 2 { - for _, r := range os.Args[1] { - if r >= 'a' && r <= 'z' { - if r >= 'a'+13 { - r -= 13 - } else { - r += 13 - } - } else if r >= 'A' && r <= 'Z' { - if r >= 'A'+13 { - r -= 13 - } else { - r += 13 - } - } - fmt.Printf("%c", r) - } - fmt.Println() - } -} diff --git a/test-go/solutions/rotatevowels_prog/main.go b/test-go/solutions/rotatevowels_prog/main.go deleted file mode 100644 index 979d777e6..000000000 --- a/test-go/solutions/rotatevowels_prog/main.go +++ /dev/null @@ -1,37 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" -) - -func main() { - var a1, a2, rev []rune - for _, arg := range os.Args[1:] { - for _, k := range arg { - if strings.ContainsRune("aeiouAEIOU", k) { - a1 = append(a1, k) - } - } - } - for i := len(a1) - 1; i >= 0; i-- { - rev = append(rev, a1[i]) - } - - m := 0 - for i, arg := range os.Args[1:] { - for _, j := range arg { - if strings.ContainsRune("aeiouAEIOU", j) { - a2 = append(a2, rev[m]) - m++ - } else { - a2 = append(a2, j) - } - } - if i != len(os.Args)-1 { - a2 = append(a2, ' ') - } - } - fmt.Println(string(a2)) -} diff --git a/test-go/solutions/rpncalc_prog/main.go b/test-go/solutions/rpncalc_prog/main.go deleted file mode 100644 index 74224b544..000000000 --- a/test-go/solutions/rpncalc_prog/main.go +++ /dev/null @@ -1,67 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" - "strings" -) - -func deleteExtraSpaces(a []string) (res []string) { - for _, v := range a { - if v != "" { - res = append(res, v) - } - } - return -} - -func main() { - if len(os.Args) != 2 { - fmt.Println("Error") - return - } - var values []int - op := strings.Split(os.Args[1], " ") - op = deleteExtraSpaces(op) - for _, v := range op { - val, err := strconv.Atoi(v) - - if err == nil { - values = append(values, val) - continue - } - - n := len(values) - if n < 2 { - fmt.Println("Error") - return - } - - switch v { - case "+": - values[n-2] += values[n-1] - values = values[:n-1] - case "-": - values[n-2] -= values[n-1] - values = values[:n-1] - case "*": - values[n-2] *= values[n-1] - values = values[:n-1] - case "/": - values[n-2] /= values[n-1] - values = values[:n-1] - case "%": - values[n-2] %= values[n-1] - values = values[:n-1] - default: - fmt.Println("Error") - return - } - } - if len(values) == 1 { - fmt.Println(values[0]) - } else { - fmt.Println("Error") - } -} diff --git a/test-go/solutions/searchreplace_prog/main.go b/test-go/solutions/searchreplace_prog/main.go deleted file mode 100644 index 41f2b2d8a..000000000 --- a/test-go/solutions/searchreplace_prog/main.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" -) - -func main() { - if len(os.Args) == 4 { - fmt.Println(strings.Map(func(r rune) rune { - if r == []rune(os.Args[2])[0] { - return []rune(os.Args[3])[0] - } - return r - }, os.Args[1])) - } -} diff --git a/test-go/solutions/sortedlistmerge.go b/test-go/solutions/sortedlistmerge.go deleted file mode 100644 index c9f65823a..000000000 --- a/test-go/solutions/sortedlistmerge.go +++ /dev/null @@ -1,16 +0,0 @@ -package solutions - -func SortedListMerge(l1 *NodeI, l2 *NodeI) *NodeI { - if l1 == nil { - return l2 - } - if l2 == nil { - return l1 - } - if l1.Data <= l2.Data { - l1.Next = SortedListMerge(l1.Next, l2) - return l1 - } - l2.Next = SortedListMerge(l1, l2.Next) - return l2 -} diff --git a/test-go/solutions/sortlistinsert.go b/test-go/solutions/sortlistinsert.go deleted file mode 100644 index 1342a7ed6..000000000 --- a/test-go/solutions/sortlistinsert.go +++ /dev/null @@ -1,25 +0,0 @@ -package solutions - -// structures for the linked lists -type NodeI struct { - Data int - Next *NodeI -} - -func SortListInsert(l *NodeI, data_ref int) *NodeI { - n := &NodeI{Data: data_ref} - n.Next = nil - - if l == nil || l.Data >= n.Data { - n.Next = l - return n - } - temp := l - for temp.Next != nil && temp.Next.Data < n.Data { - temp = temp.Next - } - n.Next = temp.Next - temp.Next = n - - return l -} diff --git a/test-go/solutions/sortparams_prog/main.go b/test-go/solutions/sortparams_prog/main.go deleted file mode 100644 index 8f6fed34a..000000000 --- a/test-go/solutions/sortparams_prog/main.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "fmt" - "os" - "sort" -) - -func main() { - args := os.Args[1:] - sort.Strings(args) - for _, v := range args { - fmt.Println(v) - } -} diff --git a/test-go/solutions/sudoku_prog/main.go b/test-go/solutions/sudoku_prog/main.go deleted file mode 100644 index 8e4c22ee3..000000000 --- a/test-go/solutions/sudoku_prog/main.go +++ /dev/null @@ -1,164 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -// Prints in standard output the sudoku board -func printBoard(board [][]rune) { - for _, row := range board { - for i, e := range row { - fmt.Printf("%c", e) - if i != len(row)-1 { - fmt.Print(" ") - } - } - fmt.Println() - } -} - -// Return true if the value 'value' is in the row 'y' of the board 'board' -func isInRow(board [][]rune, value rune, x, y int) bool { - for i, v := range board[y] { - if i != x && v == value { - return true - } - } - return false -} - -// Returns true if the value 'value' is in the column 'x' of the board 'board' -func isInColumn(board [][]rune, value rune, x, y int) bool { - for i := 0; i < 9; i++ { - if i != y && board[i][x] == value { - return true - } - } - return false -} - -// Receives an int 'x' and returns the beginning and the end -// of the interval of consecutive pairs of multiples of three 'x' is in. -// Ex. for x = 2, x is in (0, 3) -// for x = 4, x is in (3, 6) -func intervalThree(x int, max int) (int, int) { - var i int - for i = 0; i < max; i += 3 { - if x >= i && x < i+3 { - break - } - } - endi := 3 + i - return i, endi -} - -// Returns true if the value 'value' is allowed in the possition (x,y) of the board 'board' -func isAllowedInBox(board [][]rune, value rune, x, y int) bool { - n := len(board) - begi, endi := intervalThree(x, n) - begj, endj := intervalThree(y, n) - for j := begj; j < endj; j++ { - for i := begi; i < endi; i++ { - if (j != y || i != i) && board[j][i] == value { - return false - } - } - } - return true -} - -// Returns true if the value 'val' is allowed in the position (x, y) of the board -func isAllowed(board [][]rune, val rune, x, y int) bool { - return !isInRow(board, val, x, y) && - !isInColumn(board, val, x, y) && - isAllowedInBox(board, val, x, y) -} - -// Returns true if the position doesn't have any value defined -// That is, if the character is a dot '.' -func isEmpty(board [][]rune, x, y int) bool { - return board[y][x] == '.' -} - -// Returns all the empty positions in the board -func availablePos(board [][]rune) [][]int { - var ava [][]int - for y, row := range board { - for x, e := range row { - if e == '.' { - ava = append(ava, []int{x, y}) - } - } - } - return ava -} - -func validBoard(board [][]rune) bool { - size := 9 - if len(board) != size { - return false - } - for y, row := range board { - if len(row) != size { - return false - } - for x, e := range row { - if (e < '1' || e > '9') && e != '.' { - return false - } - if e != '.' && !isAllowed(board, e, x, y) { - return false - } - } - } - return true -} - -// Returns true if the sudoku has a solution -func sudokuH(board [][]rune, available [][]int, i int) bool { - n := len(available) - - if i >= n { - return true - } - - x := available[i][0] - y := available[i][1] - - for c := '1'; c <= '9'; c++ { - if isAllowed(board, c, x, y) { - board[y][x] = c - if sudokuH(board, available, i+1) { - return true - } - board[y][x] = '.' - } - } - return false -} - -// Receives a board and fills the empty positions with the correct -// value -func solveSudoku(board [][]rune) { - available := availablePos(board) - if sudokuH(board, available, 0) { - printBoard(board) - } else { - fmt.Println("Error") - } -} - -func main() { - var board [][]rune - - for _, v := range os.Args[1:] { - board = append(board, []rune(v)) - } - - if validBoard(board) { - solveSudoku(board) - } else { - fmt.Println("Error") - } -} diff --git a/test-go/solutions/switchcase_prog/main.go b/test-go/solutions/switchcase_prog/main.go deleted file mode 100644 index 0dece4ffe..000000000 --- a/test-go/solutions/switchcase_prog/main.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "fmt" - "os" - "unicode" -) - -func main() { - if len(os.Args) == 2 { - runes := []rune(os.Args[1]) - for i, r := range runes { - if unicode.IsLower(r) { - runes[i] = unicode.ToUpper(r) - } else if unicode.IsUpper(r) { - runes[i] = unicode.ToLower(r) - } - } - fmt.Println(string(runes)) - } -} diff --git a/test-go/solutions/tabmult_prog/main.go b/test-go/solutions/tabmult_prog/main.go deleted file mode 100644 index 52fb3ea1a..000000000 --- a/test-go/solutions/tabmult_prog/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" -) - -func tabmul(nbr int) { - i := 1 - for i < 10 { - result := nbr * i - fmt.Println(i, "x", nbr, "=", result) - i++ - } -} - -func main() { - if len(os.Args) == 2 { - number, _ := strconv.Atoi(os.Args[1]) - tabmul(number) - } else { - fmt.Println() - } -} diff --git a/test-go/solutions/tetrisoptimizer_prog/board.go b/test-go/solutions/tetrisoptimizer_prog/board.go deleted file mode 100644 index f490ab679..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/board.go +++ /dev/null @@ -1,62 +0,0 @@ -package main - -import "fmt" - -type board [][]byte - -func makeBoard(size int) board { - var b board - for i := 0; i < size; i++ { - row := make([]byte, size) - for j := range row { - row[j] = dot - } - b = append(b, row) - } - return b -} - -func (b board) print() { - for i := range b { - fmt.Println(string(b[i])) - } -} - -func (b board) check(i, j int, t tetrimino) bool { - for y := range t { - for x := range t[y] { - if t[y][x] != hashTag { - continue - } - if i+y >= len(b) || j+x >= len(b[i+y]) { - return false - } - if b[i+y][j+x] != dot { - return false - } - } - } - return true -} - -func (b board) put(i, j, idx int, t tetrimino) { - for y := range t { - for x := range t[y] { - if t[y][x] != hashTag { - continue - } - b[i+y][j+x] = byte(idx + 'A') - } - } -} - -func (b board) remove(i, j int, t tetrimino) { - for y := range t { - for x := range t[y] { - if t[y][x] != hashTag { - continue - } - b[i+y][j+x] = dot - } - } -} diff --git a/test-go/solutions/tetrisoptimizer_prog/main.go b/test-go/solutions/tetrisoptimizer_prog/main.go deleted file mode 100644 index 7945f8824..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/main.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "os" -) - -func main() { - if len(os.Args) != 2 { - fmt.Println("usage: ./fillit filename") - return - } - data, err := ioutil.ReadFile(os.Args[1]) - if err != nil { - fmt.Println(err) - return - } - ok, tetriminos := validateFile(data) - if !ok { - fmt.Println("ERROR") - return - } - board := solve(tetriminos) - board.print() -} diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/bad00.txt b/test-go/solutions/tetrisoptimizer_prog/samples/bad00.txt deleted file mode 100644 index 64d5de093..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/bad00.txt +++ /dev/null @@ -1,4 +0,0 @@ -#### -...# -.... -.... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/bad01.txt b/test-go/solutions/tetrisoptimizer_prog/samples/bad01.txt deleted file mode 100644 index bb2ccae55..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/bad01.txt +++ /dev/null @@ -1,4 +0,0 @@ -...# -..#. -.#.. -#... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/bad02.txt b/test-go/solutions/tetrisoptimizer_prog/samples/bad02.txt deleted file mode 100644 index c67b3173b..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/bad02.txt +++ /dev/null @@ -1,5 +0,0 @@ - -##... -##... -.... -.... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/bad03.txt b/test-go/solutions/tetrisoptimizer_prog/samples/bad03.txt deleted file mode 100644 index eed9fcddd..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/bad03.txt +++ /dev/null @@ -1,4 +0,0 @@ -.... -.... -.... -.... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/bad04.txt b/test-go/solutions/tetrisoptimizer_prog/samples/bad04.txt deleted file mode 100644 index ddaf7ff6d..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/bad04.txt +++ /dev/null @@ -1,5 +0,0 @@ - -..## -.... -.... -##.. diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/badFormat.txt b/test-go/solutions/tetrisoptimizer_prog/samples/badFormat.txt deleted file mode 100644 index 182189f7a..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/badFormat.txt +++ /dev/null @@ -1,19 +0,0 @@ -...# -...# -...# -...# -.... -.... -.... -#### - - -.### -...# -.... -.... - -.... -..## -.##. -.... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_01-1-2-0.00.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_01-1-2-0.00.txt deleted file mode 100644 index 5e48cb0d1..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_01-1-2-0.00.txt +++ /dev/null @@ -1,4 +0,0 @@ -..## -..## -.... -.... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_02-1-4-0.00.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_02-1-4-0.00.txt deleted file mode 100644 index caa819e10..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_02-1-4-0.00.txt +++ /dev/null @@ -1,4 +0,0 @@ -#... -#... -#... -#... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_03-2-4-0.00.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_03-2-4-0.00.txt deleted file mode 100644 index e91908825..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_03-2-4-0.00.txt +++ /dev/null @@ -1,9 +0,0 @@ -.... -..#. -.### -.... - -.... -.... -...# -.### diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_04-6-6-0.00.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_04-6-6-0.00.txt deleted file mode 100644 index 56562983d..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_04-6-6-0.00.txt +++ /dev/null @@ -1,29 +0,0 @@ -.##. -.##. -.... -.... - -..## -..## -.... -.... - -..## -..## -.... -.... - -.... -...# -..## -...# - -.... -.... -##.. -##.. - -.... -.... -.... -#### diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_05-21-10-0.00.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_05-21-10-0.00.txt deleted file mode 100644 index 9e961e2b5..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_05-21-10-0.00.txt +++ /dev/null @@ -1,104 +0,0 @@ -.... -...# -..## -...# - -.... -.... -..## -..## - -.... -...# -...# -..## - -.... -#... -###. -.... - -.... -##.. -.##. -.... - -..## -...# -...# -.... - -.... -.... -#... -###. - -.### -.#.. -.... -.... - -#... -#... -##.. -.... - -.... -.... -##.. -##.. - -.... -...# -..## -..#. - -.... -.... -..## -.##. - -.#.. -##.. -#... -.... - -.### -.#.. -.... -.... - -...# -...# -..## -.... - -.##. -.##. -.... -.... - -.### -...# -.... -.... - -.... -##.. -.#.. -.#.. - -.##. -.#.. -.#.. -.... - -.#.. -.##. -.#.. -.... - -#... -#... -#... -#... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_06-22-10-0.00.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_06-22-10-0.00.txt deleted file mode 100644 index 24f868929..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_06-22-10-0.00.txt +++ /dev/null @@ -1,109 +0,0 @@ -...# -..## -...# -.... - -.... -..#. -..#. -..## - -.... -.... -..## -..## - -.... -.... -.##. -.##. - -.... -.... -##.. -##.. - -.... -.... -###. -.#.. - -.... -.... -###. -#... - -###. -#... -.... -.... - -..## -..## -.... -.... - -###. -#... -.... -.... - -..## -..## -.... -.... - -.##. -##.. -.... -.... - -.... -.### -..#. -.... - -##.. -##.. -.... -.... - -.... -.### -...# -.... - -..## -.##. -.... -.... - -.##. -.##. -.... -.... - -.... -.... -...# -.### - -..## -..## -.... -.... - -##.. -.##. -.... -.... - -..## -.##. -.... -.... - -.... -.... -#... -###. diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_07-26-11-0.00.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_07-26-11-0.00.txt deleted file mode 100644 index 8fc25118e..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_07-26-11-0.00.txt +++ /dev/null @@ -1,129 +0,0 @@ -.... -.... -##.. -##.. - -.... -.### -...# -.... - -.... -.... -..#. -###. - -.... -##.. -##.. -.... - -.... -###. -#... -.... - -##.. -##.. -.... -.... - -.... -.... -..## -..## - -.... -#... -##.. -#... - -###. -#... -.... -.... - -.... -.... -..## -.##. - -.### -..#. -.... -.... - -.... -##.. -##.. -.... - -.... -.... -.##. -.##. - -.... -.... -##.. -##.. - -.... -..## -..## -.... - -.... -..#. -..## -...# - -.... -.##. -..#. -..#. - -.... -...# -...# -..## - -..## -...# -...# -.... - -.... -.... -###. -..#. - -.... -..#. -.### -.... - -.### -...# -.... -.... - -##.. -.#.. -.#.. -.... - -.### -...# -.... -.... - -..#. -..#. -..## -.... - -##.. -#... -#... -.... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_08-24-10-0.03.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_08-24-10-0.03.txt deleted file mode 100644 index e0d1ac989..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_08-24-10-0.03.txt +++ /dev/null @@ -1,119 +0,0 @@ -...# -...# -...# -...# - -.... -.... -###. -#... - -.... -.##. -.#.. -.#.. - -...# -...# -...# -...# - -.... -..#. -..#. -..## - -.... -.... -.##. -..## - -...# -...# -..## -.... - -##.. -#... -#... -.... - -.... -.... -..## -..## - -.... -...# -...# -..## - -.... -.... -#... -###. - -.... -.#.. -.#.. -##.. - -##.. -##.. -.... -.... - -##.. -##.. -.... -.... - -.... -.... -##.. -.##. - -..#. -..#. -..## -.... - -.... -.... -###. -#... - -.... -.... -##.. -##.. - -.... -.... -...# -.### - -##.. -##.. -.... -.... - -.... -##.. -#... -#... - -###. -.#.. -.... -.... - -##.. -.#.. -.#.. -.... - -.### -..#. -.... -.... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_09-11-7-0.07.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_09-11-7-0.07.txt deleted file mode 100644 index 1fec3315d..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_09-11-7-0.07.txt +++ /dev/null @@ -1,54 +0,0 @@ -.##. -##.. -.... -.... - -.#.. -.#.. -##.. -.... - -.... -.... -.##. -##.. - -...# -...# -..## -.... - -..#. -###. -.... -.... - -...# -...# -..## -.... - -.... -.... -.##. -.##. - -.... -.#.. -.#.. -##.. - -.... -.... -...# -.### - -.... -.... -##.. -##.. - -.... -.##. -##.. -.... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_10-12-7-0.52.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_10-12-7-0.52.txt deleted file mode 100644 index b0fbd7e41..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_10-12-7-0.52.txt +++ /dev/null @@ -1,59 +0,0 @@ -##.. -.##. -.... -.... - -.... -.... -.##. -.##. - -.#.. -##.. -#... -.... - -.... -.#.. -.### -.... - -.... -..#. -..#. -..## - -.#.. -.##. -..#. -.... - -.... -.... -##.. -.##. - -##.. -.##. -.... -.... - -.... -##.. -##.. -.... - -...# -...# -..## -.... - -##.. -#... -#... -.... - -.... -...# -..## -..#. diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_11-12-8-0.83.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_11-12-8-0.83.txt deleted file mode 100644 index d4192b316..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_11-12-8-0.83.txt +++ /dev/null @@ -1,59 +0,0 @@ -#... -##.. -#... -.... - -###. -..#. -.... -.... - -..## -..## -.... -.... - -.... -.... -.### -...# - -.... -##.. -##.. -.... - -.... -.... -#... -###. - -.... -.### -.#.. -.... - -.... -.### -...# -.... - -..## -..## -.... -.... - -.... -.... -..## -..## - -.... -.... -..## -..## - -.... -..## -..## -.... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_12-19-9-3.40.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_12-19-9-3.40.txt deleted file mode 100644 index d0bf39847..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_12-19-9-3.40.txt +++ /dev/null @@ -1,94 +0,0 @@ -###. -..#. -.... -.... - -#... -#... -##.. -.... - -.... -.### -..#. -.... - -.... -.##. -..#. -..#. - -.... -..#. -..#. -.##. - -..## -...# -...# -.... - -.... -.... -..#. -###. - -.... -##.. -.##. -.... - -.... -.... -##.. -##.. - -.### -..#. -.... -.... - -.### -.#.. -.... -.... - -.... -#... -#... -##.. - -#### -.... -.... -.... - -#... -##.. -#... -.... - -###. -..#. -.... -.... - -###. -.#.. -.... -.... - -.... -..#. -..## -...# - -.... -.... -.##. -##.. - -#... -##.. -#... -.... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_13-23-10-4.72.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_13-23-10-4.72.txt deleted file mode 100644 index 37463ef49..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_13-23-10-4.72.txt +++ /dev/null @@ -1,114 +0,0 @@ -.... -.... -..## -.##. - -##.. -##.. -.... -.... - -##.. -##.. -.... -.... - -.... -..#. -..#. -..## - -.... -.... -.##. -##.. - -..## -..## -.... -.... - -...# -..## -..#. -.... - -.... -.... -.##. -.##. - -.##. -..#. -..#. -.... - -#... -###. -.... -.... - -...# -...# -...# -...# - -.... -.... -...# -.### - -.### -..#. -.... -.... - -.... -..#. -..## -...# - -.... -.... -..## -.##. - -#... -##.. -#... -.... - -.... -.... -..## -..## - -.### -...# -.... -.... - -.### -.#.. -.... -.... - -.... -.... -###. -#... - -.##. -.##. -.... -.... - -.### -...# -.... -.... - -..## -...# -...# -.... diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_14-15-8-7.34.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_14-15-8-7.34.txt deleted file mode 100644 index 29b8253a2..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_14-15-8-7.34.txt +++ /dev/null @@ -1,74 +0,0 @@ -.... -..## -..## -.... - -...# -.### -.... -.... - -.... -.... -##.. -.##. - -.... -.... -..## -..## - -#### -.... -.... -.... - -.#.. -.#.. -.#.. -.#.. - -.... -.... -##.. -##.. - -.... -.... -.### -...# - -.... -.##. -.#.. -.#.. - -.##. -.##. -.... -.... - -.... -.##. -..## -.... - -.... -.... -..## -..## - -.... -.... -###. -.#.. - -.... -.... -##.. -##.. - -..#. -..#. -..#. -..#. diff --git a/test-go/solutions/tetrisoptimizer_prog/samples/good_15-26-11-72.22.txt b/test-go/solutions/tetrisoptimizer_prog/samples/good_15-26-11-72.22.txt deleted file mode 100644 index 2122d423a..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/samples/good_15-26-11-72.22.txt +++ /dev/null @@ -1,129 +0,0 @@ -.... -.#.. -##.. -.#.. - -.... -.#.. -.#.. -.##. - -.... -.#.. -.#.. -.##. - -.... -.... -##.. -.##. - -.#.. -##.. -#... -.... - -#... -#... -#... -#... - -###. -#... -.... -.... - -.##. -.##. -.... -.... - -.... -..#. -..## -...# - -.##. -.#.. -.#.. -.... - -.... -.#.. -.##. -..#. - -.... -.### -..#. -.... - -.... -#... -##.. -.#.. - -.... -.... -##.. -##.. - -.... -.... -##.. -##.. - -.... -.... -.##. -.##. - -.... -.... -##.. -##.. - -###. -..#. -.... -.... - -.... -..#. -..## -...# - -.... -.... -.### -...# - -.... -..#. -.##. -.#.. - -.... -##.. -##.. -.... - -.##. -..#. -..#. -.... - -###. -.#.. -.... -.... - -.... -.... -.##. -.##. - -##.. -#... -#... -.... diff --git a/test-go/solutions/tetrisoptimizer_prog/solver.go b/test-go/solutions/tetrisoptimizer_prog/solver.go deleted file mode 100644 index cee3404d9..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/solver.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -func recursion(b board, a []tetrimino, idx int) bool { - if idx == len(a) { - return true - } - for i := range b { - for j := range b[i] { - if !b.check(i, j, a[idx]) { - continue - } - b.put(i, j, idx, a[idx]) - if recursion(b, a, idx+1) { - return true - } - b.remove(i, j, a[idx]) - } - } - return false -} - -func solve(a []tetrimino) board { - square := 2 - for square*square < len(a)*4 { - square++ - } - for { - b := makeBoard(square) - square++ - if !recursion(b, a, 0) { - continue - } - return b - } -} diff --git a/test-go/solutions/tetrisoptimizer_prog/tetrimino.go b/test-go/solutions/tetrisoptimizer_prog/tetrimino.go deleted file mode 100644 index d2c517634..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/tetrimino.go +++ /dev/null @@ -1,69 +0,0 @@ -package main - -type tetrimino [4][]byte - -var validUint16Map = map[uint16]bool{ - 0x8888: true, 0xf000: true, // I - 0xcc00: true, // O - 0xe400: true, 0x4c40: true, 0x4e00: true, 0x8c80: true, // T - 0x88c0: true, 0xe800: true, 0xc440: true, 0x2e00: true, // L - 0x44c0: true, 0x8e00: true, 0xc880: true, 0xe200: true, // J - 0x6c00: true, 0x8c40: true, // S - 0xc600: true, 0x4c80: true, // Z -} - -func (t tetrimino) isEmptyRow(row int) bool { - result := true - for i := 0; i < 4; i++ { - result = result && t[row][i] == dot - } - return result -} - -func (t tetrimino) isEmptyColumn(column int) bool { - result := true - for i := 0; i < 4; i++ { - result = result && t[i][column] == dot - } - return result -} - -func (t tetrimino) toUint16() uint16 { - var result uint16 - for i := 0; i < 4; i++ { - for j := 0; j < 4; j++ { - result <<= 1 - if t[i][j] == hashTag { - result |= 1 - } - } - } - return result -} - -func (t tetrimino) isValid() bool { - return validUint16Map[t.toUint16()] -} - -func blockToTetrimino(b []byte) tetrimino { - in := tetrimino{b[0:4], b[5:9], b[10:14], b[15:19]} - out := tetrimino{ - {dot, dot, dot, dot}, - {dot, dot, dot, dot}, - {dot, dot, dot, dot}, - {dot, dot, dot, dot}, - } - y, x := 0, 0 - for in.isEmptyRow(y) { - y++ - } - for in.isEmptyColumn(x) { - x++ - } - for i := 0; i+y < 4; i++ { - for j := 0; j+x < 4; j++ { - out[i][j] = in[i+y][j+x] - } - } - return out -} diff --git a/test-go/solutions/tetrisoptimizer_prog/validation.go b/test-go/solutions/tetrisoptimizer_prog/validation.go deleted file mode 100644 index 3873aaab5..000000000 --- a/test-go/solutions/tetrisoptimizer_prog/validation.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -const ( - blockSize = 20 - dot = '.' - hashTag = '#' - newLine = '\n' -) - -func isValidBlock(data []byte) bool { - numDots, numHashtags := 0, 0 - for i, v := range data { - switch v { - case dot: - numDots++ - case hashTag: - numHashtags++ - case newLine: - if i%5 != 4 { - return false - } - default: - return false - } - } - return numDots == 12 && numHashtags == 4 -} - -func validateFile(data []byte) (ok bool, result []tetrimino) { - for i := 0; i < len(data); { - if i+blockSize > len(data) { - break - } - if !isValidBlock(data[i : i+blockSize]) { - break - } - t := blockToTetrimino(data[i : i+blockSize]) - if !t.isValid() { - break - } - result = append(result, t) - i += blockSize - if i == len(data) { - ok = true - break - } - if data[i] != '\n' { - break - } - i++ - } - return ok, result -} diff --git a/test-go/solutions/union_prog/main.go b/test-go/solutions/union_prog/main.go deleted file mode 100644 index 7a151b57e..000000000 --- a/test-go/solutions/union_prog/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" -) - -func main() { - if len(os.Args) == 3 { - var res string - s1 := os.Args[1] - s2 := os.Args[2] - - for _, v := range s1 { - if !strings.ContainsRune(res, v) { - res += string(v) - } - } - for _, v := range s2 { - if !strings.ContainsRune(res, v) { - res += string(v) - } - } - fmt.Print(res) - } - fmt.Println() -} diff --git a/test-go/solutions/uniqueoccurences_prog/main.go b/test-go/solutions/uniqueoccurences_prog/main.go deleted file mode 100644 index 3317c2e25..000000000 --- a/test-go/solutions/uniqueoccurences_prog/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func solve(s string) bool { - var a [26]int - for _, r := range s { - a[r-'a']++ - } - for i := 0; i < 26; i++ { - for j := i + 1; j < 26; j++ { - if a[i] == a[j] && a[i] != 0 { - return false - } - } - } - return true -} - -func main() { - if len(os.Args) == 2 { - fmt.Println(solve(os.Args[1])) - } -} diff --git a/test-go/solutions/wdmatch_prog/main.go b/test-go/solutions/wdmatch_prog/main.go deleted file mode 100644 index b7bd2b2d0..000000000 --- a/test-go/solutions/wdmatch_prog/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -func ok(s1 string, s2 string) bool { - runes1 := []rune(s1) - runes2 := []rune(s2) - var rest string - count := 0 - for i := 0; i < len(runes1); i++ { - for j := count; j < len(runes2); j++ { - if runes1[i] == runes2[j] { - rest += string(runes1[i]) - j = len(runes2) - 1 - } - count++ - } - } - return s1 == rest -} - -func main() { - if len(os.Args) == 3 { - if ok(os.Args[1], os.Args[2]) { - fmt.Println(os.Args[1]) - } - } -} diff --git a/test-go/solutions/ztail_prog/main.go b/test-go/solutions/ztail_prog/main.go deleted file mode 100644 index 634fc8c3c..000000000 --- a/test-go/solutions/ztail_prog/main.go +++ /dev/null @@ -1,58 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "os" -) - -const ( - success = iota - failure -) - -var status = success - -func notNil(err error) bool { - if err != nil { - status = failure - fmt.Fprintln(os.Stderr, err) - return true - } - return false -} - -func main() { - var bytes int64 - flag.Int64Var(&bytes, "c", 0, "output the last NUM bytes") - flag.Parse() - filenames := flag.Args() - for i, filename := range filenames { - file, err := os.Open(filename) - if notNil(err) { - continue - } - defer file.Close() - fileInfo, err := file.Stat() - if notNil(err) { - continue - } - offset := fileInfo.Size() - bytes - if offset < 0 { - offset = 0 - } - b := make([]byte, fileInfo.Size()-offset) - _, err = file.ReadAt(b, offset) - if notNil(err) { - continue - } - if len(filenames) > 1 { - if i > 0 { - fmt.Println() - } - fmt.Println("==>", filename, "<==") - } - os.Stdout.Write(b) - } - os.Exit(status) -} diff --git a/test-go/tests/abort_test/main.go b/test-go/tests/abort_test/main.go deleted file mode 100644 index ad065ddc4..000000000 --- a/test-go/tests/abort_test/main.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "sort" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -// Receives 5 ints and returns the number in the middle -func abort(a, b, c, d, e int) int { - arg := []int{a, b, c, d, e} - sort.Ints(arg) - return arg[2] -} - -func main() { - arg := lib.MultRandInt() - arg = append(arg, lib.RandInt()) - for i := 0; i < 15; i++ { - lib.Challenge("Abort", student.Abort, abort, arg[0], arg[1], arg[2], arg[3], arg[4]) - arg = lib.MultRandInt() - arg = append(arg, lib.RandInt()) - } -} diff --git a/test-go/tests/activebits_test/main.go b/test-go/tests/activebits_test/main.go deleted file mode 100644 index 1912c6084..000000000 --- a/test-go/tests/activebits_test/main.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -// Function that return the number of active bits in the number passed as the argument -func activeBits(n int) (total int) { - for ; n > 1; n /= 2 { - total += n % 2 - } - total += n - return -} - -func main() { - args := []int{lib.RandIntBetween(2, 20)} - args = append(args, lib.MultRandIntBetween(2, 20)...) - args = append(args, lib.MultRandIntBetween(2, 20)...) - - for _, v := range args { - lib.Challenge("ActiveBits", student.ActiveBits, activeBits, v) - } -} diff --git a/test-go/tests/addprimesum_test/main.go b/test-go/tests/addprimesum_test/main.go deleted file mode 100644 index f0bcb4c9f..000000000 --- a/test-go/tests/addprimesum_test/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "strconv" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/is" -) - -func main() { - // adds random numbers - table := lib.MultRandIntBetween(1, 10000) - - // fill with all prime numbers between 0 and 100 - for i := 0; i < 100; i++ { - if is.Prime(i) { - table = append(table, i) - } - } - - for _, i := range table { - lib.ChallengeMain("addprimesum", strconv.Itoa(i)) - } - // special cases - lib.ChallengeMain("addprimesum") - lib.ChallengeMain("addprimesum", `""`) - lib.ChallengeMain("addprimesum", "1", "2") -} diff --git a/test-go/tests/advancedsortwordarr_test/main.go b/test-go/tests/advancedsortwordarr_test/main.go deleted file mode 100644 index 3cb341ba2..000000000 --- a/test-go/tests/advancedsortwordarr_test/main.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "reflect" - "sort" - "strings" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func advancedSortWordArr(a []string, f func(a, b string) int) { - sort.Slice(a, func(i, j int) bool { - return f(a[i], a[j]) < 0 - }) -} - -func main() { - table := [][]string{{"a", "A", "1", "b", "B", "2", "c", "C", "3"}} - - table = append(table, lib.MultRandWords()) - - for _, org := range table { - // copy for using the solution function - cp_sol := make([]string, len(org)) - // copy for using the student function - cp_stu := make([]string, len(org)) - - copy(cp_sol, org) - copy(cp_stu, org) - - advancedSortWordArr(cp_sol, strings.Compare) - student.AdvancedSortWordArr(cp_stu, strings.Compare) - - if !reflect.DeepEqual(cp_stu, cp_sol) { - lib.Fatalf("%s(%v) == %v instead of %v\n", - "AdvancedSortWordArr", - org, - cp_stu, - cp_sol, - ) - } - } -} diff --git a/test-go/tests/alphacount_test/main.go b/test-go/tests/alphacount_test/main.go deleted file mode 100644 index acdda15c7..000000000 --- a/test-go/tests/alphacount_test/main.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "unicode" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func alphaCount(s string) (i int) { - for _, r := range s { - if unicode.IsLetter(r) { - i++ - } - } - return i -} - -func main() { - table := []string{ - " ", - "Hello 78 World! 4455 /", - } - for l := 0; l < 7; l++ { - a := lib.RandIntBetween(5, 20) - b := lib.RandASCII() - table = append(table, lib.RandStr(a, b)) - } - - for _, arg := range table { - lib.Challenge("AlphaCount", student.AlphaCount, alphaCount, arg) - } -} diff --git a/test-go/tests/alphamirror_test/main.go b/test-go/tests/alphamirror_test/main.go deleted file mode 100644 index 9d0600f02..000000000 --- a/test-go/tests/alphamirror_test/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := [][]string{ - {""}, - {"One", "ring!"}, - {"testing spaces and #!*"}, - {"more", "than", "three", "arguments"}, - {"Upper anD LoWer cAsE"}, - {lib.RandWords()}, - } - - for _, v := range args { - lib.ChallengeMain("alphamirror", v...) - } -} diff --git a/test-go/tests/any_test/main.go b/test-go/tests/any_test/main.go deleted file mode 100644 index b1866b8a9..000000000 --- a/test-go/tests/any_test/main.go +++ /dev/null @@ -1,70 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/is" -) - -func any(f func(string) bool, a []string) bool { - for _, el := range a { - if f(el) { - return true - } - } - return false -} - -func main() { - functions := []func(string) bool{is.Digit, is.Lower, is.Upper} - - type node struct { - f func(string) bool - a []string - } - - table := []node{} - - for i := 0; i < 5; i++ { - function := functions[lib.RandIntBetween(0, len(functions)-1)] - table = append(table, node{ - f: function, - a: lib.MultRandWords(), - }) - } - for i := 0; i < 5; i++ { - table = append(table, node{ - f: is.Digit, - a: lib.MultRandDigit(), - }) - } - - for i := 0; i < 5; i++ { - table = append(table, node{ - f: is.Lower, - a: lib.MultRandLower(), - }) - } - for i := 0; i < 5; i++ { - table = append(table, node{ - f: is.Upper, - a: lib.MultRandUpper(), - }) - } - - table = append(table, - node{ - f: is.Digit, - a: []string{"Hello", "how", "are", "you"}, - }, - node{ - f: is.Digit, - a: []string{"This", "is", "4", "you"}, - }, - ) - - for _, arg := range table { - lib.Challenge("Any", student.Any, any, arg.f, arg.a) - } -} diff --git a/test-go/tests/appendrange_test/main.go b/test-go/tests/appendrange_test/main.go deleted file mode 100644 index a71aedcba..000000000 --- a/test-go/tests/appendrange_test/main.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func appendRange(min, max int) []int { - size := max - min - answer := []int{} - if size <= 0 { - return nil - } - for i := min; i < max; i++ { - answer = append(answer, i) - } - return answer -} - -func main() { - type node struct { - min int - max int - } - table := []node{} - - // 15 random pairs of ints for a Valid Range - for i := 0; i < 15; i++ { - minVal := lib.RandIntBetween(-10000000, 1000000) - gap := lib.RandIntBetween(1, 20) - val := node{ - min: minVal, - max: minVal + gap, - } - table = append(table, val) - } - - // 15 random pairs of ints with ||invalid range|| - for i := 0; i < 15; i++ { - minVal := lib.RandIntBetween(-10000000, 1000000) - gap := lib.RandIntBetween(1, 20) - val := node{ - min: minVal, - max: minVal - gap, - } - table = append(table, val) - } - - table = append(table, - node{min: 0, max: 1}, - node{min: 0, max: 0}, - node{min: 5, max: 10}, - node{min: 10, max: 5}, - ) - - for _, arg := range table { - lib.Challenge("AppendRange", student.AppendRange, appendRange, arg.min, arg.max) - } -} diff --git a/test-go/tests/atoi_test/main.go b/test-go/tests/atoi_test/main.go deleted file mode 100644 index af6273c25..000000000 --- a/test-go/tests/atoi_test/main.go +++ /dev/null @@ -1,42 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func atoi(s string) int { - n, _ := strconv.Atoi(s) - return n -} - -func main() { - table := make([]string, 30) - for i := range table { - table[i] = strconv.Itoa(lib.RandInt()) - } - table = append(table, - strconv.Itoa(lib.MinInt), - strconv.Itoa(lib.MaxInt), - "", - "-", - "+", - "0", - "+0", - "-Invalid123", - "--123", - "-+123", - "++123", - "123-", - "123+", - "123.", - "123.0", - "123a45", - ) - for _, arg := range table { - lib.Challenge("Atoi", student.Atoi, atoi, arg) - } -} diff --git a/test-go/tests/atoibase_test/main.go b/test-go/tests/atoibase_test/main.go deleted file mode 100644 index ef1d22274..000000000 --- a/test-go/tests/atoibase_test/main.go +++ /dev/null @@ -1,46 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/base" -) - -func main() { - type node struct { - s string - base string - } - - table := []node{} - - // 15 random pairs of string numbers with valid bases - for i := 0; i < 15; i++ { - validBaseToInput := base.Valid() - val := node{ - s: base.StringFrom(validBaseToInput), - base: validBaseToInput, - } - table = append(table, val) - } - // 15 random pairs of string numbers with invalid bases - for i := 0; i < 15; i++ { - invalidBaseToInput := base.Invalid() - val := node{ - s: "thisinputshouldnotmatter", - base: invalidBaseToInput, - } - table = append(table, val) - } - table = append(table, - node{s: "125", base: "0123456789"}, - node{s: "1111101", base: "01"}, - node{s: "7D", base: "0123456789ABCDEF"}, - node{s: "uoi", base: "choumi"}, - node{s: "bbbbbab", base: "-ab"}, - ) - for _, arg := range table { - lib.Challenge("AtoiBase", student.AtoiBase, base.Atoi, arg.s, arg.base) - } -} diff --git a/test-go/tests/balancedstring_test/main.go b/test-go/tests/balancedstring_test/main.go deleted file mode 100644 index 919488fcc..000000000 --- a/test-go/tests/balancedstring_test/main.go +++ /dev/null @@ -1,57 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := []string{ - "CDCCDDCDCD", - "CDDDDCCCDC", - "DDDDCCCC", - "CDCCCDDCDD", - "CDCDCDCDCDCDCDCD", - "CCCDDDCDCCCCDC", - "DDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCC", - "DDDDCDDDDCDDDCCC", - } - - for i := 0; i < 15; i++ { - s := "" - chunks := lib.RandIntBetween(5, 10) - for j := 0; j < chunks; j++ { - countC := lib.RandIntBetween(1, 5) - countD := lib.RandIntBetween(1, 5) - tmpC := countC - tmpD := countD - for tmpC > 0 || tmpD > 0 { - letter := lib.RandStr(1, "CD") - if tmpC > 0 && letter == "C" { - tmpC-- - s += letter - } else if tmpD > 0 && letter == "D" { - tmpD-- - s += letter - } - } - - tmpC = countC - tmpD = countD - for tmpC > 0 || tmpD > 0 { - letter := lib.RandStr(1, "CD") - if tmpC > 0 && letter == "D" { - tmpC-- - s += letter - } else if tmpD > 0 && letter == "C" { - tmpD-- - s += letter - } - } - } - table = append(table, s) - } - - for _, arg := range table { - lib.ChallengeMain("balancedstring", arg) - } -} diff --git a/test-go/tests/basicatoi2_test/main.go b/test-go/tests/basicatoi2_test/main.go deleted file mode 100644 index b7e366491..000000000 --- a/test-go/tests/basicatoi2_test/main.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func basicAtoi2(s string) int { - n, _ := strconv.Atoi(s) - return n -} - -func main() { - table := make([]string, 30) - for i := range table { - table[i] = strconv.Itoa(lib.RandPosZ()) - } - table = append(table, - strconv.Itoa(lib.MaxInt), - "", - "0", - "Invalid123", - "123Invalid", - "Invalid", - "1Invalid23", - "123", - "123.", - "123.0", - ) - for _, arg := range table { - lib.Challenge("BasicAtoi2", student.BasicAtoi2, basicAtoi2, arg) - } -} diff --git a/test-go/tests/basicatoi_test/main.go b/test-go/tests/basicatoi_test/main.go deleted file mode 100644 index 54fb78f1d..000000000 --- a/test-go/tests/basicatoi_test/main.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func basicAtoi(s string) int { - n, _ := strconv.Atoi(s) - return n -} - -func main() { - table := make([]string, 30) - for i := range table { - table[i] = strconv.Itoa(lib.RandPosZ()) - } - table = append(table, - strconv.Itoa(lib.MaxInt), - "", - "0", - "12345", - "0000012345", - "000000", - ) - for _, arg := range table { - lib.Challenge("BasicAtoi", student.BasicAtoi, basicAtoi, arg) - } -} diff --git a/test-go/tests/basicjoin_test/main.go b/test-go/tests/basicjoin_test/main.go deleted file mode 100644 index a7688b8ee..000000000 --- a/test-go/tests/basicjoin_test/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "strings" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func basicJoin(elems []string) string { - return strings.Join(elems, "") -} - -func main() { - table := [][]string{} - - // 30 valid pair of ramdom slice of strings to concatenate - for i := 0; i < 30; i++ { - table = append(table, lib.MultRandASCII()) - } - table = append(table, - []string{"Hello!", " How are you?", "well and yourself?"}, - ) - for _, arg := range table { - lib.Challenge("BasicJoin", student.BasicJoin, basicJoin, arg) - } -} diff --git a/test-go/tests/boolean_test/main.go b/test-go/tests/boolean_test/main.go deleted file mode 100644 index cd2322a86..000000000 --- a/test-go/tests/boolean_test/main.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandWords(), "1 2 3 4 5") - - for _, s := range table { - lib.ChallengeMain("boolean", strings.Fields(s)...) - } -} diff --git a/test-go/tests/brackets_test/main.go b/test-go/tests/brackets_test/main.go deleted file mode 100644 index d91d237cc..000000000 --- a/test-go/tests/brackets_test/main.go +++ /dev/null @@ -1,42 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - oneArgs := []string{ - "(johndoe)", - ")()", - "([)]", - "{2*[d - 3]/(12)}", - } - - // 18 random tests ( at least half are valid) - for i := 0; i < 3; i++ { - oneArgs = append(oneArgs, - "("+lib.RandASCII()+")", - "["+lib.RandASCII()+"]", - "{"+lib.RandASCII()+"}", - "("+lib.RandAlnum()+")", - "["+lib.RandAlnum()+"]", - "{"+lib.RandAlnum()+"}", - ) - } - - lib.ChallengeMain("brackets") - - for _, v := range oneArgs { - lib.ChallengeMain("brackets", v) - } - - multArg := [][]string{ - {"", "{[(0 + 0)(1 + 1)](3*(-1)){()}}"}, - {"{][]}", "{3*[21/(12+ 23)]}"}, - {"{([)])}", "{{{something }- [something]}}", "there are"}, - } - - for _, v := range multArg { - lib.ChallengeMain("brackets", v...) - } -} diff --git a/test-go/tests/brainfuck_test/main.go b/test-go/tests/brainfuck_test/main.go deleted file mode 100644 index 5bbada76f..000000000 --- a/test-go/tests/brainfuck_test/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - // individual tests 1)Hello World! 2)Hi 3)abc 4)ABC - - args := []string{ - "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.", - "+++++[>++++[>++++H>+++++i<<-]>>>++\n<<<<-]>>--------.>+++++.>.", - "++++++++++[>++++++++++>++++++++++>++++++++++<<<-]>---.>--.>-.>++++++++++.", - "ld++++++++++++++++++++++++++++++++++++++++++++this+is++a++++comment++++++++++++++[>d+<-]>.+.+.>++++++++++.", - strings.Join([]string{"ld++++++++++++++++++++++++++++++++++++++++++++this+is++a++++comment++++++++++++++[>d+<-]>.+", lib.RandStr(lib.RandIntBetween(1, 10), ".+"), ".+.>++++++++++."}, ""), - } - for _, v := range args { - lib.ChallengeMain("brainfuck", v) - } -} diff --git a/test-go/tests/btreeapplybylevel_test/main.go b/test-go/tests/btreeapplybylevel_test/main.go deleted file mode 100644 index 810fadd36..000000000 --- a/test-go/tests/btreeapplybylevel_test/main.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/solutions" -) - -func main() { - root := &solutions.TreeNode{Data: "04"} - rootS := &student.TreeNode{Data: "04"} - - ins := []string{"01", "07", "05", "12", "02", "03", "10"} - - for _, v := range ins { - root = solutions.BTreeInsertData(root, v) - rootS = student.BTreeInsertData(rootS, v) - } - - solutions.ChallengeTree("BTreeApplyByLevel", solutions.BTreeApplyByLevel, student.BTreeApplyByLevel, root, rootS, fmt.Print) -} diff --git a/test-go/tests/btreeapplyinorder_test/main.go b/test-go/tests/btreeapplyinorder_test/main.go deleted file mode 100644 index 82b09e20b..000000000 --- a/test-go/tests/btreeapplyinorder_test/main.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/solutions" -) - -func main() { - root := &solutions.TreeNode{Data: "08"} - rootS := &student.TreeNode{Data: "08"} - pos := []string{ - "x", - "z", - "y", - "t", - "r", - "q", - "01", - "b", - "c", - "a", - "d", - } - - for _, arg := range pos { - root = solutions.BTreeInsertData(root, arg) - rootS = student.BTreeInsertData(rootS, arg) - } - - solutions.ChallengeTree("BTreeApplyInorder", solutions.BTreeApplyInorder, student.BTreeApplyInorder, root, rootS, fmt.Println) -} diff --git a/test-go/tests/btreeapplypostorder_test/main.go b/test-go/tests/btreeapplypostorder_test/main.go deleted file mode 100644 index 30e8ba4cd..000000000 --- a/test-go/tests/btreeapplypostorder_test/main.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/solutions" -) - -func main() { - root := &solutions.TreeNode{Data: "08"} - rootS := &student.TreeNode{Data: "08"} - pos := []string{ - "x", - "z", - "y", - "t", - "r", - "q", - "01", - "b", - "c", - "a", - "d", - } - - for _, arg := range pos { - root = solutions.BTreeInsertData(root, arg) - rootS = student.BTreeInsertData(rootS, arg) - } - - solutions.ChallengeTree("BTreeApplyPostorder", solutions.BTreeApplyPostorder, student.BTreeApplyPostorder, root, rootS, fmt.Println) -} diff --git a/test-go/tests/btreeapplypreorder_test/main.go b/test-go/tests/btreeapplypreorder_test/main.go deleted file mode 100644 index ec116a3dc..000000000 --- a/test-go/tests/btreeapplypreorder_test/main.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/solutions" -) - -func main() { - root := &solutions.TreeNode{Data: "08"} - rootS := &student.TreeNode{Data: "08"} - pos := []string{ - "x", - "z", - "y", - "t", - "r", - "q", - "01", - "b", - "c", - "a", - "d", - } - - for _, arg := range pos { - root = solutions.BTreeInsertData(root, arg) - rootS = student.BTreeInsertData(rootS, arg) - } - - solutions.ChallengeTree("BTreeApplyPreorder", solutions.BTreeApplyPreorder, student.BTreeApplyPreorder, root, rootS, fmt.Println) -} diff --git a/test-go/tests/btreedeletenode_test/main.go b/test-go/tests/btreedeletenode_test/main.go deleted file mode 100644 index d9ffca8e1..000000000 --- a/test-go/tests/btreedeletenode_test/main.go +++ /dev/null @@ -1,120 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -func parentListDelete(root *student.TreeNode) string { - if root == nil { - return "" - } - - var parent string - - if root.Parent == nil { - parent = "nil" - } else { - parent = root.Parent.Data - } - - r := "Node: " + root.Data + " Parent: " + parent + "\n" - r += parentListDelete(root.Left) + parentListDelete(root.Right) - return r -} - -func FormatTree_delete(root *student.TreeNode) string { - if root == nil { - return "" - } - res := root.Data + "\n" - res += formatSubTree_delete(root, "") - return res -} - -func formatSubTree_delete(root *student.TreeNode, prefix string) string { - if root == nil { - return "" - } - - var res string - - hasLeft := root.Left != nil - hasRight := root.Right != nil - - if !hasLeft && !hasRight { - return res - } - - res += prefix - if hasLeft && hasRight { - res += "├── " - } - - if !hasLeft && hasRight { - res += "└── " - } - - if hasRight { - printStrand := (hasLeft && hasRight && (root.Right.Right != nil || root.Right.Left != nil)) - newPrefix := prefix - if printStrand { - newPrefix += "│ " - } else { - newPrefix += " " - } - res += root.Right.Data + "\n" - res += formatSubTree_delete(root.Right, newPrefix) - } - - if hasLeft { - if hasRight { - res += prefix - } - res += "└── " + root.Left.Data + "\n" - res += formatSubTree_delete(root.Left, prefix+" ") - } - return res -} - -func errorMessage_delete(fn interface{}, deleted string, rootOr, root *solutions.TreeNode, rootS *student.TreeNode) { - lib.Fatalf("%s(\n%s, %s\n) ==\n%s instead of\n%s\n", - "BTreeDeleteNode", - solutions.FormatTree(rootOr), - deleted, - FormatTree_delete(rootS), - solutions.FormatTree(root), - ) -} - -func CompareTrees_delete(fn interface{}, deleted string, rootOr, root *solutions.TreeNode, rootS *student.TreeNode) { - sel := student.BTreeSearchItem(rootS, deleted) - - if !student.BTreeIsBinary(rootS) || sel != nil { - errorMessage_delete(fn, deleted, rootOr, root, rootS) - } -} - -func main() { - root := &solutions.TreeNode{Data: "04"} - rootS := &student.TreeNode{Data: "04"} - rootOr := &solutions.TreeNode{Data: "04"} - - ins := []string{"01", "07", "05", "12", "02", "03", "10"} - - for _, v := range ins { - root = solutions.BTreeInsertData(root, v) - rootS = student.BTreeInsertData(rootS, v) - rootOr = solutions.BTreeInsertData(rootOr, v) - } - - selected := solutions.BTreeSearchItem(root, "04") - selectedS := student.BTreeSearchItem(rootS, "04") - - root = solutions.BTreeDeleteNode(root, selected) - rootS = student.BTreeDeleteNode(rootS, selectedS) - fn := interface{}(solutions.BTreeDeleteNode) - CompareTrees_delete(fn, selected.Data, rootOr, root, rootS) -} diff --git a/test-go/tests/btreeinsertdata_test/main.go b/test-go/tests/btreeinsertdata_test/main.go deleted file mode 100644 index 5f48aefd6..000000000 --- a/test-go/tests/btreeinsertdata_test/main.go +++ /dev/null @@ -1,126 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -func parentListInsert(root *student.TreeNode) string { - if root == nil { - return "" - } - - var parent string - - if root.Parent == nil { - parent = "nil" - } else { - parent = root.Parent.Data - } - - r := "Node: " + root.Data + " Parent: " + parent + "\n" - r += parentListInsert(root.Left) + parentListInsert(root.Right) - return r -} - -func FormatTree_insert(root *student.TreeNode) string { - if root == nil { - return "" - } - res := root.Data + "\n" - res += formatSubTree_insert(root, "") - return res -} - -func formatSubTree_insert(root *student.TreeNode, prefix string) string { - if root == nil { - return "" - } - - var res string - - hasLeft := root.Left != nil - hasRight := root.Right != nil - - if !hasLeft && !hasRight { - return res - } - - res += prefix - if hasLeft && hasRight { - res += "├── " - } - - if !hasLeft && hasRight { - res += "└── " - } - - if hasRight { - printStrand := (hasLeft && hasRight && (root.Right.Right != nil || root.Right.Left != nil)) - newPrefix := prefix - if printStrand { - newPrefix += "│ " - } else { - newPrefix += " " - } - res += root.Right.Data + "\n" - res += formatSubTree_insert(root.Right, newPrefix) - } - - if hasLeft { - if hasRight { - res += prefix - } - res += "└── " + root.Left.Data + "\n" - res += formatSubTree_insert(root.Left, prefix+" ") - } - return res -} - -func errorMessage_insert(fn interface{}, inserted string, root *solutions.TreeNode, rootS *student.TreeNode) { - lib.Fatalf("%s(\n%s, %s\n) ==\n%s instead of\n%s\n", - "BTreeInsertData", - solutions.FormatTree(root), - inserted, - FormatTree_insert(rootS), - solutions.FormatTree(root), - ) -} - -func CompareTrees_insert(fn interface{}, inserted string, root *solutions.TreeNode, rootS *student.TreeNode) { - solTree := solutions.FormatTree(root) - stuTree := FormatTree_insert(rootS) - - if solTree != stuTree { - errorMessage_insert(fn, inserted, root, rootS) - } -} - -func main() { - root := &solutions.TreeNode{Data: "08"} - rootS := &student.TreeNode{Data: "08"} - - var pos []string - - pos = append(pos, - "x", - "z", - "y", - "t", - "r", - "q", - "01", - "b", - "c", - "a", - "d", - ) - fn := interface{}(solutions.BTreeInsertData) - for _, arg := range pos { - root = solutions.BTreeInsertData(root, arg) - rootS = student.BTreeInsertData(rootS, arg) - CompareTrees_insert(fn, arg, root, rootS) - } -} diff --git a/test-go/tests/btreeisbinary_test/main.go b/test-go/tests/btreeisbinary_test/main.go deleted file mode 100644 index c960ac093..000000000 --- a/test-go/tests/btreeisbinary_test/main.go +++ /dev/null @@ -1,110 +0,0 @@ -package main - -import ( - "reflect" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -func BTreeMinStu(root *student.TreeNode) *student.TreeNode { - if root == nil || root.Left == nil { - return root - } - return BTreeMinStu(root.Left) -} - -func errorMessage_isbin(fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) { - lib.Fatalf("%s(\n%s\n) == %s instead of %s\n", - "BTreeIsBinary", - solutions.FormatTree(root), - b.Data, - a.Data, - ) -} - -func CompareNode_isbin(fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) { - if a == nil || b == nil { - lib.Fatalf("Expected %v instead of %v\n", a, b) - } - if a.Data != b.Data { - errorMessage_isbin(fn, arg1, a, b) - } - if a.Parent != nil && b.Parent != nil && a.Parent.Data != b.Parent.Data { - errorMessage_isbin(fn, arg1, a, b) - lib.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) - } - if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) { - lib.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) - } - if a.Right != nil && b.Right != nil && a.Right.Data != b.Right.Data { - errorMessage_isbin(fn, arg1, a, b) - lib.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) - } - if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) { - lib.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) - } - if a.Left != nil && b.Left != nil && a.Left.Data != b.Left.Data { - errorMessage_isbin(fn, arg1, a, b) - lib.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) - } - if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) { - lib.Fatalf("Expected left child value %v instead of %v\n", a, b) - } -} - -func CompareReturn_isbin(fn1, fn2 interface{}, arg1 *solutions.TreeNode, arg2 interface{}) { - arar1 := []interface{}{arg1} - arar2 := []interface{}{arg2} - - out1 := lib.Monitor(fn1, arar1) - out2 := lib.Monitor(fn2, arar2) - - for i, v := range out1.Results { - switch str := v.(type) { - case *solutions.TreeNode: - CompareNode_isbin(fn1, arg1, str, out2.Results[i].(*student.TreeNode)) - default: - if !reflect.DeepEqual(str, out2.Results[i]) { - lib.Fatalf("%s(\n%s) == %s instead of %s\n", - "BTreeIsBinary", - solutions.FormatTree(arg1), - lib.Format(out2.Results...), - lib.Format(out1.Results...), - ) - } - } - } -} - -func main() { - root := &solutions.TreeNode{Data: "04"} - rootS := &student.TreeNode{Data: "04"} - - ins := []string{"01", "07", "05", "12", "02", "03", "10"} - - for _, v := range ins { - root = solutions.BTreeInsertData(root, v) - rootS = student.BTreeInsertData(rootS, v) - } - - CompareReturn_isbin(solutions.BTreeIsBinary, student.BTreeIsBinary, root, rootS) - - rootNB := &solutions.TreeNode{Data: "04"} - rootNB_stu := &student.TreeNode{Data: "04"} - // Test a non-binarysearch tree - for _, v := range ins { - rootNB = solutions.BTreeInsertData(rootNB, v) - rootNB_stu = student.BTreeInsertData(rootNB_stu, v) - } - - min := solutions.BTreeMin(rootNB) - minStu := BTreeMinStu(rootNB_stu) - - min.Left = &solutions.TreeNode{Data: "123"} - minStu.Left = &student.TreeNode{Data: "123"} - - CompareReturn_isbin(solutions.BTreeIsBinary, student.BTreeIsBinary, rootNB, rootNB_stu) -} diff --git a/test-go/tests/btreelevelcount_test/main.go b/test-go/tests/btreelevelcount_test/main.go deleted file mode 100644 index 3c1e48319..000000000 --- a/test-go/tests/btreelevelcount_test/main.go +++ /dev/null @@ -1,94 +0,0 @@ -package main - -import ( - "reflect" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -func errorMessage_level(fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) { - lib.Fatalf("%s(\n%s\n) == %s instead of %s\n", - "BTreeLevelCount", - solutions.FormatTree(root), - b.Data, - a.Data, - ) -} - -func CompareNode_level(fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) { - if a == nil || b == nil { - lib.Fatalf("Expected %v instead of %v\n", a, b) - return - } - - if a.Data != b.Data { - errorMessage_level(fn, arg1, a, b) - } - - if a.Parent != nil && b.Parent != nil { - if a.Parent.Data != b.Parent.Data { - errorMessage_level(fn, arg1, a, b) - lib.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) - } - } else if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) { - lib.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) - } - - if a.Right != nil && b.Right != nil { - if a.Right.Data != b.Right.Data { - errorMessage_level(fn, arg1, a, b) - lib.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) - } - } else if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) { - lib.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) - } - - if a.Left != nil && b.Left != nil { - if a.Left.Data != b.Left.Data { - errorMessage_level(fn, arg1, a, b) - lib.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) - } - } else if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) { - lib.Fatalf("Expected left child value %v instead of %v\n", a, b) - } -} - -func CompareReturn_level(fn1, fn2 interface{}, arg1 *solutions.TreeNode, arg2 interface{}) { - arar1 := []interface{}{arg1} - arar2 := []interface{}{arg2} - - out1 := lib.Monitor(fn1, arar1) - out2 := lib.Monitor(fn2, arar2) - - for i, v := range out1.Results { - switch str := v.(type) { - case *solutions.TreeNode: - CompareNode_level(fn1, arg1, str, out2.Results[i].(*student.TreeNode)) - default: - if !reflect.DeepEqual(str, out2.Results[i]) { - lib.Fatalf("%s(\n%s) == %s instead of %s\n", - "BTreeLevelCount", - solutions.FormatTree(arg1), - lib.Format(out2.Results...), - lib.Format(out1.Results...), - ) - } - } - } -} - -func main() { - root := &solutions.TreeNode{Data: "04"} - rootS := &student.TreeNode{Data: "04"} - - ins := []string{"01", "07", "05", "12", "02", "03", "10"} - - for _, v := range ins { - root = solutions.BTreeInsertData(root, v) - rootS = student.BTreeInsertData(rootS, v) - CompareReturn_level(solutions.BTreeLevelCount, student.BTreeLevelCount, root, rootS) - } -} diff --git a/test-go/tests/btreemax_test/main.go b/test-go/tests/btreemax_test/main.go deleted file mode 100644 index c23c83a43..000000000 --- a/test-go/tests/btreemax_test/main.go +++ /dev/null @@ -1,95 +0,0 @@ -package main - -import ( - "reflect" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -func errorMessage_max(fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) { - lib.Fatalf("%s(\n%s) == %s instead of %s\n", - "BTreeMax", - solutions.FormatTree(root), - b.Data, - a.Data, - ) -} - -func CompareNode_max(fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) { - if a == nil || b == nil { - lib.Fatalf("Expected %v instead of %v\n", a, b) - return - } - - if a.Data != b.Data { - errorMessage_max(fn, arg1, a, b) - } - - if a.Parent != nil && b.Parent != nil { - if a.Parent.Data != b.Parent.Data { - errorMessage_max(fn, arg1, a, b) - lib.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) - } - } else if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) { - lib.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) - } - - if a.Right != nil && b.Right != nil { - if a.Right.Data != b.Right.Data { - errorMessage_max(fn, arg1, a, b) - lib.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) - } - } else if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) { - lib.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) - } - - if a.Left != nil && b.Left != nil { - if a.Left.Data != b.Left.Data { - errorMessage_max(fn, arg1, a, b) - lib.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) - } - } else if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) { - lib.Fatalf("Expected left child value %v instead of %v\n", a, b) - } -} - -func CompareReturn_max(fn1, fn2 interface{}, arg1 *solutions.TreeNode, arg2 interface{}) { - arar1 := []interface{}{arg1} - arar2 := []interface{}{arg2} - - out1 := lib.Monitor(fn1, arar1) - out2 := lib.Monitor(fn2, arar2) - - for i, v := range out1.Results { - switch str := v.(type) { - case *solutions.TreeNode: - CompareNode_max(fn1, arg1, str, out2.Results[i].(*student.TreeNode)) - default: - if !reflect.DeepEqual(str, out2.Results[i]) { - lib.Fatalf("%s(\n%s) == %s instead of\n %s\n", - "BTreeMax", - solutions.FormatTree(arg1), - lib.Format(out2.Results...), - lib.Format(out1.Results...), - ) - } - } - } -} - -func main() { - root := &solutions.TreeNode{Data: "04"} - rootS := &student.TreeNode{Data: "04"} - - ins := []string{"01", "07", "05", "12", "02", "03", "10"} - - for _, v := range ins { - root = solutions.BTreeInsertData(root, v) - rootS = student.BTreeInsertData(rootS, v) - } - - CompareReturn_max(solutions.BTreeMax, student.BTreeMax, root, rootS) -} diff --git a/test-go/tests/btreemin_test/main.go b/test-go/tests/btreemin_test/main.go deleted file mode 100644 index 73cc768b9..000000000 --- a/test-go/tests/btreemin_test/main.go +++ /dev/null @@ -1,95 +0,0 @@ -package main - -import ( - "reflect" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -func errorMessage_min(fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) { - lib.Fatalf("%s(\n%s) == %s instead of %s\n", - "BTreeMin", - solutions.FormatTree(root), - b.Data, - a.Data, - ) -} - -func CompareNode_min(fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) { - if a == nil || b == nil { - lib.Fatalf("Expected %v instead of %v\n", a, b) - return - } - - if a.Data != b.Data { - errorMessage_min(fn, arg1, a, b) - } - - if a.Parent != nil && b.Parent != nil { - if a.Parent.Data != b.Parent.Data { - errorMessage_min(fn, arg1, a, b) - lib.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) - } - } else if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) { - lib.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) - } - - if a.Right != nil && b.Right != nil { - if a.Right.Data != b.Right.Data { - errorMessage_min(fn, arg1, a, b) - lib.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) - } - } else if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) { - lib.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) - } - - if a.Left != nil && b.Left != nil { - if a.Left.Data != b.Left.Data { - errorMessage_min(fn, arg1, a, b) - lib.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) - } - } else if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) { - lib.Fatalf("Expected left child value %v instead of %v\n", a, b) - } -} - -func CompareReturn_min(fn1, fn2, arg1, arg2 interface{}) { - arar1 := []interface{}{arg1} - arar2 := []interface{}{arg2} - - out1 := lib.Monitor(fn1, arar1) - out2 := lib.Monitor(fn2, arar2) - - for i, v := range out1.Results { - switch str := v.(type) { - case *solutions.TreeNode: - CompareNode_min(fn1, arg1.(*solutions.TreeNode), str, out2.Results[i].(*student.TreeNode)) - default: - if !reflect.DeepEqual(str, out2.Results[i]) { - lib.Fatalf("%s(%s) == %s instead of %s\n", - "BTreeMin", - lib.Format(arg1), - lib.Format(out2.Results...), - lib.Format(out1.Results...), - ) - } - } - } -} - -func main() { - root := &solutions.TreeNode{Data: "04"} - rootS := &student.TreeNode{Data: "04"} - - ins := []string{"03", "02", "01", "07", "05", "12", "10"} - - for _, v := range ins { - root = solutions.BTreeInsertData(root, v) - rootS = student.BTreeInsertData(rootS, v) - } - - CompareReturn_min(solutions.BTreeMin, student.BTreeMin, root, rootS) -} diff --git a/test-go/tests/btreesearchitem_test/main.go b/test-go/tests/btreesearchitem_test/main.go deleted file mode 100644 index bfed91d8b..000000000 --- a/test-go/tests/btreesearchitem_test/main.go +++ /dev/null @@ -1,87 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -func errorMessage_search(fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode, - seaVal string) { - lib.Fatalf("%s(\n%s\n, %s) == %s instead of %s\n", - "BTreeSearchItem", - solutions.FormatTree(root), - seaVal, - b.Data, - a.Data, - ) -} - -func CompareNode_search(fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode, - seaVal string) { - if a == nil && b == nil { - return - } - - if (a == nil && b != nil) || (b == nil && a != nil) { - lib.Fatalf("Expected %v instead of %v\n", a, b) - return - } - - if a.Data != b.Data { - errorMessage_search(fn, arg1, a, b, seaVal) - } - - if a.Parent != nil && b.Parent != nil { - if a.Parent.Data != b.Parent.Data { - errorMessage_search(fn, arg1, a, b, seaVal) - lib.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) - fmt.Println("Parent.Data", a.Parent.Data, b.Parent.Data) - } - } else if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) { - lib.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) - } - - if a.Right != nil && b.Right != nil { - if a.Right.Data != b.Right.Data { - errorMessage_search(fn, arg1, a, b, seaVal) - lib.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) - fmt.Println("Right.Data", a.Right.Data, b.Right.Data) - } - } else if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) { - lib.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) - } - - if a.Left != nil && b.Left != nil { - if a.Left.Data != b.Left.Data { - errorMessage_search(fn, arg1, a, b, seaVal) - lib.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) - fmt.Println("Left.Data", a.Left.Data, b.Left.Data) - } - } else if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) { - lib.Fatalf("Expected left child value %v instead of %v\n", a, b) - } -} - -func main() { - root := &solutions.TreeNode{Data: "04"} - rootS := &student.TreeNode{Data: "04"} - - ins := []string{"01", "07", "05", "12", "02", "03", "10"} - - for _, v := range ins { - root = solutions.BTreeInsertData(root, v) - rootS = student.BTreeInsertData(rootS, v) - } - fn := interface{}(solutions.BTreeSearchItem) - - ins = append(ins, "322") - for _, v := range ins { - selectedSol := solutions.BTreeSearchItem(root, v) - selectedStu := student.BTreeSearchItem(rootS, v) - CompareNode_search(fn, root, selectedSol, selectedStu, v) - } -} diff --git a/test-go/tests/btreetransplant_test/main.go b/test-go/tests/btreetransplant_test/main.go deleted file mode 100644 index 3b2030472..000000000 --- a/test-go/tests/btreetransplant_test/main.go +++ /dev/null @@ -1,141 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -func parentListTransp(root *student.TreeNode) string { - if root == nil { - return "" - } - - var parent string - - if root.Parent == nil { - parent = "nil" - } else { - parent = root.Parent.Data - } - - r := "Node: " + root.Data + " Parent: " + parent + "\n" - r += parentListTransp(root.Left) + parentListTransp(root.Right) - return r -} - -func FormatTree_transp(root *student.TreeNode) string { - if root == nil { - return "" - } - res := root.Data + "\n" - res += formatSubTree_transp(root, "") - return res -} - -func formatSubTree_transp(root *student.TreeNode, prefix string) string { - if root == nil { - return "" - } - - var res string - - hasLeft := root.Left != nil - hasRight := root.Right != nil - - if !hasLeft && !hasRight { - return res - } - - res += prefix - if hasLeft && hasRight { - res += "├── " - } - - if !hasLeft && hasRight { - res += "└── " - } - - if hasRight { - printStrand := (hasLeft && hasRight && (root.Right.Right != nil || root.Right.Left != nil)) - newPrefix := prefix - if printStrand { - newPrefix += "│ " - } else { - newPrefix += " " - } - res += root.Right.Data + "\n" - res += formatSubTree_transp(root.Right, newPrefix) - } - - if hasLeft { - if hasRight { - res += prefix - } - res += "└── " + root.Left.Data + "\n" - res += formatSubTree_transp(root.Left, prefix+" ") - } - return res -} - -func errorMessage_transp(fn interface{}, root, sel, repl *solutions.TreeNode, rootA *solutions.TreeNode, rootAS *student.TreeNode) { - lib.Fatalf("%s(\nRoot:\n %s, Selected:\n%s, Replacement:\n%s\n) ==\n%s instead of\n%s\n", - "BTreeTransplant", - solutions.FormatTree(root), - solutions.FormatTree(sel), - solutions.FormatTree(repl), - FormatTree_transp(rootAS), - solutions.FormatTree(rootA), - ) -} - -func CompareTrees_transp(fn interface{}, root, sel, repl *solutions.TreeNode, rootA *solutions.TreeNode, rootAS *student.TreeNode) { - solTree := solutions.FormatTree(rootA) - stuTree := FormatTree_transp(rootAS) - - if solTree != stuTree { - errorMessage_transp(fn, root, sel, repl, rootA, rootAS) - } - parentSol := solutions.ParentList(rootA) - parentStu := parentListTransp(rootAS) - - if parentSol != parentStu { - fmt.Println("Tree:\n", solTree) - lib.Fatalf("Expected\n%s instead of\n%s\n", parentSol, parentStu) - } -} - -func main() { - root := &solutions.TreeNode{Data: "04"} - rootS := &student.TreeNode{Data: "04"} - rootOr := &solutions.TreeNode{Data: "04"} - - replacement := &solutions.TreeNode{Data: "55"} - replacementS := &student.TreeNode{Data: "55"} - - ins := []string{"01", "07", "05", "12", "02", "03", "10"} - - rep := []string{"33", "12", "15", "60"} - - for _, v := range ins { - root = solutions.BTreeInsertData(root, v) - rootS = student.BTreeInsertData(rootS, v) - rootOr = solutions.BTreeInsertData(rootOr, v) - } - - for _, v := range rep { - replacement = solutions.BTreeInsertData(replacement, v) - replacementS = student.BTreeInsertData(replacementS, v) - } - - selected := solutions.BTreeSearchItem(root, "07") - selectedS := student.BTreeSearchItem(rootS, "07") - root = solutions.BTreeTransplant(root, selected, replacement) - rootS = student.BTreeTransplant(rootS, selectedS, replacementS) - fn := interface{}(solutions.BTreeTransplant) - - CompareTrees_transp(fn, rootOr, selected, replacement, root, rootS) -} diff --git a/test-go/tests/capitalize_test/main.go b/test-go/tests/capitalize_test/main.go deleted file mode 100644 index 444274fc4..000000000 --- a/test-go/tests/capitalize_test/main.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "strings" - "unicode" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func capitalize(s string) string { - r := []rune(strings.ToLower(s)) - - if unicode.Is(unicode.Latin, r[0]) { - r[0] = unicode.ToUpper(r[0]) - } - - for i := 1; i < len(r); i++ { - if !unicode.IsDigit(r[i-1]) && !unicode.Is(unicode.Latin, r[i-1]) { - r[i] = unicode.ToUpper(r[i]) - } - } - return string(r) -} - -func main() { - table := append( - lib.MultRandASCII(), - "Hello! How are you? How+are+things+4you?", - "Hello! How are you?", - "a", - "z", - "!", - "9a", - "9a LALALA!", - ) - for _, arg := range table { - lib.Challenge("Capitalize", student.Capitalize, capitalize, arg) - } -} diff --git a/test-go/tests/cat_test/main.go b/test-go/tests/cat_test/main.go deleted file mode 100644 index 1e0eafcc3..000000000 --- a/test-go/tests/cat_test/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "io/ioutil" - "os" - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - file1 := "quest8.txt" - file2 := "quest8T.txt" - if err := ioutil.WriteFile(file1, []byte(lib.RandWords()+"\n"), os.ModePerm); err != nil { - panic(err) - } - if err := ioutil.WriteFile(file2, []byte(lib.RandWords()+"\n"), os.ModePerm); err != nil { - panic(err) - } - - table := []string{file1, file1 + " " + file2, "asd", "", file1 + " abc", "abc " + file2} - - for _, s := range table { - lib.ChallengeMain("cat", strings.Fields(s)...) - } - lib.ChallengeMainStdin("cat", lib.RandWords()+"\n") -} diff --git a/test-go/tests/chunk_test/main.go b/test-go/tests/chunk_test/main.go deleted file mode 100644 index 8fe788b57..000000000 --- a/test-go/tests/chunk_test/main.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func chunk(a []int, ch int) { - slice := []int{} - if ch <= 0 { - fmt.Println() - return - } - result := make([][]int, 0, len(a)/ch+1) - for len(a) >= ch { - slice, a = a[:ch], a[ch:] - result = append(result, slice) - } - if len(a) > 0 { - result = append(result, a[:]) - } - fmt.Println(result) -} - -func randomSize() []int { - randSlice := []int{} - for i := 0; i <= lib.RandIntBetween(0, 20); i++ { - randSlice = append(randSlice, lib.RandInt()) - } - return randSlice -} - -func main() { - type node struct { - slice []int - ch int - } - table := []node{} - - for i := 0; i <= 7; i++ { - value := node{ - slice: randomSize(), - ch: lib.RandIntBetween(0, 10), - } - table = append(table, value) - } - table = append(table, node{ - slice: []int{}, - ch: 0, - }, node{ - slice: []int{1, 2, 3, 4, 5, 6, 7, 8}, - ch: 0, - }) - for _, args := range table { - lib.Challenge("Chunk", student.Chunk, chunk, args.slice, args.ch) - } -} diff --git a/test-go/tests/cleanstr_test/main.go b/test-go/tests/cleanstr_test/main.go deleted file mode 100644 index 74ee70fd6..000000000 --- a/test-go/tests/cleanstr_test/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := []string{ - "you see it's easy to display the same thing", - " only it's harder ", - "how funny", - "", - lib.RandSpace(), - } - - for _, v := range args { - lib.ChallengeMain("cleanstr", v) - } - lib.ChallengeMain("cleanstr", "this is not", "happening") -} diff --git a/test-go/tests/collatzcountdown_test/main.go b/test-go/tests/collatzcountdown_test/main.go deleted file mode 100644 index 18f4976e1..000000000 --- a/test-go/tests/collatzcountdown_test/main.go +++ /dev/null @@ -1,37 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func collatzCountdown(start int) int { - if start <= 0 { - return -1 - } - - steps := 0 - - for start != 1 { - if start%2 == 0 { - start = start / 2 - } else { - start = 3*start + 1 - } - steps++ - } - - return steps -} - -func main() { - args := append(lib.MultRandIntBetween(2, 20), - lib.RandIntBetween(-6, 20), - -5, - 0, - ) - for _, v := range args { - lib.Challenge("CollatzCountdown", student.CollatzCountdown, collatzCountdown, v) - } -} diff --git a/test-go/tests/comcheck_test/main.go b/test-go/tests/comcheck_test/main.go deleted file mode 100644 index 5e26e7104..000000000 --- a/test-go/tests/comcheck_test/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandWords(), - "01", - "galaxy", - "galaxy01", - " 01", - "as das d 01 asd", - "as galaxy d 12", - "as ds galaxy 01 asd") - - for _, s := range table { - lib.ChallengeMain("comcheck", strings.Fields(s)...) - } -} diff --git a/test-go/tests/compact_test/main.go b/test-go/tests/compact_test/main.go deleted file mode 100644 index e490df4ad..000000000 --- a/test-go/tests/compact_test/main.go +++ /dev/null @@ -1,68 +0,0 @@ -package main - -import ( - "reflect" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func compact(slice *[]string) int { - count := 0 - var compacted []string - for _, v := range *slice { - if v != "" { - count++ - compacted = append(compacted, v) - } - } - *slice = compacted - return count -} - -func main() { - arg := [][]string{{"hello", "", "hi", "", "salut", "", ""}} - - for i := 0; i < 20; i++ { - n := lib.RandIntBetween(5, 20) - - orig := make([]string, n) - - numPos := lib.RandIntBetween(1, n-1) - - for i := 0; i < numPos; i++ { - word := lib.RandWords() - randPos := lib.RandIntBetween(0, n-1) - orig[randPos] = word - } - arg = append(arg, orig) - } - - for _, v := range arg { - solSlice := make([]string, len(arg)) - stuSlice := make([]string, len(arg)) - - copy(solSlice, v) - copy(stuSlice, v) - - solSize := compact(&solSlice) - stuSize := student.Compact(&stuSlice) - - if !reflect.DeepEqual(stuSlice, solSlice) { - lib.Fatalf("Produced slice: %v, instead of %v\n", - stuSlice, - solSlice, - ) - } - - if solSize != stuSize { - lib.Fatalf("%s(%v) == %v instead of %v\n", - "Compact", - v, - stuSlice, - solSlice, - ) - } - } -} diff --git a/test-go/tests/compare_test/main.go b/test-go/tests/compare_test/main.go deleted file mode 100644 index 0f4f1df2d..000000000 --- a/test-go/tests/compare_test/main.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "strings" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - type node struct { - s string - toCompare string - } - - table := []node{} - - // the first 15 values are returning 0 for this test - for i := 0; i < 15; i++ { - wordToTest := lib.RandASCII() - - val := node{ - s: wordToTest, - toCompare: wordToTest, - } - table = append(table, val) - } - - // the next 15 values are supposed to return 1 or -1 for this test - for i := 0; i < 15; i++ { - wordToTest := lib.RandASCII() - wrongMatch := lib.RandASCII() - - val := node{ - s: wordToTest, - toCompare: wrongMatch, - } - table = append(table, val) - } - // those are the test values from the README examples - table = append(table, - node{s: "Hello!", toCompare: "Hello!"}, - node{s: "Salut!", toCompare: "lut!"}, - node{s: "Ola!", toCompare: "Ol"}, - ) - - for _, arg := range table { - lib.Challenge("Compare", student.Compare, strings.Compare, arg.s, arg.toCompare) - } -} diff --git a/test-go/tests/concat_test/main.go b/test-go/tests/concat_test/main.go deleted file mode 100644 index da4560d1d..000000000 --- a/test-go/tests/concat_test/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := [][]string{} - - // 30 valid pair of ramdom strings to concatenate - for i := 0; i < 30; i++ { - value := []string{lib.RandASCII(), lib.RandASCII()} - table = append(table, value) - } - table = append(table, - []string{"Hello!", " How are you?"}, - ) - for _, arg := range table { - lib.Challenge("Concat", student.Concat, fmt.Sprint, arg[0], arg[1]) - } -} diff --git a/test-go/tests/concatparams_test/main.go b/test-go/tests/concatparams_test/main.go deleted file mode 100644 index a58238190..000000000 --- a/test-go/tests/concatparams_test/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "strings" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func concatParams(args []string) string { - return strings.Join(args, "\n") -} - -func main() { - table := [][]string{{"Hello", "how", "are", "you?"}} - - // 30 random slice of strings - for i := 0; i < 30; i++ { - table = append(table, lib.MultRandASCII()) - } - for _, arg := range table { - lib.Challenge("ConcatParams", student.ConcatParams, concatParams, arg) - } -} diff --git a/test-go/tests/convertbase_test/main.go b/test-go/tests/convertbase_test/main.go deleted file mode 100644 index d8524c830..000000000 --- a/test-go/tests/convertbase_test/main.go +++ /dev/null @@ -1,62 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/base" -) - -func convertNbrBase(n int, base string) string { - var result string - length := len(base) - - for n >= length { - result = string(base[(n%length)]) + result - n /= length - } - result = string(base[n]) + result - - return result -} - -func convertBase(nbr, baseFrom, baseTo string) string { - resultIntermediary := base.Atoi(nbr, baseFrom) - - resultFinal := convertNbrBase(resultIntermediary, baseTo) - - return resultFinal -} - -func main() { - type node struct { - nbr string - baseFrom string - baseTo string - } - table := []node{} - - for i := 0; i < 30; i++ { - validBaseToInput1 := base.Valid() - validBaseToInput2 := base.Valid() - str := base.ConvertNbr(lib.RandIntBetween(0, 1000000), validBaseToInput1) - val := node{ - nbr: str, - baseFrom: validBaseToInput1, - baseTo: validBaseToInput2, - } - table = append(table, val) - } - - table = append(table, node{ - nbr: "101011", - baseFrom: "01", - baseTo: "0123456789", - }) - - for _, arg := range table { - lib.Challenge("ConvertBase", student.ConvertBase, convertBase, arg.nbr, arg.baseFrom, arg.baseTo) - } -} - -// TODO: fix base exercises diff --git a/test-go/tests/costumeprofit_test/main.go b/test-go/tests/costumeprofit_test/main.go deleted file mode 100644 index 0e6ff7ead..000000000 --- a/test-go/tests/costumeprofit_test/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "strconv" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - for i := 0; i < 25; i++ { - lib.ChallengeMain("costumeprofit", - strconv.Itoa(lib.RandIntBetween(0, 1000)), - strconv.Itoa(lib.RandIntBetween(0, 1000)), - strconv.Itoa(lib.RandIntBetween(0, 1000)), - strconv.Itoa(lib.RandIntBetween(0, 1000)), - strconv.Itoa(lib.RandIntBetween(0, 1000)), - strconv.Itoa(lib.RandIntBetween(0, 1000)), - ) - } -} diff --git a/test-go/tests/countdown_test/main.go b/test-go/tests/countdown_test/main.go deleted file mode 100644 index b4af2f4e5..000000000 --- a/test-go/tests/countdown_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("countdown") -} diff --git a/test-go/tests/countif_test/main.go b/test-go/tests/countif_test/main.go deleted file mode 100644 index 3bfd47b84..000000000 --- a/test-go/tests/countif_test/main.go +++ /dev/null @@ -1,76 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/is" -) - -func countIf(f func(string) bool, a []string) int { - counter := 0 - for _, el := range a { - if f(el) { - counter++ - } - } - - return counter -} - -func main() { - functions := []func(string) bool{is.Digit, is.Lower, is.Upper} - - type node struct { - f func(string) bool - a []string - } - - table := []node{} - - for i := 0; i < 5; i++ { - function := functions[lib.RandIntBetween(0, len(functions)-1)] - val := node{ - f: function, - a: lib.MultRandWords(), - } - table = append(table, val) - } - for i := 0; i < 5; i++ { - val := node{ - f: is.Digit, - a: lib.MultRandDigit(), - } - table = append(table, val) - } - - for i := 0; i < 5; i++ { - val := node{ - f: is.Lower, - a: lib.MultRandLower(), - } - table = append(table, val) - } - for i := 0; i < 5; i++ { - val := node{ - f: is.Upper, - a: lib.MultRandUpper(), - } - table = append(table, val) - } - - table = append(table, - node{ - f: is.Digit, - a: []string{"Hello", "how", "are", "you"}, - }, - node{ - f: is.Digit, - a: []string{"This", "is", "4", "you"}, - }, - ) - - for _, arg := range table { - lib.Challenge("CountIf", student.CountIf, countIf, arg.f, arg.a) - } -} diff --git a/test-go/tests/displaya_test/main.go b/test-go/tests/displaya_test/main.go deleted file mode 100644 index 215dd4699..000000000 --- a/test-go/tests/displaya_test/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandWords(), - "dsfda", - "", - "1", - "1", - ) - for _, s := range table { - lib.ChallengeMain("displaya", strings.Fields(s)...) - } - lib.ChallengeMain("displaya", "1", "a") -} diff --git a/test-go/tests/displayalpham_test/main.go b/test-go/tests/displayalpham_test/main.go deleted file mode 100644 index 937e3862f..000000000 --- a/test-go/tests/displayalpham_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("displayalpham") -} diff --git a/test-go/tests/displayalrevm_test/main.go b/test-go/tests/displayalrevm_test/main.go deleted file mode 100644 index 04a5f4bc3..000000000 --- a/test-go/tests/displayalrevm_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("displayalrevm") -} diff --git a/test-go/tests/displayfile_test/main.go b/test-go/tests/displayfile_test/main.go deleted file mode 100644 index 51902e3f9..000000000 --- a/test-go/tests/displayfile_test/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "io/ioutil" - "os" - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - fileName := "quest8.txt" - if err := ioutil.WriteFile(fileName, []byte("Almost there!!\n"), os.ModePerm); err != nil { - panic(err) - } - table := []string{"", fileName, fileName + " asdsada"} - for _, s := range table { - lib.ChallengeMain("displayfile", strings.Fields(s)...) - } -} diff --git a/test-go/tests/displayfirstparam_test/main.go b/test-go/tests/displayfirstparam_test/main.go deleted file mode 100644 index 48add520d..000000000 --- a/test-go/tests/displayfirstparam_test/main.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandWords(), - " ", - "1", - "1 2", - "1 2 3", - ) - for _, s := range table { - lib.ChallengeMain("displayfirstparam", strings.Fields(s)...) - } -} diff --git a/test-go/tests/displaylastparam_test/main.go b/test-go/tests/displaylastparam_test/main.go deleted file mode 100644 index d21e19a2b..000000000 --- a/test-go/tests/displaylastparam_test/main.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandWords(), - " ", - "1", - "1 2", - "1 2 3", - ) - for _, s := range table { - lib.ChallengeMain("displaylastparam", strings.Fields(s)...) - } -} diff --git a/test-go/tests/displayz_test/main.go b/test-go/tests/displayz_test/main.go deleted file mode 100644 index d437764d8..000000000 --- a/test-go/tests/displayz_test/main.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandWords(), - "dsfdz", - "", - "1", - "1", - ) - for _, s := range table { - lib.ChallengeMain("displayz", strings.Fields(s)...) - } - - lib.ChallengeMain("displayz", "1", "z") -} diff --git a/test-go/tests/divmod_test/main.go b/test-go/tests/divmod_test/main.go deleted file mode 100644 index 1cb09c882..000000000 --- a/test-go/tests/divmod_test/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - i := 0 - for i < lib.SliceLen { - a := lib.RandInt() - b := lib.RandInt() - var div int - var mod int - student.DivMod(a, b, &div, &mod) - if div != a/b { - lib.Fatalf("DivMod(%d, %d, &div, &mod), div == %d instead of %d", a, b, div, a/b) - } - if mod != a%b { - lib.Fatalf("DivMod(%d, %d, &div, &mod), mod == %d instead of %d", a, b, mod, a%b) - } - i++ - } -} diff --git a/test-go/tests/doop_test/main.go b/test-go/tests/doop_test/main.go deleted file mode 100644 index e52b19df4..000000000 --- a/test-go/tests/doop_test/main.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "strconv" - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - operatorsTable := []string{"+", "-", "*", "/", "%"} - - table := []string{} - - for i := 0; i < 4; i++ { - firstArg := strconv.Itoa(lib.RandIntBetween(-1000, 1000)) - secondArg := strconv.Itoa(lib.RandIntBetween(0, 1000)) - - for _, operator := range operatorsTable { - table = append(table, firstArg+" "+operator+" "+secondArg) - } - } - - table = append(table, "1 + 1") - table = append(table, "hello + 1") - table = append(table, "1 p 1") - table = append(table, "1 / 0") - table = append(table, "1 # 1") - table = append(table, "1 % 0") - table = append(table, "1 * 1") - table = append(table, "1argument") - table = append(table, "2 arguments") - table = append(table, "4 arguments so invalid") - table = append(table, "9223372036854775807 + 1") - table = append(table, "9223372036854775809 - 3") - table = append(table, "9223372036854775807 * 3") - for _, s := range table { - lib.ChallengeMain("doop", strings.Fields(s)...) - } -} diff --git a/test-go/tests/doppelganger_test/main.go b/test-go/tests/doppelganger_test/main.go deleted file mode 100644 index 3c4be10ab..000000000 --- a/test-go/tests/doppelganger_test/main.go +++ /dev/null @@ -1,54 +0,0 @@ -package main - -import ( - "strings" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -type node struct { - big, little string -} - -func main() { - table := []node{} - - table = append(table, - node{"aaaaaaa", "a"}, - node{"qwerty", "t"}, - node{"a", "b"}, - ) - - for i := 0; i < 10; i++ { - l := lib.RandIntBetween(5, 30) - big := lib.RandStr(l, "qwertyuiopasdfghjklzxcvbnm") - start := lib.RandIntBetween(0, l-1) - end := lib.RandIntBetween(start+1, l-1) - little := big[start:end] - - value := node{ - big: big, - little: little, - } - - table = append(table, value) - } - - for i := 0; i < 10; i++ { - big := lib.RandStr(lib.RandIntBetween(5, 30), "qwertyuiopasdfghjklzxcvbnm") - little := lib.RandStr(lib.RandIntBetween(1, 29), "qwertyuiopasdfghjklzxcvbnm") - - value := node{ - big: big, - little: little, - } - - table = append(table, value) - } - - for _, arg := range table { - lib.Challenge("DoppelGanger", student.DoppelGanger, strings.LastIndex, arg.big, arg.little) - } -} diff --git a/test-go/tests/eightqueens_test/main.go b/test-go/tests/eightqueens_test/main.go deleted file mode 100644 index a5cf57642..000000000 --- a/test-go/tests/eightqueens_test/main.go +++ /dev/null @@ -1,88 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -const size = 8 - -// board is a chessboard composed of boolean squares, a true square means a queen is on it -// a false square means it is a free square -var board [size][size]bool - -// goodDirection check that there is no queen on the segment that starts at (x, y) -// coordinates, points into the direction vector (vx, vy) and ends at the edge of the board -func goodDirection(x, y, vx, vy int) bool { - // x and y are still on board - for 0 <= x && x < size && - 0 <= y && y < size { - if board[x][y] { - // Not a good line : the square is already occupied - return false - } - x += vx // Move x in the right direction - y += vy // Move y in the right direction - } - // All clear - return true -} - -// goodSquare makes all the necessary line checks for the queens movements -func goodSquare(x, y int) bool { - return goodDirection(x, y, +0, -1) && - goodDirection(x, y, +1, -1) && - goodDirection(x, y, +1, +0) && - goodDirection(x, y, +1, +1) && - goodDirection(x, y, +0, +1) && - goodDirection(x, y, -1, +1) && - goodDirection(x, y, -1, +0) && - goodDirection(x, y, -1, -1) -} - -func printQueens() { - for x := 0; x < size; x++ { - for y := 0; y < size; y++ { - if board[x][y] { - // We have found a queen, let's print her y - fmt.Printf("%c", rune(y)+'1') - } - } - } - fmt.Println() -} - -// tryX tries, for a given x (column) to find a y (row) so that the queen on (x, y) is a part -// of the solution to the problem -func tryX(x int) { - for y := 0; y < size; y++ { - if goodSquare(x, y) { - // Since the square is good for the queen, let's put one on it: - board[x][y] = true - - if x == size-1 { - // x is the biggest possible x, it means that we just placed the last - // queen on the board, so the solution is complete and we can print it - printQueens() - } else { - // let's try to put another queen on the next empty x (column) - tryX(x + 1) - } - - // remove the queen of the board, to try other y values - board[x][y] = false - } - } -} - -func eightQueens() { - // try the first column - tryX(0) -} - -func main() { - lib.Challenge("EightQueens", student.EightQueens, eightQueens) -} diff --git a/test-go/tests/enigma_test/main.go b/test-go/tests/enigma_test/main.go deleted file mode 100644 index 70ca92e13..000000000 --- a/test-go/tests/enigma_test/main.go +++ /dev/null @@ -1,77 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -// Helper function used in the test for checking the function Enigma() -func decrypt(a ***int, b *int, c *******int, d ****int) { - vala := ***a - ***a = *******c - valb := *b - *b = vala - vald := ****d - ****d = valb - *******c = vald -} - -func main() { - args := lib.MultRandIntBetween(2, 20) - - aval := args[0] - x := args[0] - y := &x - z := &y - a := &z - - bval := args[1] - w := args[1] - b := &w - - cval := args[2] - u := args[2] - e := &u - f := &e - g := &f - h := &g - i := &h - j := &i - c := &j - - dval := args[3] - k := args[3] - l := &k - m := &l - n := &m - d := &n - - student.Enigma(a, b, c, d) - decrypt(a, b, c, d) - - if aval != ***a { - lib.Fatalf("Expected ***a = %d instead of %d\n", - aval, - ***a, - ) - } - if bval != *b { - lib.Fatalf("Expected *b = %d instead of %d\n", - bval, - *b, - ) - } - if cval != *******c { - lib.Fatalf("Expected *******c = %d instead of %d\n", - cval, - *******c, - ) - } - if dval != ****d { - lib.Fatalf("Expected ****d = %d instead of %d\n", - dval, - ****d, - ) - } -} diff --git a/test-go/tests/expandstr_test/main.go b/test-go/tests/expandstr_test/main.go deleted file mode 100644 index 384e62522..000000000 --- a/test-go/tests/expandstr_test/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := [][]string{ - {"hello", "you"}, - {" only it's harder "}, - {"you see it's easy to display the same thing"}, - } - - args = append(args, lib.MultRandWords()) - - for _, v := range args { - lib.ChallengeMain("expandstr", v...) - } - lib.ChallengeMain("expandstr") -} diff --git a/test-go/tests/fib_test/main.go b/test-go/tests/fib_test/main.go deleted file mode 100644 index a8c765df3..000000000 --- a/test-go/tests/fib_test/main.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func fib(n int) int { - if n <= 0 { - return 0 - } - t1 := 0 - t2 := 1 - for i := 2; i <= n; i++ { - t1 += t2 - t1, t2 = t2, t1 - } - return t2 -} - -func main() { - table := append(lib.MultRandIntBetween(-100, 150), - 20, - 0, - 9, - 2, - ) - for _, arg := range table { - lib.Challenge("Fib", student.Fib, fib, arg) - } -} diff --git a/test-go/tests/fibonacci_test/main.go b/test-go/tests/fibonacci_test/main.go deleted file mode 100644 index b0354c64c..000000000 --- a/test-go/tests/fibonacci_test/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func fibonacci(i int) int { - if i < 0 { - return -1 - } - if i == 0 { - return 0 - } - if i == 1 { - return 1 - } - return fibonacci(i-1) + fibonacci(i-2) -} - -func main() { - table := append(lib.MultRandIntBetween(0, 25), - 4, - 5, - -5, - ) - for _, arg := range table { - lib.Challenge("Fibonacci", student.Fibonacci, fibonacci, arg) - } -} diff --git a/test-go/tests/findnextprime_test/main.go b/test-go/tests/findnextprime_test/main.go deleted file mode 100644 index 21549adcd..000000000 --- a/test-go/tests/findnextprime_test/main.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/is" -) - -func findNextPrime(nb int) int { - if is.Prime(nb) { - return nb - } - return findNextPrime(nb + 1) -} - -func main() { - table := append(lib.MultRandIntBetween(-1000000, 1000000), - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 100, - 1000000086, - 1000000087, - 1000000088, - ) - for _, arg := range table { - lib.Challenge("FindNextPrime", student.FindNextPrime, findNextPrime, arg) - } -} diff --git a/test-go/tests/findprevprime_test/main.go b/test-go/tests/findprevprime_test/main.go deleted file mode 100644 index 50daf2013..000000000 --- a/test-go/tests/findprevprime_test/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/is" -) - -func findPrevPrime(nb int) int { - if nb < 2 { - return 0 - } - if is.Prime(nb) { - return nb - } - return findPrevPrime(nb - 1) -} - -func main() { - elems := append(lib.MultRandIntBetween(0, 99999), 5, 4, 1) - for _, elem := range elems { - lib.Challenge("FindPrevPrime", student.FindPrevPrime, findPrevPrime, elem) - } -} diff --git a/test-go/tests/firstrune_test/main.go b/test-go/tests/firstrune_test/main.go deleted file mode 100644 index 74ff8d606..000000000 --- a/test-go/tests/firstrune_test/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func firstRune(s string) rune { - runes := []rune(s) - return runes[0] -} - -func main() { - table := append( - lib.MultRandASCII(), - "Hello!", - "Salut!", - "Ola!", - "♥01", - ) - for _, arg := range table { - lib.Challenge("FirstRune", student.FirstRune, firstRune, arg) - } -} diff --git a/test-go/tests/firstword_test/main.go b/test-go/tests/firstword_test/main.go deleted file mode 100644 index 4a9428847..000000000 --- a/test-go/tests/firstword_test/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandWords(), - "", - " a as", - " f d", - " asd ad", - " salut !!! ", - " salut ! ! !", - "salut ! !", - ) - for _, s := range table { - lib.ChallengeMain("firstword", s) - } -} diff --git a/test-go/tests/fixthemain_test/main.go b/test-go/tests/fixthemain_test/main.go deleted file mode 100644 index 0b6323504..000000000 --- a/test-go/tests/fixthemain_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("fixthemain") -} diff --git a/test-go/tests/flags_test/main.go b/test-go/tests/flags_test/main.go deleted file mode 100644 index 4cee3f5c5..000000000 --- a/test-go/tests/flags_test/main.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -type node struct { - flags []string - flagsShorthand []string - randArgFlag []string - randArg []string -} - -func main() { - s := []string{"--insert=", "--order"} - strShorthand := []string{"-i=", "-o"} - var randflag []string - var randflagarg []string - for i := 0; i < 2; i++ { - randflagarg = append(randflagarg, lib.RandWords()) - randflag = append(randflag, lib.RandWords()) - } - - node := &node{ - flags: s, - flagsShorthand: strShorthand, - randArgFlag: randflagarg, - randArg: randflag, - } - - node.randArg = append(node.randArg, "") - - lib.ChallengeMain("flags", node.flagsShorthand[0]+"v2", "v1") - lib.ChallengeMain("flags", node.flagsShorthand[1], "v1") - lib.ChallengeMain("flags", "-h") - lib.ChallengeMain("flags", "--help") - lib.ChallengeMain("flags") - - for _, v2 := range node.randArgFlag { - for _, v1 := range node.randArg { - lib.ChallengeMain("flags", node.flags[0]+v2, node.flags[1], v1) - } - } - for _, v2 := range node.randArgFlag { - for _, v1 := range node.randArg { - lib.ChallengeMain("flags", node.flagsShorthand[0]+v2, node.flagsShorthand[1], v1) - } - } -} diff --git a/test-go/tests/foldint_test/main.go b/test-go/tests/foldint_test/main.go deleted file mode 100644 index 5a112c3ed..000000000 --- a/test-go/tests/foldint_test/main.go +++ /dev/null @@ -1,66 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func foldInt(f func(int, int) int, a []int, n int) { - result := n - for _, v := range a { - result = f(result, v) - } - fmt.Println(result) -} - -func main() { - f := []func(int, int) int{ - func(accumulator, currentValue int) int { - return accumulator + currentValue - }, - func(accumulator, currentValue int) int { - return accumulator - currentValue - }, - func(accumulator, currentValue int) int { - return currentValue * accumulator - }, - } - - type node struct { - a []int - functions []func(int, int) int - n int - } - argInt := []int{} - table := []node{} - - for i := 0; i < 8; i++ { - argInt = append(argInt, lib.MultRandIntBetween(0, 50)...) - table = append(table, node{ - a: argInt, - functions: f, - n: lib.RandIntBetween(0, 60), - }) - } - - table = append(table, node{ - a: []int{1, 2, 3}, - functions: f, - n: 93, - }) - - table = append(table, node{ - a: []int{0}, - functions: f, - n: 93, - }) - - for _, v := range table { - for _, f := range v.functions { - lib.Challenge("FoldInt", student.FoldInt, foldInt, f, v.a, v.n) - } - } -} diff --git a/test-go/tests/foreach_test/main.go b/test-go/tests/foreach_test/main.go deleted file mode 100644 index ac04bbc83..000000000 --- a/test-go/tests/foreach_test/main.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func forEach(f func(int), a []int) { - for _, el := range a { - f(el) - } -} - -func add0(i int) { - fmt.Println(i) -} - -func add1(i int) { - fmt.Println(i + 1) -} - -func add2(i int) { - fmt.Println(i + 2) -} - -func add3(i int) { - fmt.Println(i + 3) -} - -func main() { - functions := []func(int){add0, add1, add2, add3} - - type node struct { - f func(int) - a []int - } - - table := []node{} - - // 15 random slice of random ints with a random function from selection - for i := 0; i < 15; i++ { - function := functions[lib.RandIntBetween(0, len(functions)-1)] - table = append(table, node{ - f: function, - a: lib.MultRandIntBetween(-1000000, 1000000), - }) - } - - table = append(table, node{ - f: add0, - a: []int{1, 2, 3, 4, 5, 6}, - }) - - for _, arg := range table { - lib.Challenge("ForEach", student.ForEach, forEach, arg.f, arg.a) - } -} diff --git a/test-go/tests/fprime_test/main.go b/test-go/tests/fprime_test/main.go deleted file mode 100644 index edc10012e..000000000 --- a/test-go/tests/fprime_test/main.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - "strconv" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := []string{ - " ", - "1", - "1 1", - "hello", - "p 1", - "804577", - "225225", - "8333325", - "42", - "9539", - "1000002", - "1000003", - } - for i := 0; i < 10; i++ { - table = append(table, strconv.Itoa(lib.RandIntBetween(1, 100))) - } - for _, s := range table { - lib.ChallengeMain("fprime", s) - } -} diff --git a/test-go/tests/game23_test/main.go b/test-go/tests/game23_test/main.go deleted file mode 100644 index 663b12a53..000000000 --- a/test-go/tests/game23_test/main.go +++ /dev/null @@ -1,76 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func game23(a, b int) int { - if a > b { - return -1 - } - if a == b { - return 0 - } - if game23(a*2, b) != -1 { - return 1 + game23(a*2, b) - } - if game23(a*3, b) != -1 { - return 1 + game23(a*3, b) - } - return -1 -} - -func nd(a, b int) int { - if a > b { - return -1 - } - if a == b { - return 0 - } - if nd(a*2, b) != -1 { - return 1 + nd(a*2, b) - } - if nd(a*3, b) != -1 { - return 1 + nd(a*3, b) - } - return -1 -} - -func main() { - type node struct { - init int - fin int - } - table := []node{ - {50, 43}, - {13, 13}, - {10, 9}, - {5, 9}, - } - - for i := 0; i < 20; i++ { - table = append(table, node{ - init: lib.RandIntBetween(1, 1000), - fin: lib.RandIntBetween(1, 1000), - }) - } - - for i := 1; i < 100; i++ { - value := node{ - init: 1, - fin: 1, - } - if nd(1, i) > 0 { - value = node{ - init: 1, - fin: i, - } - } - table = append(table, value) - } - for _, arg := range table { - lib.Challenge("Game23", student.Game23, game23, arg.init, arg.fin) - } -} diff --git a/test-go/tests/gcd_test/main.go b/test-go/tests/gcd_test/main.go deleted file mode 100644 index 58741de23..000000000 --- a/test-go/tests/gcd_test/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "strconv" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := [][]string{ - {"23"}, - {"12", "23"}, - {"25", "15"}, - {"23043", "122"}, - {"11", "77"}, - } - for i := 0; i < 25; i++ { - a := strconv.Itoa(lib.RandIntBetween(1, 100000)) - b := strconv.Itoa(lib.RandIntBetween(1, 100)) - args = append(args, []string{a, b}) - } - for _, v := range args { - lib.ChallengeMain("gcd", v...) - } -} diff --git a/test-go/tests/grouping_test/main.go b/test-go/tests/grouping_test/main.go deleted file mode 100644 index bf7b77e01..000000000 --- a/test-go/tests/grouping_test/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func validRegExp(n int) string { - result := "(" - - for i := 0; i < n; i++ { - result += lib.RandStr(1, lib.Lower) - if lib.RandInt()%2 == 0 { - result += lib.RandStr(1, lib.Lower) - } - if i != n-1 { - result += "|" - } - } - - result += ")" - return result -} - -func main() { - args := [][2]string{ - {"(a)", "I'm heavyjumpsuit is on steady, Lighter when I'm lower, higher when I'm heavy"}, - {"(e|n)", "I currently have 4 windows opened up… and I don’t know why."}, - {"(hi)", "He swore he just saw his sushi move."}, - {"(s)", ""}, - {"i", "Something in the air"}, - {validRegExp(2), lib.RandStr(60, lib.Lower+lib.Space)}, - {validRegExp(2), lib.RandStr(60, lib.Lower+lib.Space)}, - {validRegExp(6), lib.RandStr(60, lib.Lower+lib.Space)}, - {lib.RandStr(1, "axyz"), lib.RandStr(10, "axyzdassbzzxxxyy cdq ")}, - } - for _, s := range args { - lib.ChallengeMain("grouping", s[0], s[1]) - } -} diff --git a/test-go/tests/halfcontest_test/main.go b/test-go/tests/halfcontest_test/main.go deleted file mode 100644 index fb48fae57..000000000 --- a/test-go/tests/halfcontest_test/main.go +++ /dev/null @@ -1,42 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func halfContest(h1, m1, h2, m2 int) int { - t1 := h1*60 + m1 - t2 := h2*60 + m2 - t2 = (t2 + t1) / 2 - h2 = t2 / 60 - m2 = t2 % 60 - return h2*100 + m2 -} - -func main() { - type node struct { - h1, m1 int - h2, m2 int - } - table := []node{ - {11, 44, 21, 59}, - {1, 12, 1, 14}, - {5, 50, 6, 51}, - {14, 35, 18, 55}, - } - - for i := 0; i < 20; i++ { - table = append(table, node{ - h1: lib.RandIntBetween(0, 10), - m1: lib.RandIntBetween(0, 59), - h2: lib.RandIntBetween(11, 23), - m2: lib.RandIntBetween(0, 59), - }) - } - - for _, arg := range table { - lib.Challenge("HalfContest", student.HalfContest, halfContest, arg.h1, arg.m1, arg.h2, arg.m2) - } -} diff --git a/test-go/tests/hello_test/main.go b/test-go/tests/hello_test/main.go deleted file mode 100644 index a4db00110..000000000 --- a/test-go/tests/hello_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("hello") -} diff --git a/test-go/tests/hiddenp_test/main.go b/test-go/tests/hiddenp_test/main.go deleted file mode 100644 index 8ac283e38..000000000 --- a/test-go/tests/hiddenp_test/main.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := [][2]string{ - {"fgex.;", "tyf34gdgf;'ektufjhgdgex.;.;rtjynur6"}, - {"abc", "2altrb53c.sse"}, - {"abc", "btarc"}, - {"DD", "DABC"}, - {""}, - } - for i := 0; i < 30; i++ { - args = append(args, - [2]string{lib.RandStr(1, lib.Lower), lib.RandLower()}, - [2]string{lib.RandStr(1, lib.Upper), lib.RandUpper()}, - ) - } - for _, v := range args { - lib.ChallengeMain("hiddenp", v[0], v[1]) - } -} diff --git a/test-go/tests/index_test/main.go b/test-go/tests/index_test/main.go deleted file mode 100644 index bb03afa2b..000000000 --- a/test-go/tests/index_test/main.go +++ /dev/null @@ -1,57 +0,0 @@ -package main - -import ( - "strings" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func index(s string, substr string) int { - return strings.Index(s, substr) -} - -func main() { - type node struct { - s string - toFind string - } - - table := []node{} - - // the first 15 values are valid for this test - for i := 0; i < 15; i++ { - wordToTest := lib.RandASCII() - firstLetterIndex := lib.RandIntBetween(0, (len(wordToTest)-1)/2) - lastLetterIndex := lib.RandIntBetween(firstLetterIndex, len(wordToTest)-1) - - val := node{ - s: wordToTest, - toFind: wordToTest[firstLetterIndex:lastLetterIndex], - } - table = append(table, val) - } - - // the next 15 values are supposed to be invalid for this test - for i := 0; i < 15; i++ { - wordToTest := lib.RandASCII() - wrongMatch := lib.RandASCII() - - val := node{ - s: wordToTest, - toFind: wrongMatch, - } - table = append(table, val) - } - // those are the test values from the README examples - table = append(table, - node{s: "Hello!", toFind: "l"}, - node{s: "Salut!", toFind: "alu"}, - node{s: "Ola!", toFind: "hOl"}, - ) - - for _, arg := range table { - lib.Challenge("Index", student.Index, index, arg.s, arg.toFind) - } -} diff --git a/test-go/tests/inter_test/main.go b/test-go/tests/inter_test/main.go deleted file mode 100644 index a743f0794..000000000 --- a/test-go/tests/inter_test/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := append(lib.MultRandWords(), - "padinton paqefwtdjetyiytjneytjoeyjnejeyj", - "ddf6vewg64f twthgdwthdwfteewhrtag6h4ffdhsd", - "abcdefghij efghijlmnopq", - "123456 456789", - "1 1", - "1 2", - ) - - for i := 0; i < 5; i++ { - s1 := lib.RandAlnum() - s2 := lib.RandAlnum() + s1 + lib.RandAlnum() - args = append(args, - s1+" "+s2, - lib.RandAlnum()+" "+lib.RandAlnum(), - ) - } - - for _, s := range args { - lib.ChallengeMain("inter", strings.Fields(s)...) - } -} diff --git a/test-go/tests/interestingnumber_test/main.go b/test-go/tests/interestingnumber_test/main.go deleted file mode 100644 index 626d9ec37..000000000 --- a/test-go/tests/interestingnumber_test/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func isInteresting(n int) bool { - s := 0 - for n > 0 { - s += n % 10 - n /= 10 - } - return s%7 == 0 -} - -func interestingNumber(n int) int { - for { - if isInteresting(n) { - return n - } - n++ - } -} - -func main() { - table := []int{ - 20, - 1, - 9, - 2, - } - table = append(table, lib.MultRandIntBetween(1, 1500)...) - - for _, arg := range table { - lib.Challenge("InterestingNumber", student.InterestingNumber, interestingNumber, arg) - } -} diff --git a/test-go/tests/isalpha_test/main.go b/test-go/tests/isalpha_test/main.go deleted file mode 100644 index 11682eb57..000000000 --- a/test-go/tests/isalpha_test/main.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "unicode" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func isAlpha(s string) bool { - for _, r := range s { - if !unicode.IsDigit(r) && !unicode.Is(unicode.Latin, r) { - return false - } - } - return true -} - -func main() { - table := append( - lib.MultRandASCII(), - "Hello! €How are you?", - "a", - "z", - "!", - "HelloHowareyou", - "What's this 4?", - "Whatsthis4", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!", - ) - for _, arg := range table { - lib.Challenge("IsAlpha", student.IsAlpha, isAlpha, arg) - } -} diff --git a/test-go/tests/isanagram_test/main.go b/test-go/tests/isanagram_test/main.go deleted file mode 100644 index 8a04d8f08..000000000 --- a/test-go/tests/isanagram_test/main.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func isAnagram(s, t string) bool { - alph := make([]int, 26) - for i := 0; i < len(s); i++ { - if s[i] < 'a' || s[i] > 'z' { - continue - } - alph[s[i]-'a']++ - } - for i := 0; i < len(t); i++ { - if t[i] < 'a' || t[i] > 'z' { - continue - } - alph[t[i]-'a']-- - } - for i := 0; i < 26; i++ { - if alph[i] != 0 { - return false - } - } - return true -} - -func main() { - table := [][2]string{ - {"listen", "silent"}, - {"alem", "school"}, - {"neat", "a net"}, - {"anna madrigal", "a man and a girl"}, - {"abcc", "abcd"}, - {"aaaac", "caaaa"}, - {"", ""}, - {" ", ""}, - {"lyam", "meow"}, - {"golang", "lang go"}, - {"verylongword", "v e r y l o n g w o r d"}, - {"chess", "ches"}, - {"anagram", "nnagram"}, - {"chess", "board"}, - {"mmm", "m"}, - {"pulp", "fiction"}, - } - for i := 0; i < 15; i++ { - table = append(table, [2]string{ - lib.RandStr(lib.RandIntBetween(15, 20), "qwertyuiopasdfghjklzxcvbnm "), - lib.RandStr(lib.RandIntBetween(15, 20), "qwertyuiopasdfghjklzxcvbnm "), - }) - } - - for _, arg := range table { - lib.Challenge("IsAnagram", student.IsAnagram, isAnagram, arg[0], arg[1]) - } -} diff --git a/test-go/tests/islower_test/main.go b/test-go/tests/islower_test/main.go deleted file mode 100644 index 8cf8495ef..000000000 --- a/test-go/tests/islower_test/main.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/is" -) - -func main() { - // 15 unvalid strings in the table - table := lib.MultRandASCII() - - // 15 valid lowercase strings of random size between 1 and 20 letters in the table - for i := 0; i < 15; i++ { - size := lib.RandIntBetween(1, 20) - randLow := lib.RandLower() - if len(randLow) <= size { - table = append(table, randLow) - } else { - table = append(table, randLow[:size]) - } - } - - // Special cases added to table - table = append(table, - "Hello! How are you?", - "a", - "z", - "!", - "HelloHowareyou", - "What's this 4?", - "Whatsthis4", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!", - "0123456789", - "01,02,03", - "abcdefghijklmnopqrstuvwxyz", - "hello", - "hello!", - ) - for _, arg := range table { - lib.Challenge("IsLower", student.IsLower, is.Lower, arg) - } -} diff --git a/test-go/tests/isnegative_test/main.go b/test-go/tests/isnegative_test/main.go deleted file mode 100644 index 24843ef7e..000000000 --- a/test-go/tests/isnegative_test/main.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func isNegative(n int) { - if n < 0 { - fmt.Println("T") - } else { - fmt.Println("F") - } -} - -func main() { - table := append( - lib.MultRandInt(), - lib.MinInt, - lib.MaxInt, - 0, - ) - for _, arg := range table { - lib.Challenge("IsNegative", student.IsNegative, isNegative, arg) - } -} diff --git a/test-go/tests/isnumeric_test/main.go b/test-go/tests/isnumeric_test/main.go deleted file mode 100644 index a63935a5c..000000000 --- a/test-go/tests/isnumeric_test/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/is" -) - -func main() { - // 15 unvalid strings in the table - table := lib.MultRandASCII() - - // 15 valid strings in the table - for i := 0; i < 15; i++ { - table = append(table, strconv.Itoa(lib.RandIntBetween(0, 1000000))) - } - - // Special cases added to table - table = append(table, - "Hello! How are you?", - "a", - "z", - "!", - "HelloHowareyou", - "What's this 4?", - "Whatsthis4", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!", - "0123456789", - "010203", - "01,02,03", - ) - for _, arg := range table { - lib.Challenge("IsNumeric", student.IsNumeric, is.Digit, arg) - } -} diff --git a/test-go/tests/ispowerof2_test/main.go b/test-go/tests/ispowerof2_test/main.go deleted file mode 100644 index 6b9fd4724..000000000 --- a/test-go/tests/ispowerof2_test/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "strconv" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := [][]string{ - {"1"}, - {"2"}, - {"3"}, - {"4"}, - {"1024"}, - {"4096"}, - {"8388608"}, - {"1", "2"}, - {}, - } - for i := 0; i < 12; i++ { - args = append(args, []string{strconv.Itoa(lib.RandIntBetween(1, 2048))}) - } - for _, v := range args { - lib.ChallengeMain("ispowerof2", v...) - } -} diff --git a/test-go/tests/isprime_test/main.go b/test-go/tests/isprime_test/main.go deleted file mode 100644 index 9901b414c..000000000 --- a/test-go/tests/isprime_test/main.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/is" -) - -func main() { - table := append( - lib.MultRandIntBetween(-1000000, 1000000), - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 100, - 1000000086, - 1000000087, - ) - for _, arg := range table { - lib.Challenge("IsPrime", student.IsPrime, is.Prime, arg) - } -} diff --git a/test-go/tests/isprintable_test/main.go b/test-go/tests/isprintable_test/main.go deleted file mode 100644 index c5109aa03..000000000 --- a/test-go/tests/isprintable_test/main.go +++ /dev/null @@ -1,58 +0,0 @@ -package main - -import ( - "math/rand" - "unicode" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func isPrintable(s string) bool { - for _, r := range s { - if !unicode.IsPrint(r) { - return false - } - } - return true -} - -func main() { - // 15 unvalid strings in the table - table := lib.MultRandASCII() - - // 15 valid lowercase strings of random size between 1 and 20 letters in the table - for i := 0; i < 15; i++ { - letters := []rune("\a\b\f\r\n\v\t") - size := lib.RandIntBetween(1, 20) - r := make([]rune, size) - for i := range r { - r[i] = letters[rand.Intn(len(letters))] - } - table = append(table, string(r)) - } - - // Special cases added to table - table = append(table, - "Hello! How are you?", - "a", - "z", - "!", - "HelloHowareyou", - "What's this 4?", - "Whatsthis4", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!", - "0123456789", - "01,02,03", - "abcdefghijklmnopqrstuvwxyz", - "hello", - "hello!", - "hello\n", - "\n", - ) - for _, arg := range table { - lib.Challenge("IsPrintable", student.IsPrintable, isPrintable, arg) - } -} diff --git a/test-go/tests/issorted_test/main.go b/test-go/tests/issorted_test/main.go deleted file mode 100644 index e3615293a..000000000 --- a/test-go/tests/issorted_test/main.go +++ /dev/null @@ -1,122 +0,0 @@ -package main - -import ( - "sort" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func isSorted(f func(int, int) int, a []int) bool { - ascendingOrdered := true - descendingOrdered := true - - for i := 1; i < len(a); i++ { - if f(a[i-1], a[i]) < 0 { - ascendingOrdered = false - } - } - - for i := 1; i < len(a); i++ { - if f(a[i-1], a[i]) > 0 { - descendingOrdered = false - } - } - - return ascendingOrdered || descendingOrdered -} - -func isSortedBy1(a, b int) int { - if a-b < 0 { - return -1 - } - if a-b > 0 { - return 1 - } - return 0 -} - -func isSortedBy10(a, b int) int { - if a-b < 0 { - return -10 - } - if a-b > 0 { - return 10 - } - return 0 -} - -func isSortedByDiff(a, b int) int { - return a - b -} - -func main() { - functions := []func(int, int) int{isSortedByDiff, isSortedBy1, isSortedBy10} - - type node struct { - f func(int, int) int - a []int - } - - table := []node{} - - // 5 unordered slices - for i := 0; i < 5; i++ { - function := functions[lib.RandIntBetween(0, len(functions)-1)] - val := node{ - f: function, - a: lib.MultRandIntBetween(-1000000, 1000000), - } - table = append(table, val) - } - - // 5 slices ordered in ascending order - for i := 0; i < 5; i++ { - function := functions[lib.RandIntBetween(0, len(functions)-1)] - ordered := lib.MultRandIntBetween(-1000000, 1000000) - sort.Ints(ordered) - - val := node{ - f: function, - a: ordered, - } - table = append(table, val) - } - - // 5 slices ordered in descending order - for i := 0; i < 5; i++ { - function := functions[lib.RandIntBetween(0, len(functions)-1)] - reversed := lib.MultRandIntBetween(-1000000, 1000000) - sort.Sort(sort.Reverse(sort.IntSlice(reversed))) - val := node{ - f: function, - a: reversed, - } - table = append(table, val) - } - - table = append(table, node{ - f: isSortedByDiff, - a: []int{1, 2, 3, 4, 5, 6}, - }) - - table = append(table, node{ - f: isSortedByDiff, - a: []int{6, 5, 4, 3, 2, 1}, - }) - - table = append(table, node{ - f: isSortedByDiff, - a: []int{0, 0, 0, 0, 0, 0, 0}, - }) - - table = append(table, node{ - f: isSortedByDiff, - a: []int{0}, - }) - - for _, arg := range table { - lib.Challenge("IsSorted", student.IsSorted, isSorted, arg.f, arg.a) - } -} diff --git a/test-go/tests/isupper_test/main.go b/test-go/tests/isupper_test/main.go deleted file mode 100644 index cf0380c6a..000000000 --- a/test-go/tests/isupper_test/main.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/is" -) - -func main() { - // 15 unvalid strings in the table - table := lib.MultRandASCII() - - // 15 valid lowercase strings of random size between 1 and 20 letters in the table - for i := 0; i < 15; i++ { - size := lib.RandIntBetween(1, 20) - randLow := lib.RandLower() - if len(randLow) <= size { - table = append(table, randLow) - } else { - table = append(table, randLow[:size]) - } - } - - // Special cases added to table - table = append(table, - "Hello! How are you?", - "a", - "z", - "!", - "HelloHowareyou", - "What's this 4?", - "Whatsthis4", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!", - "0123456789", - "01,02,03", - "abcdefghijklmnopqrstuvwxyz", - "hello", - "hello!", - "HELLO", - "HELLO!", - ) - for _, arg := range table { - lib.Challenge("IsUpper", student.IsUpper, is.Upper, arg) - } -} diff --git a/test-go/tests/iterativefactorial_test/main.go b/test-go/tests/iterativefactorial_test/main.go deleted file mode 100644 index 4e0af7384..000000000 --- a/test-go/tests/iterativefactorial_test/main.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import ( - "math/bits" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func iterativeFactorial(nb int) int { - limit := 20 - if nb < 0 || nb > limit { - return 0 - } - if nb == 0 { - return 1 - } - return nb * iterativeFactorial(nb-1) -} - -func main() { - if bits.UintSize != 64 { - panic("only works on 64 bits CPU") - } - table := append( - lib.MultRandInt(), - lib.IntRange(0, 20)..., - ) - for _, arg := range table { - lib.Challenge("IterativeFactorial", student.IterativeFactorial, iterativeFactorial, arg) - } -} diff --git a/test-go/tests/iterativepower_test/main.go b/test-go/tests/iterativepower_test/main.go deleted file mode 100644 index 168c16e1b..000000000 --- a/test-go/tests/iterativepower_test/main.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "math" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func iterativePower(nb int, power int) int { - if power < 0 { - return 0 - } - result := math.Pow(float64(nb), float64(power)) - return int(result) -} - -func main() { - i := 0 - for i < 30 { - nb := lib.RandIntBetween(-8, 8) - power := lib.RandIntBetween(-10, 10) - lib.Challenge("IterativePower", student.IterativePower, iterativePower, nb, power) - i++ - } - lib.Challenge("IterativePower", student.IterativePower, iterativePower, 0, 0) - lib.Challenge("IterativePower", student.IterativePower, iterativePower, 0, 1) -} diff --git a/test-go/tests/itoa_test/main.go b/test-go/tests/itoa_test/main.go deleted file mode 100644 index 365fe1385..000000000 --- a/test-go/tests/itoa_test/main.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - for i := 0; i < 50; i++ { - lib.Challenge("Itoa", student.Itoa, strconv.Itoa, lib.RandInt()) - } -} diff --git a/test-go/tests/itoabase_test/main.go b/test-go/tests/itoabase_test/main.go deleted file mode 100644 index 592dc4615..000000000 --- a/test-go/tests/itoabase_test/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "strconv" - "strings" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func itoaBase(value, base int) string { - if base < 2 || base > 16 { - return "" - } - - return strings.ToUpper(strconv.FormatInt(int64(value), base)) -} - -func main() { - for i := 0; i < 30; i++ { - value := lib.RandIntBetween(-1000000, 1000000) - base := lib.RandIntBetween(2, 16) - lib.Challenge("ItoaBase", student.ItoaBase, itoaBase, value, base) - } - for i := 0; i < 5; i++ { - base := lib.RandIntBetween(2, 16) - lib.Challenge("ItoaBase", student.ItoaBase, itoaBase, lib.MaxInt, base) - lib.Challenge("ItoaBase", student.ItoaBase, itoaBase, lib.MinInt, base) - } -} diff --git a/test-go/tests/join_test/main.go b/test-go/tests/join_test/main.go deleted file mode 100644 index 69c63e2de..000000000 --- a/test-go/tests/join_test/main.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "strings" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func join(elems []string, sep string) string { - return strings.Join(elems, sep) -} - -func main() { - seps := []string{" ", "-", " ,", "_", "SPC", " . "} - - args := [][]string{ - {"hello", "how", "are", "you", "doing"}, - {"fine", "and", "you"}, - {"I'm", "O.K."}, - } - - for i := 0; i < 5; i++ { - // random position for the slice of arguments - posA := lib.RandIntBetween(0, len(args)-1) - // random position for the slice of separators - posS := lib.RandIntBetween(0, len(seps)-1) - - lib.Challenge("Join", student.Join, join, args[posA], seps[posS]) - } -} diff --git a/test-go/tests/lastrune_test/main.go b/test-go/tests/lastrune_test/main.go deleted file mode 100644 index f4c4bc990..000000000 --- a/test-go/tests/lastrune_test/main.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func lastRune(s string) rune { - runes := []rune(s) - index := len(runes) - 1 - return runes[index] -} - -func main() { - table := lib.MultRandASCII() - table = append(table, - "Hello!", - "Salut!", - "Ola!", - lib.RandStr(lib.RandIntBetween(1, 15), lib.RandAlnum()), - ) - for _, arg := range table { - lib.Challenge("LastRune", student.LastRune, lastRune, arg) - } -} diff --git a/test-go/tests/lastword_test/main.go b/test-go/tests/lastword_test/main.go deleted file mode 100644 index 6f5c63083..000000000 --- a/test-go/tests/lastword_test/main.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := []string{ - "FOR PONY", - "this ... is sparta, then again, maybe not", - " ", - " lorem,ipsum ", - } - - args = append(args, lib.MultRandWords()...) - - for _, v := range args { - lib.ChallengeMain("lastword", v) - } - - lib.ChallengeMain("lastword", "a", "b") - lib.ChallengeMain("lastword") -} diff --git a/test-go/tests/lcm_test/main.go b/test-go/tests/lcm_test/main.go deleted file mode 100644 index 1967d8f23..000000000 --- a/test-go/tests/lcm_test/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func gcd(first, second int) int { - if second == 0 { - return first - } - return gcd(second, first%second) -} - -func lcm(first, second int) int { - return first / gcd(second, first%second) * second -} - -func main() { - table := [][2]int{ - {50, 43}, - {13, 13}, - {10, 9}, - {0, 9}, - {1, 1}, - } - - for i := 0; i < 15; i++ { - table = append(table, [2]int{ - lib.RandIntBetween(0, 1000), - lib.RandIntBetween(0, 1000), - }) - } - - for _, arg := range table { - lib.Challenge("Lcm", student.Lcm, lcm, arg[0], arg[1]) - } -} diff --git a/test-go/tests/listat_test/main.go b/test-go/tests/listat_test/main.go deleted file mode 100644 index deffbc00f..000000000 --- a/test-go/tests/listat_test/main.go +++ /dev/null @@ -1,98 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - Node5 = student.NodeL - NodeS5 = solutions.NodeL -) - -func nodePushBackList5(l1 *Node5, l2 *NodeS5, data interface{}) (*Node5, *NodeS5) { - n1 := &Node5{Data: data} - n2 := &NodeS5{Data: data} - - if l1 == nil { - l1 = n1 - } else { - iterator := l1 - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n1 - } - if l2 == nil { - l2 = n2 - } else { - iterator1 := l2 - for iterator1.Next != nil { - iterator1 = iterator1.Next - } - iterator1.Next = n2 - } - return l1, l2 -} - -// compare functions that consist on inserting using the structure node -func comparFuncNode5(solutionList *NodeS5, l1 *Node5, l2 *NodeS5, arg int) { - if l1 == nil && l2 == nil { - return - } - if l1 != nil && l2 == nil { - lib.Fatalf("\nListAt(%s, %d) == %v instead of %v\n\n", - solutions.ListToString(solutionList), arg, l1, l2) - } - if l1.Data != l2.Data { - lib.Fatalf("\nListAt(%s, %d) == %v instead of %v\n\n", - solutions.ListToString(solutionList), arg, l1.Data, l2.Data) - } -} - -// finds an element of a solutions.ListS using a given position -func main() { - var link1 *Node5 - var link2 *NodeS5 - - type nodeTest struct { - data []interface{} - pos int - } - - var table []nodeTest - - for i := 0; i < 4; i++ { - table = append(table, nodeTest{ - data: solutions.ConvertIntToInterface(lib.MultRandInt()), - pos: lib.RandIntBetween(1, 12), - }) - } - - for i := 0; i < 4; i++ { - table = append(table, nodeTest{ - data: solutions.ConvertIntToStringface(lib.MultRandWords()), - pos: lib.RandIntBetween(1, 12), - }) - } - - table = append(table, nodeTest{ - data: []interface{}{"I", 1, "something", 2}, - pos: lib.RandIntBetween(1, 4), - }) - - for _, arg := range table { - for i := 0; i < len(arg.data); i++ { - link1, link2 = nodePushBackList5(link1, link2, arg.data[i]) - } - - result1 := student.ListAt(link1, arg.pos) - result2 := solutions.ListAt(link2, arg.pos) - - comparFuncNode5(link2, result1, result2, arg.pos) - link1 = nil - link2 = nil - } -} diff --git a/test-go/tests/listclear_test/main.go b/test-go/tests/listclear_test/main.go deleted file mode 100644 index e82114668..000000000 --- a/test-go/tests/listclear_test/main.go +++ /dev/null @@ -1,85 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - Node4 = student.NodeL - List4 = solutions.List - NodeS4 = solutions.NodeL - ListS4 = student.List -) - -func listToStringStu5(l *ListS4) string { - var res string - it := l.Head - for it != nil { - switch it.Data.(type) { - case int: - res += strconv.Itoa(it.Data.(int)) + "-> " - case string: - res += it.Data.(string) + "-> " - } - it = it.Next - } - res += "" - return res -} - -func listPushBackTest4(l1 *ListS4, l2 *List4, data interface{}) { - n := &Node4{Data: data} - n1 := &NodeS4{Data: data} - if l1.Head == nil { - l1.Head = n - } else { - iterator := l1.Head - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n - } - if l2.Head == nil { - l2.Head = n1 - } else { - iterator1 := l2.Head - for iterator1.Next != nil { - iterator1 = iterator1.Next - } - iterator1.Next = n1 - } -} - -// simply cleans the linked solutions.ListS -func main() { - link1 := &List4{} - link2 := &ListS4{} - - table := []solutions.NodeTest{} - - table = solutions.ElementsToTest(table) - - table = append(table, - solutions.NodeTest{ - Data: []interface{}{"I", 1, "something", 2}, - }, - ) - - for _, arg := range table { - for i := 0; i < len(arg.Data); i++ { - listPushBackTest4(link2, link1, arg.Data[i]) - } - solutions.ListClear(link1) - student.ListClear(link2) - - if link2.Head != nil { - lib.Fatalf("\nstudent list:%s\nlist:%s\n\nListClear() == %v instead of %v\n\n", - listToStringStu5(link2), solutions.ListToString(link1.Head), link2.Head, link1.Head) - } - } -} diff --git a/test-go/tests/listfind_test/main.go b/test-go/tests/listfind_test/main.go deleted file mode 100644 index dd0eb1c82..000000000 --- a/test-go/tests/listfind_test/main.go +++ /dev/null @@ -1,81 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - Node9 = student.NodeL - List9 = solutions.List - NodeS9 = solutions.NodeL - ListS9 = student.List -) - -func listPushBackTest9(l1 *ListS9, l2 *List9, data interface{}) { - n := &Node9{Data: data} - n1 := &NodeS9{Data: data} - if l1.Head == nil { - l1.Head = n - } else { - iterator := l1.Head - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n - } - if l2.Head == nil { - l2.Head = n1 - } else { - iterator1 := l2.Head - for iterator1.Next != nil { - iterator1 = iterator1.Next - } - iterator1.Next = n1 - } -} - -func main() { - link1 := &List9{} - link2 := &ListS9{} - - table := []solutions.NodeTest{} - table = solutions.ElementsToTest(table) - table = append(table, - solutions.NodeTest{ - Data: []interface{}{"hello", "hello1", "hello2", "hello3"}, - }, - ) - - for _, arg := range table { - for i := 0; i < len(arg.Data); i++ { - listPushBackTest9(link2, link1, arg.Data[i]) - } - if len(arg.Data) != 0 { - aux1 := student.ListFind(link2, arg.Data[(len(arg.Data)-1)/2], student.CompStr) - aux2 := solutions.ListFind(link1, arg.Data[(len(arg.Data)-1)/2], solutions.CompStr) - - if aux1 != nil || aux2 != nil { - if *aux1 != *aux2 { - lib.Fatalf("ListFind(ref: %s) == %s instead of %s\n", arg.Data[(len(arg.Data)-1)/2], *aux1, *aux2) - } - } - } - link1 = &List9{} - link2 = &ListS9{} - } - - for i := 0; i < len(table[0].Data); i++ { - listPushBackTest9(link2, link1, table[0].Data[i]) - } - - aux1 := student.ListFind(link2, "lksdf", student.CompStr) - aux2 := solutions.ListFind(link1, "lksdf", solutions.CompStr) - if aux1 != nil && aux2 != nil { - if *aux1 != *aux2 { - lib.Fatalf("ListFind(ref: lksdf) == %s instead of %s\n", *aux1, *aux2) - } - } -} diff --git a/test-go/tests/listforeach_test/main.go b/test-go/tests/listforeach_test/main.go deleted file mode 100644 index 7f81348d4..000000000 --- a/test-go/tests/listforeach_test/main.go +++ /dev/null @@ -1,102 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - Node7 = student.NodeL - List7 = solutions.List - NodeS7 = solutions.NodeL - ListS7 = student.List -) - -func listToStringStu8(l *ListS7) string { - var res string - it := l.Head - for it != nil { - switch it.Data.(type) { - case int: - res += strconv.Itoa(it.Data.(int)) + "-> " - case string: - res += it.Data.(string) + "-> " - } - it = it.Next - } - res += "" - return res -} - -func listPushBackTest7(l1 *ListS7, l2 *List7, data interface{}) { - n := &Node7{Data: data} - n1 := &NodeS7{Data: data} - if l1.Head == nil { - l1.Head = n - } else { - iterator := l1.Head - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n - } - if l2.Head == nil { - l2.Head = n1 - } else { - iterator1 := l2.Head - for iterator1.Next != nil { - iterator1 = iterator1.Next - } - iterator1.Next = n1 - } -} - -func comparFuncList7(l1 *List7, l2 *ListS7, f func(*Node7)) { - funcName := solutions.GetName(f) - for l1.Head != nil || l2.Head != nil { - if (l1.Head == nil && l2.Head != nil) || (l1.Head != nil && l2.Head == nil) { - lib.Fatalf("\nstudent list: %s\nlist: %s\nfunction used: %s\n\nListForEach() == %v instead of %v\n\n", - listToStringStu8(l2), solutions.ListToString(l1.Head), funcName, l2.Head, l1.Head) - } - if l1.Head.Data != l2.Head.Data { - lib.Fatalf("\nstudent list: %s\nlist: %s\nfunction used: %s\n\nListForEach() == %v instead of %v\n\n", - listToStringStu8(l2), solutions.ListToString(l1.Head), funcName, l2.Head.Data, l1.Head.Data) - } - l1.Head = l1.Head.Next - l2.Head = l2.Head.Next - } -} - -// applies a function to the solutions.ListS -func main() { - link1 := &List7{} - link2 := &ListS7{} - table := []solutions.NodeTest{} - table = solutions.ElementsToTest(table) - table = append(table, - solutions.NodeTest{ - Data: []interface{}{"I", 1, "something", 2}, - }, - ) - for _, arg := range table { - for i := 0; i < len(arg.Data); i++ { - listPushBackTest7(link2, link1, arg.Data[i]) - } - student.ListForEach(link2, student.Add2_node) - solutions.ListForEach(link1, solutions.Add2_node) - - comparFuncList7(link1, link2, student.Add2_node) - - student.ListForEach(link2, student.Subtract3_node) - solutions.ListForEach(link1, solutions.Subtract3_node) - - comparFuncList7(link1, link2, student.Subtract3_node) - - link1 = &List7{} - link2 = &ListS7{} - } -} diff --git a/test-go/tests/listforeachif_test/main.go b/test-go/tests/listforeachif_test/main.go deleted file mode 100644 index 2a7fd8ecf..000000000 --- a/test-go/tests/listforeachif_test/main.go +++ /dev/null @@ -1,149 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - Node8 = student.NodeL - List8 = solutions.List - NodeS8 = solutions.NodeL - ListS8 = student.List -) - -// function to apply, in listforeachif -func addOneS(node *NodeS8) { - data := node.Data.(int) - data++ - node.Data = interface{}(data) -} - -// function to apply, in listforeachif -func addOne(node *Node8) { - data := node.Data.(int) - data++ - node.Data = interface{}(data) -} - -func subtract1_sol(node *NodeS8) { - data := node.Data.(int) - data-- - node.Data = interface{}(data) -} - -func subtractOne(node *Node8) { - data := node.Data.(int) - data-- - node.Data = interface{}(data) -} - -func listToStringStu7(l *ListS8) string { - var res string - it := l.Head - for it != nil { - switch it.Data.(type) { - case int: - res += strconv.Itoa(it.Data.(int)) + "-> " - case string: - res += it.Data.(string) + "-> " - } - it = it.Next - } - res += "" - return res -} - -func listPushBackTest8(l1 *ListS8, l2 *List8, data interface{}) { - n1 := &Node8{Data: data} - n2 := &NodeS8{Data: data} - - if l1.Head == nil { - l1.Head = n1 - } else { - iterator := l1.Head - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n1 - } - - if l2.Head == nil { - l2.Head = n2 - } else { - iterator1 := l2.Head - for iterator1.Next != nil { - iterator1 = iterator1.Next - } - iterator1.Next = n2 - } -} - -func comparFuncList8(l1 *List8, l2 *ListS8, f func(*Node8) bool, comp func(*Node8)) { - funcFName := solutions.GetName(f) - funcComp := solutions.GetName(comp) - for l1.Head != nil || l2.Head != nil { - if (l1.Head == nil && l2.Head != nil) || (l1.Head != nil && l2.Head == nil) { - lib.Fatalf("\nstudent list:%s\nlist:%s\nfunction f used: %s\nfunction comp: %s\n\nListForEachIf() == %v instead of %v\n\n", - listToStringStu7(l2), solutions.ListToString(l1.Head), funcComp, funcFName, l2.Head, l1.Head) - } - if l1.Head.Data != l2.Head.Data { - lib.Fatalf("\nstudent list:%s\nlist:%s\nfunction f used: %s\nfunction comp: %s\n\nListForEachIf() == %v instead of %v\n\n", - listToStringStu7(l2), solutions.ListToString(l1.Head), funcComp, funcFName, l2.Head.Data, l1.Head.Data) - } - l1.Head = l1.Head.Next - l2.Head = l2.Head.Next - } -} - -// applies a function to an element of the linked solutions.ListS -func main() { - link1 := &ListS8{} - link2 := &List8{} - - table := []solutions.NodeTest{} - table = append(table, - solutions.NodeTest{ - Data: []interface{}{}, - }, - ) - - // just numbers/ints - for i := 0; i < 3; i++ { - val := solutions.NodeTest{ - Data: solutions.ConvertIntToInterface(lib.MultRandInt()), - } - table = append(table, val) - } - // just strings - for i := 0; i < 3; i++ { - val := solutions.NodeTest{ - Data: solutions.ConvertIntToStringface(lib.MultRandWords()), - } - table = append(table, val) - } - table = append(table, - solutions.NodeTest{ - Data: []interface{}{"I", 1, "something", 2}, - }, - ) - for _, arg := range table { - for i := 0; i < len(arg.Data); i++ { - listPushBackTest8(link1, link2, arg.Data[i]) - } - solutions.ListForEachIf(link2, addOneS, solutions.IsPositive_node) - student.ListForEachIf(link1, addOne, student.IsPositive_node) - comparFuncList8(link2, link1, student.IsPositive_node, addOne) - - solutions.ListForEachIf(link2, subtract1_sol, solutions.IsPositive_node) - student.ListForEachIf(link1, subtractOne, student.IsPositive_node) - comparFuncList8(link2, link1, student.IsPositive_node, subtractOne) - - link1 = &ListS8{} - link2 = &List8{} - } -} diff --git a/test-go/tests/listlast_test/main.go b/test-go/tests/listlast_test/main.go deleted file mode 100644 index 268d2ab52..000000000 --- a/test-go/tests/listlast_test/main.go +++ /dev/null @@ -1,81 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - Node3 = student.NodeL - List3 = solutions.List - NodeS3 = solutions.NodeL - ListS3 = student.List -) - -func listToStringStu9(l *ListS3) string { - var res string - it := l.Head - for it != nil { - switch it.Data.(type) { - case int: - res += strconv.Itoa(it.Data.(int)) + "-> " - case string: - res += it.Data.(string) + "-> " - } - it = it.Next - } - res += "" - return res -} - -// inserts node on two lists -func listPushBackTest3(l *ListS3, l1 *List3, data interface{}) { - n := &Node3{Data: data} - n1 := &NodeS3{Data: data} - if l.Head == nil { - l.Head = n - l.Tail = n - } else { - l.Tail.Next = n - l.Tail = n - } - if l1.Head == nil { - l1.Head = n1 - l1.Tail = n1 - } else { - l1.Tail.Next = n1 - l1.Tail = n1 - } -} - -// last element of the solutions.ListS -func main() { - link1 := &List3{} - link2 := &ListS3{} - table := []solutions.NodeTest{} - - table = solutions.ElementsToTest(table) - table = append(table, - solutions.NodeTest{ - Data: []interface{}{3, 2, 1}, - }, - ) - for _, arg := range table { - for i := 0; i < len(arg.Data); i++ { - listPushBackTest3(link2, link1, arg.Data[i]) - } - aux1 := solutions.ListLast(link1) - aux2 := student.ListLast(link2) - - if aux1 != aux2 { - lib.Fatalf("\nlist:%s\n\nListLast() == %v instead of %v\n\n", - listToStringStu9(link2), aux2, aux1) - } - link1 = &List3{} - link2 = &ListS3{} - } -} diff --git a/test-go/tests/listmerge_test/main.go b/test-go/tests/listmerge_test/main.go deleted file mode 100644 index f6360ac67..000000000 --- a/test-go/tests/listmerge_test/main.go +++ /dev/null @@ -1,138 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - Node11 = student.NodeL - List11 = solutions.List - NodeS11 = solutions.NodeL - ListS11 = student.List -) - -func listToStringStu(l *ListS11) string { - var res string - it := l.Head - for it != nil { - switch it.Data.(type) { - case int: - res += strconv.Itoa(it.Data.(int)) + "->" - case string: - res += it.Data.(string) + "->" - } - it = it.Next - } - res += "" - return res -} - -func listPushBackTest11(l1 *ListS11, l2 *List11, data interface{}) { - n1 := &Node11{Data: data} - n2 := &NodeS11{Data: data} - - if l1.Head == nil { - l1.Head = n1 - } else { - iterator := l1.Head - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n1 - } - l1.Tail = n1 - - if l2.Head == nil { - l2.Head = n2 - } else { - iterator1 := l2.Head - for iterator1.Next != nil { - iterator1 = iterator1.Next - } - iterator1.Next = n2 - } - l2.Tail = n2 -} - -func comparFuncList11(l1 *List11, l2 *ListS11) { - for l1.Head != nil || l2.Head != nil { - if (l1.Head == nil && l2.Head != nil) || (l1.Head != nil && l2.Head == nil) { - lib.Fatalf("\nstudent list:%s\nlist:%s\n\nListMerge() == %v instead of %v\n\n", - listToStringStu(l2), solutions.ListToString(l1.Head), l2.Head, l1.Head) - } - if l1.Head.Data != l2.Head.Data { - lib.Fatalf("\nstudent list:%s\nlist:%s\n\nListMerge() == %v instead of %v\n\n", - listToStringStu(l2), solutions.ListToString(l1.Head), l2.Head.Data, l1.Head.Data) - } - l1.Head = l1.Head.Next - l2.Head = l2.Head.Next - } -} - -func main() { - link1 := &List11{} - linkTest := &List11{} - link2 := &ListS11{} - link2Test := &ListS11{} - - type nodeTest struct { - data1 []interface{} - data2 []interface{} - } - table := []nodeTest{} - // empty list - table = append(table, - nodeTest{ - data1: []interface{}{}, - data2: []interface{}{}, - }) - table = append(table, - nodeTest{ - data1: solutions.ConvertIntToInterface(lib.MultRandInt()), - data2: []interface{}{}, - }) - // jut ints - for i := 0; i < 3; i++ { - val := nodeTest{ - data1: solutions.ConvertIntToInterface(lib.MultRandInt()), - data2: solutions.ConvertIntToInterface(lib.MultRandInt()), - } - table = append(table, val) - } - // just strings - for i := 0; i < 2; i++ { - val := nodeTest{ - data1: solutions.ConvertIntToStringface(lib.MultRandWords()), - data2: solutions.ConvertIntToStringface(lib.MultRandWords()), - } - table = append(table, val) - } - table = append(table, - nodeTest{ - data1: []interface{}{}, - data2: []interface{}{"a", 1}, - }, - ) - for _, arg := range table { - for i := 0; i < len(arg.data1); i++ { - listPushBackTest11(link2, link1, arg.data1[i]) - } - for i := 0; i < len(arg.data2); i++ { - listPushBackTest11(link2Test, linkTest, arg.data2[i]) - } - - solutions.ListMerge(link1, linkTest) - student.ListMerge(link2, link2Test) - comparFuncList11(link1, link2) - - link1 = &List11{} - linkTest = &List11{} - link2 = &ListS11{} - link2Test = &ListS11{} - } -} diff --git a/test-go/tests/listpushback_test/main.go b/test-go/tests/listpushback_test/main.go deleted file mode 100644 index 511c6f67f..000000000 --- a/test-go/tests/listpushback_test/main.go +++ /dev/null @@ -1,67 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - ListS = solutions.List - List = student.List -) - -func listToStringStu10(l *List) string { - var res string - it := l.Head - for it != nil { - switch it.Data.(type) { - case int: - res += strconv.Itoa(it.Data.(int)) + "-> " - case string: - res += it.Data.(string) + "-> " - } - it = it.Next - } - res += "" - return res -} - -// makes the test, compares 2 lists one from the solutions and the other from the student -func comparFuncList(l *ListS, l1 *List, data []interface{}) { - for l.Head != nil || l1.Head != nil { - if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) { - lib.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushBack()== %v instead of %v\n\n", - data, listToStringStu10(l1), solutions.ListToString(l.Head), l1.Head, l.Head) - } - if l.Head.Data != l1.Head.Data { - lib.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushBack()== %v instead of %v\n\n", - data, listToStringStu10(l1), solutions.ListToString(l.Head), l1.Head.Data, l.Head.Data) - } - l.Head = l.Head.Next - l1.Head = l1.Head.Next - } -} - -func main() { - link1 := &ListS{} - link2 := &List{} - - table := []solutions.NodeTest{} - table = solutions.ElementsToTest(table) - table = append(table, - solutions.NodeTest{ - Data: []interface{}{"Hello", "man", "how are you"}, - }, - ) - for _, arg := range table { - for _, item := range arg.Data { - student.ListPushBack(link2, item) - solutions.ListPushBack(link1, item) - } - comparFuncList(link1, link2, arg.Data) - } -} diff --git a/test-go/tests/listpushfront_test/main.go b/test-go/tests/listpushfront_test/main.go deleted file mode 100644 index c313ae511..000000000 --- a/test-go/tests/listpushfront_test/main.go +++ /dev/null @@ -1,69 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - ListSa = solutions.List - Lista = student.List -) - -func listToStringStu11(l *Lista) string { - var res string - it := l.Head - for it != nil { - switch it.Data.(type) { - case int: - res += strconv.Itoa(it.Data.(int)) + "-> " - case string: - res += it.Data.(string) + "-> " - } - it = it.Next - } - res += "" - return res -} - -// makes the test, compares 2 lists one from the solutions and the other from the student -func comparFuncList1(l *Lista, l1 *ListSa, data []interface{}) { - for l.Head != nil || l1.Head != nil { - if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) { - lib.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushFront()== %v instead of %v\n\n", - data, listToStringStu11(l), solutions.ListToString(l1.Head), l.Head, l1.Head) - } - if l.Head.Data != l1.Head.Data { - lib.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushFront()== %v instead of %v\n\n", - data, listToStringStu11(l), solutions.ListToString(l1.Head), l.Head, l1.Head) - } - l1.Head = l1.Head.Next - l.Head = l.Head.Next - } -} - -// to insert a value in the first position of the list -func main() { - link1 := &Lista{} - link2 := &ListSa{} - table := []solutions.NodeTest{} - table = solutions.ElementsToTest(table) - table = append(table, - solutions.NodeTest{ - Data: []interface{}{"Hello", "man", "how are you"}, - }, - ) - for _, arg := range table { - for _, item := range arg.Data { - student.ListPushFront(link1, item) - solutions.ListPushFront(link2, item) - } - comparFuncList1(link1, link2, arg.Data) - link1 = &Lista{} - link2 = &ListSa{} - } -} diff --git a/test-go/tests/listremoveif_test/main.go b/test-go/tests/listremoveif_test/main.go deleted file mode 100644 index 3ead1dd5e..000000000 --- a/test-go/tests/listremoveif_test/main.go +++ /dev/null @@ -1,109 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - Node10 = student.NodeL - List10 = solutions.List - NodeS10 = solutions.NodeL - ListS10 = student.List -) - -func listToStringStu12(l *ListS10) string { - var res string - it := l.Head - for it != nil { - switch it.Data.(type) { - case int: - res += strconv.Itoa(it.Data.(int)) + "-> " - case string: - res += it.Data.(string) + "-> " - } - it = it.Next - } - res += "" - return res -} - -func listPushBackTest10(l *ListS10, l1 *List10, data interface{}) { - n := &Node10{Data: data} - n1 := &NodeS10{Data: data} - if l.Head == nil { - l.Head = n - } else { - iterator := l.Head - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n - } - if l1.Head == nil { - l1.Head = n1 - } else { - iterator1 := l1.Head - for iterator1.Next != nil { - iterator1 = iterator1.Next - } - iterator1.Next = n1 - } -} - -func comparFuncList10(l *List10, l1 *ListS10, data interface{}) { - for l.Head != nil || l1.Head != nil { - if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) { - lib.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n", - data, listToStringStu12(l1), solutions.ListToString(l.Head), l1.Head, l.Head) - } - if l.Head.Data != l1.Head.Data { - lib.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n", - data, listToStringStu12(l1), solutions.ListToString(l.Head), l1.Head.Data, l.Head.Data) - } - l.Head = l.Head.Next - l1.Head = l1.Head.Next - } -} - -// removes all the elements that are equal to a value -func main() { - link1 := &List10{} - link2 := &ListS10{} - var index int - table := []solutions.NodeTest{} - - table = solutions.ElementsToTest(table) - - table = append(table, - solutions.NodeTest{ - Data: []interface{}{"hello", "hello1", "hello2", "hello3"}, - }, - ) - - for _, arg := range table { - for i := 0; i < len(arg.Data); i++ { - listPushBackTest10(link2, link1, arg.Data[i]) - } - aux := len(arg.Data) - 1 - - index = lib.RandIntBetween(0, aux) - if link1.Head != nil && link2.Head != nil { - cho := arg.Data[index] - student.ListRemoveIf(link2, cho) - solutions.ListRemoveIf(link1, cho) - comparFuncList10(link1, link2, cho) - } else { - student.ListRemoveIf(link2, 1) - solutions.ListRemoveIf(link1, 1) - comparFuncList10(link1, link2, 1) - } - - link1 = &List10{} - link2 = &ListS10{} - } -} diff --git a/test-go/tests/listreverse_test/main.go b/test-go/tests/listreverse_test/main.go deleted file mode 100644 index 72e7a6da8..000000000 --- a/test-go/tests/listreverse_test/main.go +++ /dev/null @@ -1,90 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - Node6 = student.NodeL - List6 = solutions.List - NodeS6 = solutions.NodeL - ListS6 = student.List -) - -func listToStringStu13(l *ListS6) string { - var res string - it := l.Head - for it != nil { - switch it.Data.(type) { - case int: - res += strconv.Itoa(it.Data.(int)) + "-> " - case string: - res += it.Data.(string) + "-> " - } - it = it.Next - } - res += "" - return res -} - -func comparFuncList6(l *List6, l1 *ListS6) { - for l.Head != nil || l1.Head != nil { - if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) { - lib.Fatalf("\nstudent list:%s\nlist:%s\n\nListReverse() == %v instead of %v\n\n", - listToStringStu13(l1), solutions.ListToString(l.Head), l1.Head, l.Head) - } - if l.Head.Data != l1.Head.Data { - lib.Fatalf("\nstudent list:%s\nlist:%s\n\nListReverse() == %v instead of %v\n\n", - listToStringStu13(l1), solutions.ListToString(l.Head), l1.Head.Data, l.Head.Data) - } - l.Head = l.Head.Next - l1.Head = l1.Head.Next - } -} - -func listPushBackTest6(l *ListS6, l1 *List6, data interface{}) { - n := &Node6{Data: data} - n1 := &NodeS6{Data: data} - if l.Head == nil { - l.Head = n - } else { - iterator := l.Head - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n - } - if l1.Head == nil { - l1.Head = n1 - } else { - iterator1 := l1.Head - for iterator1.Next != nil { - iterator1 = iterator1.Next - } - iterator1.Next = n1 - } -} - -func main() { - link1 := &List6{} - link2 := &ListS6{} - table := []solutions.NodeTest{{ - Data: []interface{}{"I", 1, "something", 2}, - }} - table = solutions.ElementsToTest(table) - for _, arg := range table { - for _, item := range arg.Data { - listPushBackTest6(link2, link1, item) - } - student.ListReverse(link2) - solutions.ListReverse(link1) - comparFuncList6(link1, link2) - link1 = &List6{} - link2 = &ListS6{} - } -} diff --git a/test-go/tests/listsize_test/main.go b/test-go/tests/listsize_test/main.go deleted file mode 100644 index 0bf855148..000000000 --- a/test-go/tests/listsize_test/main.go +++ /dev/null @@ -1,63 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - Node2 = student.NodeL - List2 = solutions.List - NodeS2 = solutions.NodeL - ListS2 = student.List -) - -func listPushBackTest2(l *ListS2, l1 *List2, data interface{}) { - n := &Node2{Data: data} - n1 := &NodeS2{Data: data} - if l.Head == nil { - l.Head = n - } else { - iterator := l.Head - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n - } - - if l1.Head == nil { - l1.Head = n1 - } else { - iterator1 := l1.Head - for iterator1.Next != nil { - iterator1 = iterator1.Next - } - iterator1.Next = n1 - } -} - -func main() { - link := &List2{} - link2 := &ListS2{} - table := []solutions.NodeTest{} - table = solutions.ElementsToTest(table) - table = append(table, - solutions.NodeTest{ - Data: []interface{}{"Hello", "man", "how are you"}, - }, - ) - for _, arg := range table { - for i := 0; i < len(arg.Data); i++ { - listPushBackTest2(link2, link, arg.Data[i]) - } - aux := solutions.ListSize(link) - aux2 := student.ListSize(link2) - if aux != aux2 { - lib.Fatalf("ListSize(%v) == %d instead of %d\n", solutions.ListToString(link.Head), aux2, aux) - } - link = &List2{} - link2 = &ListS2{} - } -} diff --git a/test-go/tests/listsort_test/main.go b/test-go/tests/listsort_test/main.go deleted file mode 100644 index 0e477245a..000000000 --- a/test-go/tests/listsort_test/main.go +++ /dev/null @@ -1,96 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - NodeI12 = student.NodeI - NodeIS12 = solutions.NodeI -) - -func printListStudent(n *NodeI12) string { - var res string - it := n - for it != nil { - res += strconv.Itoa(it.Data) + "-> " - it = it.Next - } - res += "" - return res -} - -func nodePushBackListInt12(l1 *NodeI12, l2 *NodeIS12, data int) { - n1 := &NodeI12{Data: data} - n2 := &NodeIS12{Data: data} - - if l1 == nil { - l1 = n1 - } else { - iterator1 := l1 - for iterator1.Next != nil { - iterator1 = iterator1.Next - } - iterator1.Next = n1 - } - - if l2 == nil { - l2 = n2 - } else { - iterator2 := l2 - for iterator2.Next != nil { - iterator2 = iterator2.Next - } - iterator2.Next = n2 - } -} - -func comparFuncNodeInt12(l1 *NodeI12, l2 *NodeIS12) { - for l1 != nil || l2 != nil { - if (l1 == nil && l2 != nil) || (l1 != nil && l2 == nil) { - lib.Fatalf("\nstudent list:%s\nlist:%s\n\nListSort() == %v instead of %v\n\n", - printListStudent(l1), solutions.PrintList(l2), l1, l2) - } - if l1.Data != l2.Data { - lib.Fatalf("\nstudent list:%s\nlist:%s\n\nListSort() == %v instead of %v\n\n", - printListStudent(l1), solutions.PrintList(l2), l1.Data, l2.Data) - } - l1 = l1.Next - l2 = l2.Next - } -} - -func main() { - var link1 *NodeI12 - var link2 *NodeIS12 - - type nodeTest struct { - data []int - } - table := []nodeTest{} - table = append(table, nodeTest{[]int{}}) - - // just numbers/ints - for i := 0; i < 2; i++ { - table = append(table, nodeTest{lib.MultRandInt()}) - } - table = append(table, nodeTest{[]int{5, 4, 3, 2, 1}}) - - for _, arg := range table { - for i := 0; i < len(arg.data); i++ { - nodePushBackListInt12(link1, link2, arg.data[i]) - } - aux1 := solutions.ListSort(link2) - aux2 := student.ListSort(link1) - - comparFuncNodeInt12(aux2, aux1) - - link1 = &NodeI12{} - link2 = &NodeIS12{} - } -} diff --git a/test-go/tests/makerange_test/main.go b/test-go/tests/makerange_test/main.go deleted file mode 100644 index e0a2da136..000000000 --- a/test-go/tests/makerange_test/main.go +++ /dev/null @@ -1,61 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func makeRange(min, max int) []int { - size := max - min - - if size <= 0 { - return nil - } - answer := make([]int, size) - for i := range answer { - answer[i] = min - min++ - } - return answer -} - -func main() { - type node struct { - min int - max int - } - - table := []node{} - - // 15 random pairs of ints for a Valid Range - for i := 0; i < 15; i++ { - minVal := lib.RandIntBetween(-10000000, 1000000) - gap := lib.RandIntBetween(1, 20) - val := node{ - min: minVal, - max: minVal + gap, - } - table = append(table, val) - } - // 15 random pairs of ints with ||invalid range|| - for i := 0; i < 15; i++ { - minVal := lib.RandIntBetween(-10000000, 1000000) - gap := lib.RandIntBetween(1, 20) - val := node{ - min: minVal, - max: minVal - gap, - } - table = append(table, val) - } - - table = append(table, - node{min: 0, max: 1}, - node{min: 0, max: 0}, - node{min: 5, max: 10}, - node{min: 10, max: 5}, - ) - for _, arg := range table { - lib.Challenge("MakeRange", student.MakeRange, makeRange, arg.min, arg.max) - } -} diff --git a/test-go/tests/map_test/main.go b/test-go/tests/map_test/main.go deleted file mode 100644 index 06e3b49e4..000000000 --- a/test-go/tests/map_test/main.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/is" -) - -func isPositive(i int) bool { - return i > 0 -} - -func isNegative(i int) bool { - return i < 0 -} - -func _map(f func(int) bool, a []int) []bool { - result := make([]bool, len(a)) - - for i, el := range a { - result[i] = f(el) - } - - return result -} - -func main() { - functions := []func(int) bool{isPositive, isNegative, is.Prime} - - type node struct { - f func(int) bool - a []int - } - - table := []node{} - - for i := 0; i < 15; i++ { - function := functions[lib.RandIntBetween(0, len(functions)-1)] - val := node{ - f: function, - a: lib.MultRandIntBetween(-1000000, 1000000), - } - table = append(table, val) - } - - table = append(table, node{ - f: is.Prime, - a: []int{1, 2, 3, 4, 5, 6}, - }) - - for _, arg := range table { - lib.Challenge("Map", student.Map, _map, arg.f, arg.a) - } -} diff --git a/test-go/tests/max_test/main.go b/test-go/tests/max_test/main.go deleted file mode 100644 index 030cc4789..000000000 --- a/test-go/tests/max_test/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "sort" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func max(a []int) int { - if len(a) == 0 { - return 0 - } - sort.Ints(a) - return a[len(a)-1] -} - -func main() { - args := []int{lib.RandInt()} - limit := lib.RandIntBetween(20, 50) - for i := 0; i < limit; i++ { - args = append(args, lib.RandInt()) - } - - lib.Challenge("Max", student.Max, max, args) -} diff --git a/test-go/tests/nauuo_test/main.go b/test-go/tests/nauuo_test/main.go deleted file mode 100644 index 03d880ae3..000000000 --- a/test-go/tests/nauuo_test/main.go +++ /dev/null @@ -1,59 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func nauuo(plus, minus, rand int) string { - if rand == 0 { - if plus > minus { - return "+" - } - if plus < minus { - return "-" - } - if plus == minus { - return "0" - } - } - if plus > minus+rand { - return "+" - } - if plus+rand < minus { - return "-" - } - if plus+rand >= minus && plus-rand <= minus { - return "?" - } - if minus+rand >= plus && minus-rand <= plus { - return "?" - } - return "?" -} - -func main() { - type node struct { - plus int - minus int - rand int - } - table := []node{ - {50, 43, 20}, - {13, 13, 0}, - {10, 9, 0}, - {5, 9, 2}, - } - - for i := 0; i < 15; i++ { - table = append(table, node{ - plus: lib.RandIntBetween(0, 10), - minus: lib.RandIntBetween(0, 10), - rand: lib.RandIntBetween(0, 10), - }) - } - for _, arg := range table { - lib.Challenge("Nauuo", student.Nauuo, nauuo, arg.plus, arg.minus, arg.rand) - } -} diff --git a/test-go/tests/nbrconvertalpha_test/main.go b/test-go/tests/nbrconvertalpha_test/main.go deleted file mode 100644 index 74e4badb0..000000000 --- a/test-go/tests/nbrconvertalpha_test/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "strconv" - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := []string{ - "--upper 8 5 25", - "8 5 12 12 15", - "12 5 7 5 14 56 4 1 18 25", - "12 5 7 5 14 56 4 1 18 25 32 86 h", - "32 86 h", - "", - } - for i := 0; i < 5; i++ { - m := lib.MultRandIntBetween(1, 46) - s := "" - for _, j := range m { - s += strconv.Itoa(j) + " " - } - table = append(table, s) - } - - for _, args := range table { - lib.ChallengeMain("nbrconvertalpha", strings.Fields(args)...) - } -} diff --git a/test-go/tests/nenokku_test/main.go b/test-go/tests/nenokku_test/main.go deleted file mode 100644 index 9cc907f03..000000000 --- a/test-go/tests/nenokku_test/main.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := [][]string{{ - "? love", - "? is", - "A loveis", - "? love", - "? Who", - "A Whoareyou", - "? is", - }} - - sets := [][]string{ - {"An", "array", "variable", "denotes", "the", "entire", "array"}, - {"This", "means", "that", "when", "you", "assign", "or", "pass"}, - {"To", "avoid", "the", "copy", "you", "could", "pass"}, - {"struct", "but", "with", "indexed", "rather", "than", "named", "fields"}, - } - ops := []string{ - "?", "x", "A", - } - - for i := 0; i < 6; i++ { - result := []string{} - nOps := lib.RandIntBetween(3, 15) - index := lib.RandIntBetween(0, len(sets)-1) - for j := 0; j < nOps; j++ { - k := lib.RandIntBetween(0, len(ops)-1) - s := lib.RandIntBetween(0, len(sets[index])-1) - result = append(result, ops[k]+" "+sets[index][s]) - } - table = append(table, result) - } - - for _, arg := range table { - lib.ChallengeMain("nenokku", arg...) - } -} diff --git a/test-go/tests/nrune_test/main.go b/test-go/tests/nrune_test/main.go deleted file mode 100644 index 06b616bee..000000000 --- a/test-go/tests/nrune_test/main.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "math/rand" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func nRune(s string, n int) rune { - if n > len(s) || n < 1 { - return 0 - } - runes := []rune(s) - return runes[n-1] -} - -func main() { - type node struct { - word string - n int - } - - table := []node{} - - for i := 0; i < 30; i++ { - wordToInput := lib.RandASCII() - val := node{ - word: wordToInput, - n: rand.Intn(len(wordToInput)) + 1, - } - table = append(table, val) - } - - table = append(table, - node{word: "Hello!", n: 3}, - node{word: "Salut!", n: 2}, - node{word: "Ola!", n: 4}, - node{word: "♥01!", n: 1}, - node{word: "Not", n: 6}, - node{word: "Also not", n: 9}, - node{word: "Tree house", n: 5}, - node{word: "Whatever", n: 0}, - node{word: "Whatshisname", n: -2}, - ) - - for _, arg := range table { - lib.Challenge("NRune", student.NRune, nRune, arg.word, arg.n) - } -} diff --git a/test-go/tests/onlya_test/main.go b/test-go/tests/onlya_test/main.go deleted file mode 100644 index 71bcba7cc..000000000 --- a/test-go/tests/onlya_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("onlya") -} diff --git a/test-go/tests/onlyz_test/main.go b/test-go/tests/onlyz_test/main.go deleted file mode 100644 index 0b3276ea1..000000000 --- a/test-go/tests/onlyz_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("onlyz") -} diff --git a/test-go/tests/options_test/main.go b/test-go/tests/options_test/main.go deleted file mode 100644 index c508ab1d6..000000000 --- a/test-go/tests/options_test/main.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - var table []string - - table = append(table, "-"+lib.RandLower(), - " ", - "-%", - "-?", - "-=", - "-abc -ijk", - "-z", - "-abc -hijk", - "-abcdefghijklmnopqrstuvwxyz", - "-abcdefgijklmnopqrstuvwxyz", - "-eeeeee", - "-hhhhhh", - "-h", - "-hz", - "-zh", - "-z -h", - strings.Join([]string{"-", lib.RandStr(10, lib.RuneRange('a', 'z'))}, ""), - ) - - for _, s := range table { - lib.ChallengeMain("options", strings.Fields(s)...) - } -} diff --git a/test-go/tests/paramcount_test/main.go b/test-go/tests/paramcount_test/main.go deleted file mode 100644 index 7b06a5154..000000000 --- a/test-go/tests/paramcount_test/main.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import ( - "strconv" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := [][]string{ - {"2", "5", "u", "19"}, - {"2"}, - {"1", "2", "3", "5", "7", "24"}, - {"6", "12", "24"}, - } - - for i := 0; i < 10; i++ { - var arg []string - init := lib.RandIntBetween(0, 10) - for i := init; i < init+lib.RandIntBetween(5, 10); i++ { - arg = append(arg, strconv.Itoa(i)) - } - args = append(args, arg) - } - - for i := 0; i < 1; i++ { - args = append(args, lib.MultRandWords()) - } - - for _, v := range args { - lib.ChallengeMain("paramcount", v...) - } - - lib.ChallengeMain("paramcount") -} diff --git a/test-go/tests/piglatin_test/main.go b/test-go/tests/piglatin_test/main.go deleted file mode 100644 index 4c0ea13a5..000000000 --- a/test-go/tests/piglatin_test/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := [][]string{ - {"", "pig", "is", "crunch", "crnch"}, - {"something", "else"}, - } - - for i := 0; i < 4; i++ { - args = append(args, lib.MultRandBasic()) - } - - for _, v := range args { - lib.ChallengeMain("piglatin", v...) - } -} diff --git a/test-go/tests/pilot_test/main.go b/test-go/tests/pilot_test/main.go deleted file mode 100644 index 681e72e90..000000000 --- a/test-go/tests/pilot_test/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "github.com/01-edu/public/test-go/lib" - -func main() { - lib.ChallengeMain("pilot") -} diff --git a/test-go/tests/point_test/main.go b/test-go/tests/point_test/main.go deleted file mode 100644 index df1352071..000000000 --- a/test-go/tests/point_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("point") -} diff --git a/test-go/tests/pointone_test/main.go b/test-go/tests/pointone_test/main.go deleted file mode 100644 index 657ebb508..000000000 --- a/test-go/tests/pointone_test/main.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func PointOne(n *int) { - *n = 1 -} - -func main() { - n := 0 - student.PointOne(&n) - if n != 1 { - lib.Fatalf("PointOne(&n), n == %d instead of 1\n", n) - } -} diff --git a/test-go/tests/printalphabet_test/main.go b/test-go/tests/printalphabet_test/main.go deleted file mode 100644 index 1e07fdcee..000000000 --- a/test-go/tests/printalphabet_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printalphabet") -} diff --git a/test-go/tests/printalphabetalt2_test/main.go b/test-go/tests/printalphabetalt2_test/main.go deleted file mode 100644 index 40c2fd991..000000000 --- a/test-go/tests/printalphabetalt2_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printalphabetalt2") -} diff --git a/test-go/tests/printalphabetalt_test/main.go b/test-go/tests/printalphabetalt_test/main.go deleted file mode 100644 index b98103883..000000000 --- a/test-go/tests/printalphabetalt_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printalphabetalt") -} diff --git a/test-go/tests/printalphabetg_test/main.go b/test-go/tests/printalphabetg_test/main.go deleted file mode 100644 index a923a8dc6..000000000 --- a/test-go/tests/printalphabetg_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printalphabetg") -} diff --git a/test-go/tests/printalt2_test/main.go b/test-go/tests/printalt2_test/main.go deleted file mode 100644 index f5e8484d9..000000000 --- a/test-go/tests/printalt2_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printalt2") -} diff --git a/test-go/tests/printalt_test/main.go b/test-go/tests/printalt_test/main.go deleted file mode 100644 index dfb6bdb64..000000000 --- a/test-go/tests/printalt_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printalt") -} diff --git a/test-go/tests/printaltu2_test/main.go b/test-go/tests/printaltu2_test/main.go deleted file mode 100644 index 1bdf767b0..000000000 --- a/test-go/tests/printaltu2_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printaltu2") -} diff --git a/test-go/tests/printaltu_test/main.go b/test-go/tests/printaltu_test/main.go deleted file mode 100644 index 6fe108a1e..000000000 --- a/test-go/tests/printaltu_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printaltu") -} diff --git a/test-go/tests/printbits_test/main.go b/test-go/tests/printbits_test/main.go deleted file mode 100644 index 2a85477b9..000000000 --- a/test-go/tests/printbits_test/main.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "strconv" - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - var args []string - for i := 0; i < 20; i++ { - args = append(args, strconv.Itoa(lib.RandIntBetween(0, 255))) - } - args = append(args, - "", - "a", - "bc", - "def", - "notanumber", - lib.RandBasic(), - ) - for _, v := range args { - lib.ChallengeMain("printbits", strings.Fields(v)...) - } -} diff --git a/test-go/tests/printchessboard_test/main.go b/test-go/tests/printchessboard_test/main.go deleted file mode 100644 index 9c999640f..000000000 --- a/test-go/tests/printchessboard_test/main.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - "strconv" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := [][]string{ - {"0", "0"}, - {"1", "2"}, - {"2"}, - {"0"}, - {"3", "3"}, - {"1", "5"}, - {"5", "1"}, - {"4", "3"}, - } - for i := 0; i < 2; i++ { - table = append(table, []string{ - strconv.Itoa(lib.RandIntBetween(1, 200)), - strconv.Itoa(lib.RandIntBetween(1, 200)), - }) - } - - for _, v := range table { - lib.ChallengeMain("printchessboard", v...) - } -} diff --git a/test-go/tests/printcomb2_test/main.go b/test-go/tests/printcomb2_test/main.go deleted file mode 100644 index 32b7b314f..000000000 --- a/test-go/tests/printcomb2_test/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func printComb2() { - for a := 0; a <= 98; a++ { - for b := a + 1; b <= 99; b++ { - fmt.Printf("%.2d %.2d", a, b) - if a != 98 || b != 99 { - fmt.Print(", ") - } - } - } - fmt.Println() -} - -func main() { - lib.Challenge("PrintComb2", student.PrintComb2, printComb2) -} diff --git a/test-go/tests/printcomb_test/main.go b/test-go/tests/printcomb_test/main.go deleted file mode 100644 index c24d98ee6..000000000 --- a/test-go/tests/printcomb_test/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func printComb() { - for i := '0'; i <= '7'; i++ { - for j := i + 1; j <= '8'; j++ { - for k := j + 1; k <= '9'; k++ { - fmt.Printf("%c%c%c", i, j, k) - if i < '7' { - fmt.Print(", ") - } - } - } - } - fmt.Println() -} - -func main() { - lib.Challenge("PrintComb", student.PrintComb, printComb) -} diff --git a/test-go/tests/printcombn_test/main.go b/test-go/tests/printcombn_test/main.go deleted file mode 100644 index fdcd6b920..000000000 --- a/test-go/tests/printcombn_test/main.go +++ /dev/null @@ -1,77 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func show(n int, table [9]int, tmax [9]int) { - i := 0 - for i < n { - fmt.Print(table[i]) - i++ - } - if table[0] != tmax[0] { - fmt.Print(", ") - } -} - -func printComb1() { - table := [9]int{0} - tmax := [9]int{9} - for table[0] <= tmax[0] { - show(1, table, tmax) - table[0]++ - } -} - -func printCombN(n int) { - table := [9]int{0, 1, 2, 3, 4, 5, 6, 7, 8} - tmax := [9]int{} - - if n == 1 { - printComb1() - } else { - i := n - 1 - j := 9 - for i >= 0 { - tmax[i] = j - i-- - j-- - } - i = n - 1 - for table[0] < tmax[0] { - if table[i] != tmax[i] { - show(n, table, tmax) - table[i]++ - } - if table[i] == tmax[i] { - if table[i-1] != tmax[i-1] { - show(n, table, tmax) - table[i-1]++ - j = i - for j < n { - table[j] = table[j-1] + 1 - j++ - } - i = n - 1 - } - } - for table[i] == tmax[i] && table[i-1] == tmax[i-1] && i > 1 { - i-- - } - } - show(n, table, tmax) - } - fmt.Println() -} - -func main() { - table := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} - for _, arg := range table { - lib.Challenge("PrintCombN", student.PrintCombN, printCombN, arg) - } -} diff --git a/test-go/tests/printdigits_test/main.go b/test-go/tests/printdigits_test/main.go deleted file mode 100644 index 52ed26bed..000000000 --- a/test-go/tests/printdigits_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printdigits") -} diff --git a/test-go/tests/printhex_test/main.go b/test-go/tests/printhex_test/main.go deleted file mode 100644 index 4736a3127..000000000 --- a/test-go/tests/printhex_test/main.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "strconv" - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := []string{ - " ", - "123 132 1", - "1 5", - "0", - } - for i := 0; i < 10; i++ { - table = append(table, strconv.Itoa(lib.RandIntBetween(-1000, lib.MaxInt))) - } - for i := 0; i < 15; i++ { - table = append(table, strconv.Itoa(i)) - } - for _, s := range table { - lib.ChallengeMain("printhex", strings.Fields(s)...) - } -} diff --git a/test-go/tests/printmemory_test/main.go b/test-go/tests/printmemory_test/main.go deleted file mode 100644 index 7da5211fc..000000000 --- a/test-go/tests/printmemory_test/main.go +++ /dev/null @@ -1,100 +0,0 @@ -package main - -import ( - "fmt" - "unicode" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func printBase(nbr int) int { - var result []rune - base := "0123456789abcdef" - typeBase := []rune(base) - a := 0 - pos := 0 - i := 0 - if nbr == 0 { - result = append(result, '0', '0') - i = 2 - } - for nbr > 0 { - pos = nbr % 16 - nbr = nbr / 16 - result = append(result, typeBase[pos]) - i++ - } - if i == 1 { - result = append(result, '0') - i = 2 - } - for j := i - 1; j >= 0; j-- { - fmt.Printf("%c", result[j]) - a++ - } - return a -} - -func printLine(elems [10]int, start int) { - size := len(elems) - a := start - var aux, b int - - for a < start+16 && a < size { - if a%4 == 0 && a != 0 { - fmt.Println() - } - b = 8 - printBase(elems[a]) - for aux != b { - if b == 6 { - fmt.Print("0") - } - if aux == 1 { - fmt.Print(" ") - } - if b < 6 { - fmt.Print("0") - } - aux++ - } - fmt.Print(" ") - aux = 0 - a++ - } - fmt.Println() - c := start - for c < start+16 && c < size { - if unicode.IsGraphic(rune(elems[c])) { - fmt.Printf("%c", rune(elems[c])) - } else { - fmt.Print(".") - } - c++ - } - fmt.Println() -} - -func printMemory(a [10]int) { - i := 0 - for i < len(a) { - printLine(a, i) - i += 16 - } -} - -func main() { - var table [10]int - - for j := 0; j < 5; j++ { - for i := 0; i < 10; i++ { - table[i] = lib.RandIntBetween(0, 1000) - } - lib.Challenge("PrintMemory", student.PrintMemory, printMemory, table) - } - table2 := [10]int{104, 101, 108, 108, 111, 16, 21, 42} - lib.Challenge("PrintMemory", student.PrintMemory, printMemory, table2) -} - -// TODO: this can be simplified a lot diff --git a/test-go/tests/printnbr_test/main.go b/test-go/tests/printnbr_test/main.go deleted file mode 100644 index 96f68eafd..000000000 --- a/test-go/tests/printnbr_test/main.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func printNbr(n int) { - fmt.Print(n) -} - -func main() { - table := append(lib.MultRandInt(), - lib.MinInt, - lib.MaxInt, - 0, - ) - for _, arg := range table { - lib.Challenge("PrintNbr", student.PrintNbr, printNbr, arg) - } -} diff --git a/test-go/tests/printnbrbase_test/main.go b/test-go/tests/printnbrbase_test/main.go deleted file mode 100644 index 8d30d3775..000000000 --- a/test-go/tests/printnbrbase_test/main.go +++ /dev/null @@ -1,71 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/lib/base" -) - -func printNbrBase(n int, b string) { - if base.IsValid(b) { - length := len(b) - sign := 1 - rbase := []rune(b) - if n < 0 { - fmt.Print("-") - sign = -1 - } - if n < length && n >= 0 { - fmt.Printf("%c", rbase[n]) - } else { - printNbrBase(sign*(n/length), b) - fmt.Printf("%c", rbase[sign*(n%length)]) - } - } else { - fmt.Print("NV") - } -} - -func main() { - type node struct { - n int - base string - } - - table := []node{} - - // 15 random pairs of ints with valid bases - for i := 0; i < 15; i++ { - validBaseToInput := base.Valid() - val := node{ - n: lib.RandIntBetween(-1000000, 1000000), - base: validBaseToInput, - } - table = append(table, val) - } - - // 15 random pairs of ints with invalid bases - for i := 0; i < 15; i++ { - invalidBaseToInput := base.Invalid() - val := node{ - n: lib.RandIntBetween(-1000000, 1000000), - base: invalidBaseToInput, - } - table = append(table, val) - } - - table = append(table, - node{n: 125, base: "0123456789"}, - node{n: -125, base: "01"}, - node{n: 125, base: "0123456789ABCDEF"}, - node{n: -125, base: "choumi"}, - node{n: 125, base: "-ab"}, - node{n: lib.MinInt, base: "0123456789"}, - ) - for _, arg := range table { - lib.Challenge("PrintNbrBase", student.PrintNbrBase, printNbrBase, arg.n, arg.base) - } -} diff --git a/test-go/tests/printnbrinorder_test/main.go b/test-go/tests/printnbrinorder_test/main.go deleted file mode 100644 index c9435c353..000000000 --- a/test-go/tests/printnbrinorder_test/main.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "fmt" - "sort" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func intToDigits(n int) (digits []int) { - for n > 0 { - if n == 0 { - digits = append(digits, 0) - } else { - digits = append(digits, n%10) - } - n /= 10 - } - return -} - -func printNbrInOrder(n int) { - if n == 0 { - fmt.Print("0") - return - } - digits := intToDigits(n) - sort.Ints(digits) - for _, i := range digits { - fmt.Printf("%c", rune(i)+'0') - } -} - -func main() { - table := append( - lib.MultRandIntBetween(0, lib.MaxInt), - lib.MaxInt, - 321, - 321321, - 0, - ) - for _, arg := range table { - lib.Challenge("PrintNbrInOrder", student.PrintNbrInOrder, printNbrInOrder, arg) - } -} diff --git a/test-go/tests/printparams_test/main.go b/test-go/tests/printparams_test/main.go deleted file mode 100644 index 95f8b6553..000000000 --- a/test-go/tests/printparams_test/main.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandWords(), "choumi is the best cat") - for _, s := range table { - lib.ChallengeMain("printparams", strings.Fields(s)...) - } -} diff --git a/test-go/tests/printprogramname_test/main.go b/test-go/tests/printprogramname_test/main.go deleted file mode 100644 index 6a2e03bdb..000000000 --- a/test-go/tests/printprogramname_test/main.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - "os" - "os/exec" - - "github.com/01-edu/public/test-go/lib" -) - -var oldName = "exe" - -func test(name string) { - if err := os.Rename(oldName, name); err != nil { - lib.Fatalln(err) - } - b, err := exec.Command("./" + name).CombinedOutput() - if err != nil { - lib.Fatalln(err) - } - if string(b) != name+"\n" { - lib.Fatalln("Failed to print the program name :", string(b)) - } - oldName = name -} - -func main() { - test("choumi") - test("🤦🏻‍♀️") - test("€") -} diff --git a/test-go/tests/printrevcomb_test/main.go b/test-go/tests/printrevcomb_test/main.go deleted file mode 100644 index 6171d70f3..000000000 --- a/test-go/tests/printrevcomb_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printrevcomb") -} diff --git a/test-go/tests/printreversealphabet_test/main.go b/test-go/tests/printreversealphabet_test/main.go deleted file mode 100644 index 99ecacd26..000000000 --- a/test-go/tests/printreversealphabet_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printreversealphabet") -} diff --git a/test-go/tests/printreversealphabetalt2_test/main.go b/test-go/tests/printreversealphabetalt2_test/main.go deleted file mode 100644 index 76a629edd..000000000 --- a/test-go/tests/printreversealphabetalt2_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printreversealphabetalt2") -} diff --git a/test-go/tests/printreversealphabetalt_test/main.go b/test-go/tests/printreversealphabetalt_test/main.go deleted file mode 100644 index d97536461..000000000 --- a/test-go/tests/printreversealphabetalt_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printreversealphabetalt") -} diff --git a/test-go/tests/printreversealphabetg_test/main.go b/test-go/tests/printreversealphabetg_test/main.go deleted file mode 100644 index d777cf838..000000000 --- a/test-go/tests/printreversealphabetg_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("printreversealphabetg") -} diff --git a/test-go/tests/printrot_test/main.go b/test-go/tests/printrot_test/main.go deleted file mode 100644 index e6fbe0d6b..000000000 --- a/test-go/tests/printrot_test/main.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := []string{ - "A", - "a", - "b", - "c", - "d", - "e", - "f", - "g", - "h", - "i", - "j", - "k", - "l", - "m", - "n", - "o", - "p", - "q", - "r", - "s", - "t", - "u", - "v", - "w", - "x", - "y", - "z", - "Z", - "2 arguments", - "4 arguments so invalid", - } - for _, s := range table { - lib.ChallengeMain("printrot", strings.Fields(s)...) - } -} diff --git a/test-go/tests/printstr_test/main.go b/test-go/tests/printstr_test/main.go deleted file mode 100644 index 9888da1d2..000000000 --- a/test-go/tests/printstr_test/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func printStr(s string) { - fmt.Print(s) -} - -func main() { - table := append(lib.MultRandASCII(), "Hello World!") - for _, arg := range table { - lib.Challenge("PrintStr", student.PrintStr, printStr, arg) - } -} diff --git a/test-go/tests/printwordstables_test/main.go b/test-go/tests/printwordstables_test/main.go deleted file mode 100644 index 3c134bda6..000000000 --- a/test-go/tests/printwordstables_test/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func printWordsTables(a []string) { - for _, s := range a { - fmt.Println(s) - } -} - -func main() { - table := [][]string{{"Hello", "how", "are", "you?"}} - - // 30 random slice of slice of strings - for i := 0; i < 30; i++ { - table = append(table, lib.MultRandASCII()) - } - - for _, arg := range table { - lib.Challenge("PrintWordsTables", student.PrintWordsTables, printWordsTables, arg) - } -} diff --git a/test-go/tests/priorprime_test/main.go b/test-go/tests/priorprime_test/main.go deleted file mode 100644 index cdc262798..000000000 --- a/test-go/tests/priorprime_test/main.go +++ /dev/null @@ -1,38 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func priorPrime(x int) int { - ans := 0 - ok := 0 - for i := 2; i < x; i++ { - ok = 1 - for j := 2; j*j <= i; j++ { - if i%j == 0 { - ok = 0 - } - } - if ok == 1 { - ans += i - } - } - return ans -} - -func main() { - table := append(lib.MultRandIntBetween(0, 1000), - 50, - 13, - 10, - 0, - 1, - 2, - ) - for _, arg := range table { - lib.Challenge("PriorPrime", student.PriorPrime, priorPrime, arg) - } -} diff --git a/test-go/tests/quada_test/main.go b/test-go/tests/quada_test/main.go deleted file mode 100644 index 8a7c4472a..000000000 --- a/test-go/tests/quada_test/main.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func drawLine(x int, s string) { - beg := s[0] - med := s[1] - end := s[2] - if x >= 1 { - fmt.Printf("%c", beg) - } - if x > 2 { - for i := 0; i < (x - 2); i++ { - fmt.Printf("%c", med) - } - } - if x > 1 { - fmt.Printf("%c", end) - } - fmt.Println() -} - -func printTheLines(x, y int, strBeg, strMed, strEnd string) { - if y >= 1 { - drawLine(x, strBeg) - } - if y > 2 { - for i := 0; i < y-2; i++ { - drawLine(x, strMed) - } - } - if y > 1 { - drawLine(x, strEnd) - } -} - -func quadA(x, y int) { - if x < 1 || y < 1 { - return - } - printTheLines(x, y, "o-o", "| |", "o-o") -} - -func main() { - // testing examples of subjects - table := []int{ - 5, 3, - 5, 1, - 1, 1, - 1, 5, - } - - // testing special cases and one valid random case. - table = append(table, - 0, 0, - -1, 6, - 6, -1, - lib.RandIntBetween(1, 20), lib.RandIntBetween(1, 20), - ) - - // Tests all possibilities including 0 0, -x y, x -y - for i := 0; i < len(table); i += 2 { - if i != len(table)-1 { - lib.Challenge("QuadA", quadA, student.QuadA, table[i], table[i+1]) - } - } -} diff --git a/test-go/tests/quadb_test/main.go b/test-go/tests/quadb_test/main.go deleted file mode 100644 index 30197362a..000000000 --- a/test-go/tests/quadb_test/main.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func drawLineQuadB(x int, s string) { - beg := s[0] - med := s[1] - end := s[2] - if x >= 1 { - fmt.Printf("%c", beg) - } - if x > 2 { - for i := 0; i < (x - 2); i++ { - fmt.Printf("%c", med) - } - } - if x > 1 { - fmt.Printf("%c", end) - } - fmt.Println() -} - -func quadB(x, y int) { - if x < 1 || y < 1 { - return - } - strBeg := "/*\\" - strMed := "* *" - strEnd := "\\*/" - - if y >= 1 { - drawLineQuadB(x, strBeg) - } - if y > 2 { - for i := 0; i < y-2; i++ { - drawLineQuadB(x, strMed) - } - } - if y > 1 { - drawLineQuadB(x, strEnd) - } -} - -func main() { - // testing examples of subjects - table := []int{ - 5, 3, - 5, 1, - 1, 1, - 1, 5, - } - - // testing special cases and one valid random case. - table = append(table, - 0, 0, - -1, 6, - 6, -1, - lib.RandIntBetween(1, 20), lib.RandIntBetween(1, 20), - ) - - // Tests all possibilities including 0 0, -x y, x -y - for i := 0; i < len(table); i += 2 { - if i != len(table)-1 { - lib.Challenge("QuadB", quadB, student.QuadB, table[i], table[i+1]) - } - } -} diff --git a/test-go/tests/quadc_test/main.go b/test-go/tests/quadc_test/main.go deleted file mode 100644 index fc6436d95..000000000 --- a/test-go/tests/quadc_test/main.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func drawLineQuadC(x int, s string) { - beg := s[0] - med := s[1] - end := s[2] - if x >= 1 { - fmt.Printf("%c", beg) - } - if x > 2 { - for i := 0; i < (x - 2); i++ { - fmt.Printf("%c", med) - } - } - if x > 1 { - fmt.Printf("%c", end) - } - fmt.Println() -} - -func quadC(x, y int) { - if x < 1 || y < 1 { - return - } - strBeg := "ABA" - strMed := "B B" - strEnd := "CBC" - - if y >= 1 { - drawLineQuadC(x, strBeg) - } - if y > 2 { - for i := 0; i < y-2; i++ { - drawLineQuadC(x, strMed) - } - } - if y > 1 { - drawLineQuadC(x, strEnd) - } -} - -func main() { - // testing examples of subjects - table := []int{ - 5, 3, - 5, 1, - 1, 1, - 1, 5, - } - - // testing special cases and one valid random case. - table = append(table, - 0, 0, - -1, 6, - 6, -1, - lib.RandIntBetween(1, 20), lib.RandIntBetween(1, 20), - ) - - // Tests all possibilities including 0 0, -x y, x -y - for i := 0; i < len(table); i += 2 { - if i != len(table)-1 { - lib.Challenge("QuadC", quadC, student.QuadC, table[i], table[i+1]) - } - } -} diff --git a/test-go/tests/quadd_test/main.go b/test-go/tests/quadd_test/main.go deleted file mode 100644 index 80e28dc0c..000000000 --- a/test-go/tests/quadd_test/main.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func drawLineQuadD(x int, s string) { - beg := s[0] - med := s[1] - end := s[2] - if x >= 1 { - fmt.Printf("%c", beg) - } - if x > 2 { - for i := 0; i < (x - 2); i++ { - fmt.Printf("%c", med) - } - } - if x > 1 { - fmt.Printf("%c", end) - } - fmt.Println() -} - -func quadD(x, y int) { - if x < 1 || y < 1 { - return - } - strBeg := "ABC" - strMed := "B B" - strEnd := "ABC" - - if y >= 1 { - drawLineQuadD(x, strBeg) - } - if y > 2 { - for i := 0; i < y-2; i++ { - drawLineQuadD(x, strMed) - } - } - if y > 1 { - drawLineQuadD(x, strEnd) - } -} - -func main() { - // testing examples of subjects - table := []int{ - 5, 3, - 5, 1, - 1, 1, - 1, 5, - } - - // testing special cases and one valid random case. - table = append(table, - 0, 0, - -1, 6, - 6, -1, - lib.RandIntBetween(1, 20), lib.RandIntBetween(1, 20), - ) - - // Tests all possibilities including 0 0, -x y, x -y - for i := 0; i < len(table); i += 2 { - if i != len(table)-1 { - lib.Challenge("QuadD", quadD, student.QuadD, table[i], table[i+1]) - } - } -} diff --git a/test-go/tests/quade_test/main.go b/test-go/tests/quade_test/main.go deleted file mode 100644 index 629f700c2..000000000 --- a/test-go/tests/quade_test/main.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func drawLineQuadE(x int, s string) { - beg := s[0] - med := s[1] - end := s[2] - if x >= 1 { - fmt.Printf("%c", beg) - } - if x > 2 { - for i := 0; i < (x - 2); i++ { - fmt.Printf("%c", med) - } - } - if x > 1 { - fmt.Printf("%c", end) - } - fmt.Println() -} - -func quadE(x, y int) { - if x < 1 || y < 1 { - return - } - strBeg := "ABC" - strMed := "B B" - strEnd := "CBA" - - if y >= 1 { - drawLineQuadE(x, strBeg) - } - if y > 2 { - for i := 0; i < y-2; i++ { - drawLineQuadE(x, strMed) - } - } - if y > 1 { - drawLineQuadE(x, strEnd) - } -} - -func main() { - // testing examples of subjects - table := []int{ - 5, 3, - 5, 1, - 1, 1, - 1, 5, - } - - // testing special cases and one valid random case. - table = append(table, - 0, 0, - -1, 6, - 6, -1, - lib.RandIntBetween(1, 20), lib.RandIntBetween(1, 20), - ) - - // Tests all possibilities including 0 0, -x y, x -y - for i := 0; i < len(table); i += 2 { - if i != len(table)-1 { - lib.Challenge("QuadE", quadE, student.QuadE, table[i], table[i+1]) - } - } -} diff --git a/test-go/tests/raid3_test/main.go b/test-go/tests/raid3_test/main.go deleted file mode 100644 index 264a4c1c1..000000000 --- a/test-go/tests/raid3_test/main.go +++ /dev/null @@ -1,54 +0,0 @@ -package main - -import ( - "os/exec" - "strconv" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - execFatal := func(name string, arg ...string) string { - b, err := exec.Command(name, arg...).CombinedOutput() - if _, ok := err.(*exec.ExitError); ok { - lib.Fatalf("%s\n", b) - } else { - lib.Fatalf("%s\n", err) - } - return string(b) - } - - // executes the test and compares student with solutions - executeTest := func(name string, x, y int) { - var output, correct string - - if x == 0 && y == 0 { - output = execFatal("sh", "-c", name+" | ./raid3") - correct = execFatal("sh", "-c", name+" | raid3_prog") - } else { - output = execFatal("sh", "-c", "./"+name+" "+strconv.Itoa(x)+" "+strconv.Itoa(y)+" | ./raid3") - correct = execFatal("sh", "-c", "./"+name+" "+strconv.Itoa(x)+" "+strconv.Itoa(y)+" | raid3_prog") - } - if output != correct { - lib.Fatalf("./%s %d %d | ./raid3 prints %q instead of %q\n", - name, x, y, output, correct) - } - } - - // testing all raids1 - names := []string{"raid1a", "raid1b", "raid1c", "raid1d", "raid1e"} - for _, name := range names { - x := lib.RandIntBetween(1, 50) - y := lib.RandIntBetween(1, 50) - executeTest(name, x, y) - } - - // testing special case AA, AC, A, A - // A C - executeTest("raid1e", 2, 1) - executeTest("raid1c", 2, 1) - executeTest("raid1d", 1, 2) - executeTest("raid1e", 1, 2) - executeTest("raid1e", 1, 1) - executeTest("echo", 0, 0) -} diff --git a/test-go/tests/range_test/main.go b/test-go/tests/range_test/main.go deleted file mode 100644 index add9e2bf2..000000000 --- a/test-go/tests/range_test/main.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "strconv" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - for i := 0; i < 10; i++ { - start := lib.RandIntBetween(-20, 20) - end := lib.RandIntBetween(-20, 20) - lib.ChallengeMain("range", strconv.Itoa(start), strconv.Itoa(end)) - } - lib.ChallengeMain("range", "2", "1", "3") - lib.ChallengeMain("range", "a", "1") - lib.ChallengeMain("range", "1", "b") - lib.ChallengeMain("range", "1", "nan") - lib.ChallengeMain("range", "nan", "b") - lib.ChallengeMain("range") -} diff --git a/test-go/tests/reachablenumber_test/main.go b/test-go/tests/reachablenumber_test/main.go deleted file mode 100644 index 6f209852a..000000000 --- a/test-go/tests/reachablenumber_test/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func reachableNumber(n int) int { - cnt := 0 - for n > 0 { - cnt++ - if n < 10 { - cnt += 8 - break - } else { - n++ - } - for n%10 == 0 { - n /= 10 - } - } - return cnt -} - -func main() { - table := []int{ - 20, - 1, - 9, - 2, - } - for i := 0; i < 25; i++ { - table = append(table, lib.MultRandIntBetween(1, 877)...) - } - for _, arg := range table { - lib.Challenge("ReachableNumber", student.ReachableNumber, reachableNumber, arg) - } -} diff --git a/test-go/tests/rectangle_test/main.go b/test-go/tests/rectangle_test/main.go deleted file mode 100644 index 4f62cdd7a..000000000 --- a/test-go/tests/rectangle_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("rectangle") -} diff --git a/test-go/tests/recursivefactorial_test/main.go b/test-go/tests/recursivefactorial_test/main.go deleted file mode 100644 index 43c8e3361..000000000 --- a/test-go/tests/recursivefactorial_test/main.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import ( - "math/bits" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func recursiveFactorial(nb int) int { - limit := 20 - if nb < 0 || nb > limit { - return 0 - } - if nb == 0 { - return 1 - } - return nb * recursiveFactorial(nb-1) -} - -func main() { - if bits.UintSize != 64 { - panic("only works on 64 bits CPU") - } - table := append( - lib.MultRandInt(), - lib.IntRange(0, 20)..., - ) - for _, arg := range table { - lib.Challenge("RecursiveFactorial", student.RecursiveFactorial, recursiveFactorial, arg) - } -} diff --git a/test-go/tests/recursivepower_test/main.go b/test-go/tests/recursivepower_test/main.go deleted file mode 100644 index 540bacd61..000000000 --- a/test-go/tests/recursivepower_test/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "math" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func recursivePower(nb, power int) int { - if power < 0 { - return 0 - } - return int(math.Pow(float64(nb), float64(power))) -} - -func main() { - i := 0 - for i < 30 { - nb := lib.RandIntBetween(-8, 8) - power := lib.RandIntBetween(-10, 10) - lib.Challenge("RecursivePower", student.RecursivePower, recursivePower, nb, power) - i++ - } - lib.Challenge("RecursivePower", student.RecursivePower, recursivePower, 0, 0) - lib.Challenge("RecursivePower", student.RecursivePower, recursivePower, 0, 1) -} diff --git a/test-go/tests/reduceint_test/main.go b/test-go/tests/reduceint_test/main.go deleted file mode 100644 index f4c125972..000000000 --- a/test-go/tests/reduceint_test/main.go +++ /dev/null @@ -1,52 +0,0 @@ -package main - -import ( - "fmt" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func reduceInt(a []int, f func(int, int) int) { - acc := a[0] - for i := 1; i < len(a); i++ { - acc = f(acc, a[i]) - } - fmt.Println(acc) -} - -func main() { - f := []func(int, int) int{ - func(accumulator, currentValue int) int { - return accumulator + currentValue - }, - func(accumulator, currentValue int) int { - return accumulator - currentValue - }, - func(accumulator, currentValue int) int { - return currentValue * accumulator - }, - } - argInt := []int{} - - type node struct { - a []int - functions []func(int, int) int - } - - table := []node{} - for i := 0; i < 4; i++ { - argInt = lib.MultRandIntBetween(0, 50) - table = append(table, node{ - a: argInt, - functions: f, - }) - } - - for _, v := range table { - for _, f := range v.functions { - lib.Challenge("ReduceInt", student.ReduceInt, reduceInt, v.a, f) - } - } -} diff --git a/test-go/tests/repeatalpha_test/main.go b/test-go/tests/repeatalpha_test/main.go deleted file mode 100644 index 0928514a3..000000000 --- a/test-go/tests/repeatalpha_test/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := []string{ - "", - "Hello", - "World", - "Home", - "Theorem", - "Choumi is the best cat", - "abracadaba 01!", - "abc", - "MaTheMatiCs", - } - - args = append(args, lib.MultRandAlnum()...) - - for _, v := range args { - lib.ChallengeMain("repeatalpha", v) - } - lib.ChallengeMain("repeatalpha") - lib.ChallengeMain("repeatalpha", "", "") -} diff --git a/test-go/tests/reversebits_test/main.go b/test-go/tests/reversebits_test/main.go deleted file mode 100644 index 95d341883..000000000 --- a/test-go/tests/reversebits_test/main.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "math/bits" - "reflect" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func reverseBits(octet byte) byte { - return bits.Reverse8(uint8(octet)) -} - -func challengeBytes(fn1, fn2 interface{}, args ...interface{}) { - st1 := lib.Monitor(fn1, args) - st2 := lib.Monitor(fn2, args) - if !reflect.DeepEqual(st1.Results, st2.Results) { - lib.Fatalf("%s(%08b) == %08b instead of %08b\n", - "ReverseBits", - args[0].(byte), - st1.Results[0].(byte), - st2.Results[0].(byte), - ) - } -} - -func main() { - args := []byte{0x26, 0x27, 0x28, 0x29, 0xAA, 0xBB} - - for i := 0; i < 10; i++ { - n := lib.RandIntBetween(0, 255) - args = append(args, byte(n)) - } - - for _, v := range args { - challengeBytes(student.ReverseBits, reverseBits, v) - } -} diff --git a/test-go/tests/reverserange_test/main.go b/test-go/tests/reverserange_test/main.go deleted file mode 100644 index e39c55645..000000000 --- a/test-go/tests/reverserange_test/main.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "strconv" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - for i := 0; i < 10; i++ { - start := lib.RandIntBetween(-20, 20) - end := lib.RandIntBetween(-20, 20) - lib.ChallengeMain("reverserange", strconv.Itoa(start), strconv.Itoa(end)) - } - lib.ChallengeMain("reverserange", "2", "1", "3") - lib.ChallengeMain("reverserange", "a", "1") - lib.ChallengeMain("reverserange", "1", "b") - lib.ChallengeMain("reverserange", "1", "nan") - lib.ChallengeMain("reverserange", "nan", "b") - lib.ChallengeMain("reverserange") -} diff --git a/test-go/tests/reversestrcap_test/main.go b/test-go/tests/reversestrcap_test/main.go deleted file mode 100644 index 55bbc9570..000000000 --- a/test-go/tests/reversestrcap_test/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := [][]string{ - {"First SMALL TesT"}, - {"SEconD Test IS a LItTLE EasIEr", "bEwaRe IT'S NoT HARd WhEN ", " Go a dernier 0123456789 for the road e"}, - {""}, - } - - for i := 0; i < 15; i++ { - args = append(args, lib.MultRandAlnum()) - } - - for _, v := range args { - lib.ChallengeMain("reversestrcap", v...) - } - lib.ChallengeMain("reversestrcap") -} diff --git a/test-go/tests/revivethreenums_test/main.go b/test-go/tests/revivethreenums_test/main.go deleted file mode 100644 index 2eaf813dc..000000000 --- a/test-go/tests/revivethreenums_test/main.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func max(ints ...int) int { - if len(ints) == 0 { - panic("max() is invalid") - } - max := ints[0] - for _, i := range ints[1:] { - if i > max { - max = i - } - } - return max -} - -func reviveThreeNums(a, b, c, d int) int { - maxi := -111 - if a != max(a, b, c, d) { - maxi = max(maxi, max(a, b, c, d)-a) - } - if b != max(a, b, c, d) { - maxi = max(maxi, max(a, b, c, d)-b) - } - if c != max(a, b, c, d) { - maxi = max(maxi, max(a, b, c, d)-c) - } - if d != max(a, b, c, d) { - maxi = max(maxi, max(a, b, c, d)-d) - } - return maxi -} - -func main() { - table := [][4]int{ - {3, 6, 5, 4}, - {40, 40, 40, 60}, - {201, 101, 101, 200}, - } - - for i := 0; i < 25; i++ { - first := lib.RandIntBetween(0, 877) - second := lib.RandIntBetween(0, 877) - third := lib.RandIntBetween(0, 877) - table = append(table, [4]int{ - first + second, - second + third, - first + third, - first + second + third, - }) - } - for _, arg := range table { - lib.Challenge("Revivethreenums", student.ReviveThreeNums, reviveThreeNums, arg[0], arg[1], arg[2], arg[3]) - } -} diff --git a/test-go/tests/revparams_test/main.go b/test-go/tests/revparams_test/main.go deleted file mode 100644 index 5240d034c..000000000 --- a/test-go/tests/revparams_test/main.go +++ /dev/null @@ -1,10 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("revparams", "choumi", "is", "the", "best", "cat") - lib.ChallengeMain("revparams", lib.MultRandWords()...) -} diff --git a/test-go/tests/revwstr_test/main.go b/test-go/tests/revwstr_test/main.go deleted file mode 100644 index ac80abb87..000000000 --- a/test-go/tests/revwstr_test/main.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := []string{ - "", - "abcdefghijklm", - "the time of contempt precedes that of indifference", - "he stared at the mountain", - "qw qw e qwsa d", - } - - // 3 valid random sentences with no spaces at the beginning nor the end and only one space for separator. - for i := 0; i < 3; i++ { - numberOfWords := lib.RandIntBetween(1, 6) - sentence := lib.RandAlnum() - for j := 0; j < numberOfWords; j++ { - sentence += " " + lib.RandAlnum() - } - sentence += lib.RandAlnum() - table = append(table, sentence) - } - - for _, s := range table { - lib.ChallengeMain("revwstr", s) - } - - lib.ChallengeMain("revwstr") - lib.ChallengeMain("revwstr", "1param", "2param", "3param", "4param") -} diff --git a/test-go/tests/robottoorigin_test/main.go b/test-go/tests/robottoorigin_test/main.go deleted file mode 100644 index 614d19d69..000000000 --- a/test-go/tests/robottoorigin_test/main.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := []string{ - "UD", - "LL", - } - - for i := 0; i < 15; i++ { - table = append(table, lib.RandStr(lib.RandIntBetween(5, 1000), "UDLR")) - } - - for _, arg := range table { - lib.ChallengeMain("robottoorigin", arg) - } -} diff --git a/test-go/tests/romannumbers_test/main.go b/test-go/tests/romannumbers_test/main.go deleted file mode 100644 index c6fa46be3..000000000 --- a/test-go/tests/romannumbers_test/main.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "strconv" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - rand := []string{ - "0", - "4000", - "5000", - "12433", - "hello", - "good luck", - } - for i := 0; i < 7; i++ { - rand = append(rand, strconv.Itoa(lib.RandIntBetween(0, 4000))) - } - for _, v := range rand { - lib.ChallengeMain("romannumbers", v) - } -} diff --git a/test-go/tests/rostring_test/main.go b/test-go/tests/rostring_test/main.go deleted file mode 100644 index 0f58a2c40..000000000 --- a/test-go/tests/rostring_test/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := []string{ - "abc ", - "Let there be light", - " AkjhZ zLKIJz , 23y", - "", - } - args = append(args, lib.MultRandWords()...) - - for _, arg := range args { - lib.ChallengeMain("rostring", arg) - } - lib.ChallengeMain("rostring") - lib.ChallengeMain("rostring", "this", "is") - lib.ChallengeMain("rostring", "not", "good", "for you") -} diff --git a/test-go/tests/rot13_test/main.go b/test-go/tests/rot13_test/main.go deleted file mode 100644 index f4e1ac33d..000000000 --- a/test-go/tests/rot13_test/main.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandWords(), - " ", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRSTUVWXYZ", - "a b c d e f g h ijklmnopqrstuvwxyz A B C D E FGHIJKLMNOPRSTUVWXYZ", - ) - for _, s := range table { - lib.ChallengeMain("rot13", s) - } - lib.ChallengeMain("rot13", "1 argument", "2 arguments") - lib.ChallengeMain("rot13", "1 argument", "2 arguments", "3 arguments") -} diff --git a/test-go/tests/rot14_test/main.go b/test-go/tests/rot14_test/main.go deleted file mode 100644 index 6dbaad2c5..000000000 --- a/test-go/tests/rot14_test/main.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func rot14(s string) (result string) { - for _, r := range s { - if r >= 'a' && r <= 'z' { - if r >= 'm' { - r -= 12 - } else { - r += 14 - } - } else if r >= 'A' && r <= 'Z' { - if r >= 'M' { - r -= 12 - } else { - r += 14 - } - } - result += string(r) - } - return result -} - -func main() { - type nodeTest struct { - data []string - } - - table := []nodeTest{} - for i := 0; i < 5; i++ { - val := nodeTest{ - data: lib.MultRandWords(), - } - table = append(table, val) - } - - for _, arg := range table { - for _, s := range arg.data { - lib.Challenge("Rot14", rot14, student.Rot14, s) - } - } -} diff --git a/test-go/tests/rotatevowels_test/main.go b/test-go/tests/rotatevowels_test/main.go deleted file mode 100644 index c6a385b1e..000000000 --- a/test-go/tests/rotatevowels_test/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - letters := lib.Lower + lib.Upper + " " - a := []string{""} - for i := 0; i < 10; i++ { - a = append(a, lib.RandStr(lib.RandIntBetween(2, 20), letters)) - } - - for _, v := range a { - lib.ChallengeMain("rotatevowels", strings.Fields(v)...) - } - lib.ChallengeMain("rotatevowels", "Hello World") - lib.ChallengeMain("rotatevowels", "HEllO World", "problem solved") - lib.ChallengeMain("rotatevowels", "str", "shh", "psst") - lib.ChallengeMain("rotatevowels", "happy thoughts", "good luck") - lib.ChallengeMain("rotatevowels", "al's elEphAnt is overly underweight!") - lib.ChallengeMain("rotatevowels", "aEi", "Ou") -} diff --git a/test-go/tests/rpncalc_test/main.go b/test-go/tests/rpncalc_test/main.go deleted file mode 100644 index ca94e6849..000000000 --- a/test-go/tests/rpncalc_test/main.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - args := []string{ - "1 2 * 3 * 4 +", - "3 1 2 * * 4 %", - "5 10 9 / - 50 *", - "21 3 2 % 2 3 2 *", - "1 2 3 4 +", - "324 + 1 - 23 ", - "32 / 22", - "11 22 +", - "23491234 102030932 -", - "123 2222 /", - "299 255 %", - "15 76 *", - "88 67 dks -", - " 1 3 * 2 -", - } - - for _, v := range args { - lib.ChallengeMain("rpncalc", v) - } - lib.ChallengeMain("rpncalc") - lib.ChallengeMain("rpncalc", "1 2 * 3 * 4 +", "10 33 - 12 %") -} diff --git a/test-go/tests/searchreplace_test/main.go b/test-go/tests/searchreplace_test/main.go deleted file mode 100644 index 311ae9102..000000000 --- a/test-go/tests/searchreplace_test/main.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - type nodeTest struct { - dataSearched string - letterLookedFor string - letterReplacing string - } - - table := []nodeTest{} - - for i := 0; i < 20; i++ { - letter1 := []rune(lib.RandAlnum()) - letter2 := []rune(lib.RandAlnum()) - - table = append(table, - nodeTest{ - dataSearched: lib.RandWords(), - letterLookedFor: string(letter1[0]), - letterReplacing: string(letter2[0]), - }) - } - - table = append(table, - nodeTest{ - dataSearched: "hélla", - letterLookedFor: "é", - letterReplacing: "o", - }, - nodeTest{ - dataSearched: "hella", - letterLookedFor: "z", - letterReplacing: "o", - }, - nodeTest{ - dataSearched: "hella", - letterLookedFor: "h", - letterReplacing: "o", - }, - ) - - for _, arg := range table { - lib.ChallengeMain("searchreplace", arg.dataSearched, arg.letterLookedFor, arg.letterReplacing) - } -} diff --git a/test-go/tests/slice_test/main.go b/test-go/tests/slice_test/main.go deleted file mode 100644 index 22998aa15..000000000 --- a/test-go/tests/slice_test/main.go +++ /dev/null @@ -1,86 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func ifNegative(a []string, n int) int { - if n < 0 { - n = len(a) + n - } - - if n < 0 { - n = 0 - } else if n > len(a) { - n = len(a) - } - - return n -} - -func slice(a []string, nbr ...int) []string { - if len(nbr) == 0 { - return a - } - - first := nbr[0] - if len(nbr) == 1 { - if first < 0 { - first = len(a) + first - if first < 0 { - return a - } - } - return a[first:] - } - second := nbr[1] - - first = ifNegative(a, first) - second = ifNegative(a, second) - - if first > second { - return nil - } - - return a[first:second] -} - -func main() { - elems := [][]interface{}{ - { - []string{"coding", "algorithm", "ascii", "package", "golang"}, - 1, - }, - { - []string{"coding", "algorithm", "ascii", "package", "golang"}, - -3, - }, - { - []string{"coding", "algorithm", "ascii", "package", "golang"}, - 2, 4, - }, - { - []string{"coding", "algorithm", "ascii", "package", "golang"}, - -2, -1, - }, - { - []string{"coding", "algorithm", "ascii", "package", "golang"}, - 2, 0, - }, - } - - s := lib.MultRandWords() - - elems = append(elems, []interface{}{s, -len(s) - 10, -len(s) - 5}) - - for i := 0; i < 3; i++ { - s = lib.MultRandWords() - elems = append(elems, []interface{}{s, lib.RandIntBetween(-len(s)-10, len(s)+10), lib.RandIntBetween(-len(s)-8, len(s)+10)}) - } - - for _, a := range elems { - lib.Challenge("Slice", student.Slice, slice, a...) - } -} diff --git a/test-go/tests/sortedlistmerge_test/main.go b/test-go/tests/sortedlistmerge_test/main.go deleted file mode 100644 index a86037118..000000000 --- a/test-go/tests/sortedlistmerge_test/main.go +++ /dev/null @@ -1,111 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - NodeI13 = student.NodeI - NodeIS13 = solutions.NodeI -) - -func printListStudent1(n *NodeI13) string { - var res string - it := n - for it != nil { - res += strconv.Itoa(it.Data) + "-> " - it = it.Next - } - - res += "" - return res -} - -func nodePushBackListInt13(l *NodeI13, l1 *NodeIS13, data int) { - n := &NodeI13{Data: data} - n1 := &NodeIS13{Data: data} - - if l == nil { - l = n - } else { - iterator := l - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n - } - - if l1 == nil { - l1 = n1 - } else { - iterator1 := l1 - for iterator1.Next != nil { - iterator1 = iterator1.Next - } - iterator1.Next = n1 - } -} - -func main() { - var link1 *NodeI13 - var link2 *NodeI13 - var linkTest1 *NodeIS13 - var linkTest2 *NodeIS13 - type nodeTest struct { - data1 []int - data2 []int - } - - table := []nodeTest{{ - data1: []int{}, - }} - - for i := 0; i < 3; i++ { - val := nodeTest{ - data1: lib.MultRandInt(), - data2: lib.MultRandInt(), - } - table = append(table, val) - } - table = append(table, - nodeTest{ - data1: []int{3, 5, 7}, - data2: []int{1, -2, 4, 6}, - }, - ) - for _, arg := range table { - for i := 0; i < len(arg.data1); i++ { - nodePushBackListInt13(link1, linkTest1, arg.data1[i]) - } - for i := 0; i < len(arg.data2); i++ { - nodePushBackListInt13(link2, linkTest2, arg.data2[i]) - } - - link1 = student.ListSort(link1) - link2 = student.ListSort(link2) - linkTest1 = solutions.ListSort(linkTest1) - linkTest2 = solutions.ListSort(linkTest2) - - aux1 := student.SortedListMerge(link1, link2) - aux2 := solutions.SortedListMerge(linkTest1, linkTest2) - - if aux1 == nil && aux2 == nil { - } else if aux1 != nil && aux2 == nil { - lib.Fatalf("\nstudent merged lists:%s\nmerged lists:%s\n\nSortListMerge() == %v instead of %v\n\n", - printListStudent1(aux1), solutions.PrintList(aux2), aux1, aux2) - } else if aux1.Data != aux2.Data { - lib.Fatalf("\nstudent merged lists:%s\nmerged lists:%s\n\nSortListMerge() == %v instead of %v\n\n", - printListStudent1(aux1), solutions.PrintList(aux2), aux1, aux2) - } - - link1 = &NodeI13{} - link2 = &NodeI13{} - linkTest1 = &NodeIS13{} - linkTest2 = &NodeIS13{} - } -} diff --git a/test-go/tests/sortintegertable_test/main.go b/test-go/tests/sortintegertable_test/main.go deleted file mode 100644 index 168a83344..000000000 --- a/test-go/tests/sortintegertable_test/main.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "reflect" - "sort" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func sortIntegerTable(a []int) { - sort.Ints(a) -} - -func main() { - i := 0 - for i < lib.SliceLen { - table1 := lib.MultRandIntBetween(-100, 100) - - tableCopyBefore := make([]int, len(table1)) - copy(tableCopyBefore, table1) - - table2 := make([]int, len(table1)) - copy(table2, table1) - - student.SortIntegerTable(table1) - sortIntegerTable(table2) - if !reflect.DeepEqual(table1, table2) { - lib.Fatalf("SortIntegerTable(%v), table1 == %v instead of %v ", tableCopyBefore, table1, table2) - } - i++ - } -} diff --git a/test-go/tests/sortlistinsert_test/main.go b/test-go/tests/sortlistinsert_test/main.go deleted file mode 100644 index a6eb4182b..000000000 --- a/test-go/tests/sortlistinsert_test/main.go +++ /dev/null @@ -1,141 +0,0 @@ -package main - -import ( - "strconv" - - student "student" - - "github.com/01-edu/public/test-go/lib" - "github.com/01-edu/public/test-go/solutions" -) - -type ( - NodeI14 = student.NodeI - NodeIS14 = solutions.NodeI -) - -func listToStringStu3(n *NodeI14) string { - var res string - it := n - for it != nil { - res += strconv.Itoa(it.Data) + "-> " - it = it.Next - } - res += "" - return res -} - -func nodepushback1(l *NodeI14, data int) *NodeI14 { - n := &NodeI14{Data: data} - - if l == nil { - return n - } - iterator := l - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n - return l -} - -func nodepushback2(l *NodeIS14, data int) *NodeIS14 { - n := &NodeIS14{Data: data} - - if l == nil { - return n - } - iterator := l - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n - return l -} - -func comparFuncNodeInt14(l1 *NodeI14, l2 *NodeIS14, data []int) { - for l1 != nil || l2 != nil { - if (l1 == nil && l2 != nil) || (l1 != nil && l2 == nil) { - lib.Fatalf("\ndata used to insert: %d\nstudent list:%s\nlist:%s\n\nSortListInsert() == %v instead of %v\n\n", - data, listToStringStu3(l1), solutions.PrintList(l2), l1, l2) - } - if l1.Data != l2.Data { - lib.Fatalf("\ndata used to insert: %d\nstudent list:%s\nlist:%s\n\nSortListInsert() == %v instead of %v\n\n", - data, listToStringStu3(l1), solutions.PrintList(l2), l1.Data, l2.Data) - } - l1 = l1.Next - l2 = l2.Next - } -} - -func move(l *NodeI14) *NodeI14 { - p := l - n := l.Next - ret := n - - for n != nil && l.Data > n.Data { - p = n - n = n.Next - } - p.Next = l - l.Next = n - return ret -} - -func sortStudentsList(l *NodeI14) *NodeI14 { - head := l - if head == nil { - return nil - } - head.Next = sortStudentsList(head.Next) - - if head.Next != nil && head.Data > head.Next.Data { - head = move(head) - } - return head -} - -func main() { - var link1 *NodeI14 - var link2 *NodeIS14 - - type nodeTest struct { - data []int - data_ref []int - } - table := []nodeTest{{ - data: []int{}, - data_ref: []int{}, - }} - - for i := 0; i < 2; i++ { - table = append(table, nodeTest{ - data: lib.MultRandInt(), - data_ref: lib.MultRandInt(), - }) - } - table = append(table, - nodeTest{ - data: []int{5, 4, 3, 2, 1}, - data_ref: lib.MultRandInt(), - }, - ) - for _, arg := range table { - for _, item := range arg.data { - link2 = nodepushback2(link2, item) - link1 = nodepushback1(link1, item) - } - - link2 = solutions.ListSort(link2) - link1 = sortStudentsList(link1) - - for _, item := range arg.data_ref { - link2 = solutions.SortListInsert(link2, item) - link1 = student.SortListInsert(link1, item) - } - - comparFuncNodeInt14(link1, link2, arg.data_ref) - link1 = &NodeI14{} - link2 = &NodeIS14{} - } -} diff --git a/test-go/tests/sortparams_test/main.go b/test-go/tests/sortparams_test/main.go deleted file mode 100644 index 59657efb8..000000000 --- a/test-go/tests/sortparams_test/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - lib.ChallengeMain("sortparams", lib.MultRandWords()...) -} diff --git a/test-go/tests/sortwordarr_test/main.go b/test-go/tests/sortwordarr_test/main.go deleted file mode 100644 index 92ea17226..000000000 --- a/test-go/tests/sortwordarr_test/main.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "reflect" - "sort" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := [][]string{{"a", "A", "1", "b", "B", "2", "c", "C", "3"}} - - for i := 0; i < 15; i++ { - table = append(table, lib.MultRandWords()) - } - - for _, org := range table { - // copy for using the solution function - copySol := make([]string, len(org)) - // copy for using the student function - copyStu := make([]string, len(org)) - - copy(copySol, org) - copy(copyStu, org) - - sort.Strings(copySol) - student.SortWordArr(copyStu) - - if !reflect.DeepEqual(copyStu, copySol) { - lib.Fatalf("%s(%v) == %v instead of %v\n", - "SortWordArr", - org, - copyStu, - copySol, - ) - } - } -} diff --git a/test-go/tests/split_test/main.go b/test-go/tests/split_test/main.go deleted file mode 100644 index b0a6dab02..000000000 --- a/test-go/tests/split_test/main.go +++ /dev/null @@ -1,46 +0,0 @@ -package main - -import ( - "math/rand" - "strings" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - separators := []string{ - "!=HA=!", - "!==!", - " ", - "|=choumi=|", - "|<=>|", - lib.RandStr(3, lib.RuneRange('A', 'Z')), - "<<==123==>>", - "[<>abc<>]", - } - - type node struct { - s string - sep string - } - table := []node{} - // 15 random slice of strings - - for i := 0; i < 15; i++ { - separator := separators[rand.Intn(len(separators))] - val := node{ - s: strings.Join(lib.MultRandAlnum(), separator), - sep: separator, - } - table = append(table, val) - } - - table = append(table, - node{s: "HelloHAhowHAareHAyou?", sep: "HA"}) - - for _, arg := range table { - lib.Challenge("Split", student.Split, strings.Split, arg.s, arg.sep) - } -} diff --git a/test-go/tests/splitwhitespaces_test/main.go b/test-go/tests/splitwhitespaces_test/main.go deleted file mode 100644 index 2208dfd41..000000000 --- a/test-go/tests/splitwhitespaces_test/main.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "strings" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := []string{"Hello how are you?"} - - // 30 random slice of strings - for i := 0; i < 30; i++ { - table = append(table, strings.Join(lib.MultRandASCII(), " ")) - } - for _, arg := range table { - lib.Challenge("SplitWhiteSpaces", student.SplitWhiteSpaces, strings.Fields, arg) - } -} diff --git a/test-go/tests/sqrt_test/main.go b/test-go/tests/sqrt_test/main.go deleted file mode 100644 index d807e7d3e..000000000 --- a/test-go/tests/sqrt_test/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "math" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func sqrt(value int) int { - sr := math.Sqrt(float64(value)) - if math.Mod(sr, 1) == 0 { - return int(sr) - } - return 0 -} - -func main() { - table := append(lib.MultRandIntBetween(-1000000, 1000000), - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 100, - ) - for _, arg := range table { - lib.Challenge("Sqrt", student.Sqrt, sqrt, arg) - } -} diff --git a/test-go/tests/strlen_test/main.go b/test-go/tests/strlen_test/main.go deleted file mode 100644 index 28a3160cf..000000000 --- a/test-go/tests/strlen_test/main.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func strLen(s string) int { - return len([]rune(s)) -} - -func main() { - randomStringCharset := "a b c d e f g h ijklmnopqrstuvwxyz A B C D E FGHIJKLMNOPRSTUVWXYZ" - - table := []string{} - for i := 0; i < 10; i++ { - randomLenghtOfWord := lib.RandIntBetween(1, 20) - randomStrRandomLenght := lib.RandStr(randomLenghtOfWord, randomStringCharset) - table = append(table, randomStrRandomLenght) - } - table = append(table, "Héllo!") - table = append(table, randomStringCharset) - - for _, s := range table { - lib.Challenge("StrLen", student.StrLen, strLen, s) - } -} - -// TODO: refactor, simplify, no need for specific charset : check lib diff --git a/test-go/tests/strrev_test/main.go b/test-go/tests/strrev_test/main.go deleted file mode 100644 index def61971e..000000000 --- a/test-go/tests/strrev_test/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func strRev(s string) string { - runes := []rune(s) - i := 0 - j := len(runes) - 1 - for i < j { - runes[i], runes[j] = runes[j], runes[i] - i++ - j-- - } - return string(runes) -} - -func main() { - table := append( - lib.MultRandASCII(), - "Hello!", - "Bonjour!", - "Hola!", - ) - for _, arg := range table { - lib.Challenge("StrRev", student.StrRev, strRev, arg) - } -} diff --git a/test-go/tests/sudoku_test/main.go b/test-go/tests/sudoku_test/main.go deleted file mode 100644 index 4b04e53b3..000000000 --- a/test-go/tests/sudoku_test/main.go +++ /dev/null @@ -1,298 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - valid := [][]string{ - // 3 9 6 2 4 5 7 8 1 - // 1 7 8 3 6 9 5 2 4 - // 5 2 4 8 1 7 3 9 6 - // 2 8 7 9 5 1 6 4 3 - // 9 3 1 4 8 6 2 7 5 - // 4 6 5 7 2 3 9 1 8 - // 7 1 2 6 3 8 4 5 9 - // 6 5 9 1 7 4 8 3 2 - // 8 4 3 5 9 2 1 6 7 - { - ".96.4...1", - "1...6...4", - "5.481.39.", - "..795..43", - ".3..8....", - "4.5.23.18", - ".1.63..59", - ".59.7.83.", - "..359...7", - }, - - // 1 4 5 8 9 2 6 7 3 - // 8 9 3 1 7 6 4 2 5 - // 2 7 6 4 3 5 8 1 9 - // 5 1 9 2 4 7 3 8 6 - // 7 6 2 5 8 3 1 9 4 - // 3 8 4 9 6 1 7 5 2 - // 9 5 7 6 1 4 2 3 8 - // 4 3 8 7 2 9 5 6 1 - // 6 2 1 3 5 8 9 4 7 - { - "1.58.2...", - ".9..764.5", - "2..4..819", - ".19..73.6", - "762.83.9.", - "....61.5.", - "..76...3.", - "43..2.5.1", - "6..3.89..", - }, - - // 4 7 5 9 3 6 2 8 1 - // 9 3 2 8 5 1 7 6 4 - // 6 8 1 2 7 4 3 5 9 - // 5 1 7 4 9 2 8 3 6 - // 3 4 9 7 6 8 1 2 5 - // 2 6 8 3 1 5 4 9 7 - // 1 5 3 6 8 7 9 4 2 - // 7 9 4 5 2 3 6 1 8 - // 8 2 6 1 4 9 5 7 3 - { - "..5.3..81", - "9.285..6.", - "6....4.5.", - "..74.283.", - "34976...5", - "..83..49.", - "15..87..2", - ".9....6..", - ".26.495.3", - }, - - // 3 4 7 9 1 5 6 2 8 - // 2 9 6 7 8 3 5 4 1 - // 5 1 8 6 2 4 9 7 3 - // 8 6 4 1 5 7 2 3 9 - // 1 3 2 4 6 9 7 8 5 - // 9 7 5 8 3 2 1 6 4 - // 4 5 9 2 7 8 3 1 6 - // 7 8 1 3 9 6 4 5 2 - // 6 2 3 5 4 1 8 9 7 - { - "34.91..2.", - ".96.8..41", - "..8.2..7.", - ".6..57.39", - "1.2.6.7..", - "97..3..64", - "45.2.8..6", - ".8..9..5.", - "6.3..189.", - }, - - // 9 6 7 3 8 1 4 2 5 - // 4 1 8 5 2 7 9 3 6 - // 2 5 3 9 6 4 8 7 1 - // 5 9 1 7 4 8 3 6 2 - // 7 2 4 1 3 6 5 8 9 - // 8 3 6 2 5 9 1 4 7 - // 1 4 9 8 7 2 6 5 3 - // 6 7 5 4 9 3 2 1 8 - // 3 8 2 6 1 5 7 9 4 - { - "..73..4.5", - "....2.9..", - "253.6487.", - ".9.74.36.", - "....3..8.", - "8362.9.47", - "1..8.26.3", - "6......18", - ".8261...4", - }, - - // 9 3 5 6 4 7 1 2 8 - // 1 2 4 3 9 8 6 7 5 - // 6 8 7 5 2 1 4 9 3 - // 8 7 3 2 6 4 5 1 9 - // 4 9 2 1 7 5 3 8 6 - // 5 6 1 8 3 9 2 4 7 - // 2 1 8 7 5 6 9 3 4 - // 3 4 6 9 8 2 7 5 1 - // 7 5 9 4 1 3 8 6 2 - { - "935..7..8", - "...3.8.7.", - "6..5..49.", - ".73..4...", - "4..175.8.", - ".618..247", - ".187.....", - "..6.8.75.", - "75.4.3862", - }, - - // 3 6 5 4 2 9 7 8 1 - // 2 8 7 3 5 1 9 4 6 - // 4 1 9 8 6 7 5 3 2 - // 1 5 4 9 7 8 2 6 3 - // 8 7 2 6 3 5 4 1 9 - // 6 9 3 1 4 2 8 5 7 - // 7 4 1 5 9 3 6 2 8 - // 9 3 6 2 8 4 1 7 5 - // 5 2 8 7 1 6 3 9 4 - { - "..5.2...1", - ".8735..46", - "4...6.5..", - ".5.9.....", - ".7..3541.", - "69314.857", - "7415..6.8", - "...284..5", - "5.....3.4", - }, - - // 9 6 7 5 4 8 2 3 1 - // 8 1 5 2 3 6 4 7 9 - // 2 3 4 7 9 1 8 6 5 - // 5 2 3 6 7 4 1 9 8 - // 7 4 8 1 5 9 6 2 3 - // 1 9 6 8 2 3 5 4 7 - // 3 5 1 9 6 2 7 8 4 - // 4 8 2 3 1 7 9 5 6 - // 6 7 9 4 8 5 3 1 2 - { - "..75...3.", - "8..23...9", - ".3479.86.", - "..3..4198", - ".4815...3", - "..6.23..7", - "351.6.78.", - "4..31...6", - ".7...5..2", - }, - - // 7 5 8 6 9 4 3 2 1 - // 2 6 1 8 5 3 4 9 7 - // 4 3 9 1 2 7 8 6 5 - // 8 2 7 5 4 1 9 3 6 - // 5 4 3 7 6 9 2 1 8 - // 1 9 6 3 8 2 5 7 4 - // 6 7 4 2 3 5 1 8 9 - // 9 1 2 4 7 8 6 5 3 - // 3 8 5 9 1 6 7 4 2 - { - ".58..4.21", - ".6.853..7", - ".39.2...5", - "8....1..6", - "..37..21.", - "1.6.825..", - "67.2..18.", - "9..4...5.", - ".8.9167.2", - }, - - // 4 2 7 1 9 5 8 3 6 - // 5 3 1 6 8 2 9 4 7 - // 8 6 9 3 4 7 2 1 5 - // 3 5 4 2 7 6 1 8 9 - // 2 1 6 9 3 8 7 5 4 - // 9 7 8 4 5 1 6 2 3 - // 1 9 2 5 6 3 4 7 8 - // 7 4 3 8 1 9 5 6 2 - // 6 8 5 7 2 4 3 9 1 - { - ".2.1....6", - "53..8294.", - "8..34...5", - "3542761..", - "..6.3...4", - "9....162.", - ".9...3.78", - "7438.9...", - "..5..43.1", - }, - } - - invalid := [][]string{ - { - ".932..8.", - "27.3.85..", - ".8.73.254", - "9758...31", - "....74.6.", - "6.45.38.7", - "7....2.48", - "32.4...7.", - "..8.579..", - }, - { - ".867.2..4", - ".2.5..8..", - "154.9.237", - ".7.9.5..1", - ".29..4.18", - "51.6...42", - "2.5.7..83", - "...153...", - "39...8.75", - }, - - // . . 7 3 . . 4 . 5 - // . . . . 2 . 9 . . - // 2 5 3 . 6 4 8 7 . - // . 9 . 7 4 . 3 6 . - // . . . . 3 . . 8 . - // 8 3 6 2 . 9 . 4 7 - // 1 . . 8 . 2 6 . 3 - // 6 . . . . . . 1 8 - // . 8 2 6 1 . . . 4 - { - ".7....28.", - ".2...6.57", - "8654729..", - "..925..64", - ".4..19.7.", - "7.8..4..9", - "3..7..698", - "..79.1...", - "59..28.39", - }, - { - "..213.748", - "8.4.....2", - ".178.26..", - ".68.9.27.", - ".932....4", - "5..46.3..", - "..9.24.23", - "..63..19.", - "385..1.2.", - }, - { - "9.46.3..1", - "37.1..2.6", - "..6..93.4", - "..13..9.5", - "56..91...", - "82...461.", - "..79...4.", - "425.167..", - "1.2..75.8", - }, - } - - for _, v := range valid { - lib.ChallengeMain("sudoku", v...) - } - - for _, v := range invalid { - lib.ChallengeMain("sudoku", v...) - } - - lib.ChallengeMain("sudoku") - lib.ChallengeMain("sudoku", "not", "a", "sudoku") -} diff --git a/test-go/tests/swap_test/main.go b/test-go/tests/swap_test/main.go deleted file mode 100644 index 7b74117c4..000000000 --- a/test-go/tests/swap_test/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - i := 0 - for i < 30 { - a := lib.RandInt() - b := lib.RandInt() - aCopy := a - bCopy := b - student.Swap(&a, &b) - if a != bCopy { - lib.Fatalf("Swap(%d, %d), a == %d instead of %d", aCopy, bCopy, a, bCopy) - } - if b != aCopy { - lib.Fatalf("Swap(%d, %d), b == %d instead of %d", aCopy, bCopy, b, aCopy) - } - i++ - } -} diff --git a/test-go/tests/swapbits_test/main.go b/test-go/tests/swapbits_test/main.go deleted file mode 100644 index f2c0cdb0a..000000000 --- a/test-go/tests/swapbits_test/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "reflect" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func swapBits(n byte) byte { - return (n >> 4) | (n << 4) -} - -func challengeBytes(fn1, fn2 interface{}, args ...interface{}) { - st1 := lib.Monitor(fn1, args) - st2 := lib.Monitor(fn2, args) - if !reflect.DeepEqual(st1.Results, st2.Results) { - lib.Fatalf("%s(%08b) == %08b instead of %08b\n", - "SwapBits", - args[0].(byte), - st1.Results[0].(byte), - st2.Results[0].(byte), - ) - } -} - -func main() { - args := []byte{0x24, 0x14, 0x11, 0x22, 0xd2, 0x15, 0xff, 0x0, 0x35, 0x58, 0x43} - - for i := 0; i < 10; i++ { - n := lib.RandIntBetween(0, 255) - args = append(args, byte(n)) - } - - for _, v := range args { - challengeBytes(student.SwapBits, swapBits, v) - } -} diff --git a/test-go/tests/sweetproblem_test/main.go b/test-go/tests/sweetproblem_test/main.go deleted file mode 100644 index b883c6be3..000000000 --- a/test-go/tests/sweetproblem_test/main.go +++ /dev/null @@ -1,98 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func min3(a, b, c int) int { - if a <= b && a <= c { - return a - } - if b <= a && b <= c { - return b - } - return c -} - -func max3(a, b, c int) int { - if a >= b && a >= c { - return a - } - if b >= a && b >= c { - return b - } - return c -} - -func min2(a, b int) int { - if a <= b { - return a - } - return b -} - -func sweetproblem(a, b, c int) int { - if a > b { - f := a - a = b - b = f - } - if a > c { - f := a - a = c - c = f - } - if b > c { - f := b - b = c - c = f - } - ans := a - if c-b >= a { - c -= a - } else { - a -= c - b - half := a / 2 - c -= half - b -= a - half - } - ans += min2(b, c) - return ans -} - -func main() { - type node struct { - red int - green int - blue int - } - - table := []node{ - {50, 43, 20}, - {10, 0, 0}, - {0, 10, 0}, - {0, 0, 10}, - {10, 1, 0}, - {0, 10, 1}, - {1, 0, 10}, - {10, 2, 0}, - {2, 10, 0}, - {0, 2, 10}, - {13, 13, 0}, - {10, 9, 0}, - {5, 9, 2}, - } - - for i := 0; i < 15; i++ { - table = append(table, node{ - red: lib.RandIntBetween(0, 30), - green: lib.RandIntBetween(0, 30), - blue: lib.RandIntBetween(0, 30), - }) - } - for _, arg := range table { - lib.Challenge("SweetProblem", student.Sweetproblem, sweetproblem, arg.red, arg.green, arg.blue) - } -} diff --git a/test-go/tests/switchcase_test/main.go b/test-go/tests/switchcase_test/main.go deleted file mode 100644 index ffe1cf452..000000000 --- a/test-go/tests/switchcase_test/main.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandWords(), - " ", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", - "abcdefghi jklmnop qrstuvwxyz ABCDEFGHI JKLMNOPQR STUVWXYZ ! ", - ) - for _, s := range table { - lib.ChallengeMain("switchcase", s) - } -} diff --git a/test-go/tests/tabmult_test/main.go b/test-go/tests/tabmult_test/main.go deleted file mode 100644 index be465578c..000000000 --- a/test-go/tests/tabmult_test/main.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "strconv" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - var table []string - for i := 1; i < 10; i++ { - table = append(table, strconv.Itoa(i)) - } - for i := 0; i < 5; i++ { - table = append(table, strconv.Itoa(lib.RandIntBetween(1, 1000))) - } - - for _, arg := range table { - lib.ChallengeMain("tabmult", arg) - } -} diff --git a/test-go/tests/tetrisoptimizer_test/main.go b/test-go/tests/tetrisoptimizer_test/main.go deleted file mode 100644 index 63b549408..000000000 --- a/test-go/tests/tetrisoptimizer_test/main.go +++ /dev/null @@ -1,166 +0,0 @@ -package main - -import ( - "context" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "sort" - "strconv" - "strings" - "time" - - "github.com/01-edu/public/test-go/lib" -) - -type ( - vect struct{ x, y int } - - // the tetromino is described with three vectors - // example : - // - // [#][#][#] - // [#] - // - // tetromino{{1, 0}, {2, 0}, {1, 1}} - tetromino [3]vect -) - -// load a tetromino composed of the rune r in the map s, example : -// -// read(`...... -// ...... -// ...... -// ....X. -// ..XXX. -// ...... -// `, -// 'X', -// ) == tetromino{{-2, 1}, {-1, 1}, {0, 1}} -func read(s string, r rune) (t tetromino) { - var origin vect - i := 0 - first := true - lines := strings.Split(s, "\n") - for y, line := range lines { - for x, rr := range line { - if rr == r { - if first { - first = false - origin = vect{x, y} - } else { - t[i] = vect{x - origin.x, y - origin.y} - i++ - if i == 3 { - return tetromino{} - } - } - } - } - } - return -} - -func main() { - var ( - timeout = 30 * time.Second - samples = "./solutions/tetrisoptimizer/samples" - student = "./student/tetrisoptimizer" - exe = filepath.Join(student, "a.out") - ) - // load samples - f, err := os.Open(samples) - if err != nil { - lib.Fatal("Cannot open directory", err) - } - defer f.Close() - filenames, err := f.Readdirnames(0) - if err != nil { - lib.Fatal("Cannot read directory", err) - } - - // separate samples into good (valid) and bad (invalid) files - var goodFiles, badFiles []string - for _, filename := range filenames { - if strings.HasPrefix(filename, "good") { - goodFiles = append(goodFiles, filepath.Join(samples, filename)) - } else if strings.HasPrefix(filename, "bad") { - badFiles = append(badFiles, filepath.Join(samples, filename)) - } - } - sort.Strings(badFiles) - sort.Strings(goodFiles) - - // compile student code - cmd := exec.Command("go", "build", "-o", exe, "-trimpath", "-ldflags", "-s -w", student) - cmd.Env = append(os.Environ(), "CGO_ENABLED=0", "GOARCH=amd64") - if out, err := cmd.CombinedOutput(); err != nil { - lib.Fatal("Cannot compile :", string(out)) - } - - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - - // test invalid cases - for _, badFile := range badFiles { - b, _ := exec.CommandContext(ctx, exe, badFile).CombinedOutput() - if string(b) != "ERROR\n" { - lib.Fatal(`Failed to handle bad format, should output : "ERROR\n"`) - } - } - - // test valid cases - score := .0 - defer func() { - fmt.Println("score =", score) - }() - for _, goodFile := range goodFiles { - size, _ := strconv.Atoi(strings.Split(goodFile, "-")[2]) - b, err := exec.CommandContext(ctx, exe, goodFile).Output() - if ctx.Err() == context.DeadlineExceeded { - return - } - if err != nil { - lib.Fatal("Failed to process a valid map : execution failed") - } - s := string(b) - lines := strings.Split(s, "\n") - if lines[len(lines)-1] != "" { - lib.Fatal(`Failed to process a valid map : missing final '\n'`) - } - lines = lines[:len(lines)-1] - for _, line := range lines { - if len(line) != len(lines) { - lib.Fatal("Failed to process a valid map : invalid square, it is expected as many lines as characters") - } - } - if len(lines) < size { - lib.Fatal("Failed to process a valid map : the square cannot be that small") - } - b, err = ioutil.ReadFile(goodFile) - if err != nil { - lib.Fatal("Failed to read a valid map") - } - pieces := strings.Split(string(b), "\n\n") - surface := len(lines) * len(lines) - if strings.Count(s, ".") != surface-len(pieces)*4 { - lib.Fatal("Failed to process a valid map : the number of holes (character '.') is not correct") - } - letter := 'A' - for _, piece := range pieces { - if read(s, letter) != read(piece, '#') { - lib.Fatal("Failed to process a valid map : a tetromino is missing") - } - letter += 1 - } - score += float64(size*size) / float64(surface) - } -} - -// TODO: -// Fix path -// Add error cases : -// wrong arguments -// bad file types (links, folders) diff --git a/test-go/tests/tolower_test/main.go b/test-go/tests/tolower_test/main.go deleted file mode 100644 index d09b73661..000000000 --- a/test-go/tests/tolower_test/main.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import ( - "strings" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandASCII(), "Hello! How are you?") - for _, arg := range table { - lib.Challenge("ToLower", student.ToLower, strings.ToLower, arg) - } -} diff --git a/test-go/tests/toupper_test/main.go b/test-go/tests/toupper_test/main.go deleted file mode 100644 index 9576b68e1..000000000 --- a/test-go/tests/toupper_test/main.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import ( - "strings" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandASCII(), "Hello! How are you?") - for _, arg := range table { - lib.Challenge("ToUpper", student.ToUpper, strings.ToUpper, arg) - } -} diff --git a/test-go/tests/trimatoi_test/main.go b/test-go/tests/trimatoi_test/main.go deleted file mode 100644 index 7acdcc659..000000000 --- a/test-go/tests/trimatoi_test/main.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func trimAtoi(s string) int { - runes := []rune(s) - for i := range s { - runes[i] = rune(s[i]) - } - var numbers []rune - for _, r := range runes { - if (r >= '0' && r <= '9') || (len(numbers) == 0 && (r) == '-' || r == '+') { - numbers = append(numbers, r) - } - } - if len(numbers) == 0 || (len(numbers) == 1 && (numbers[0] == '-' || numbers[0] == '+')) { - return 0 - } - - res, i, sign := 0, 0, 1 - - if numbers[0] == '-' { - sign = -1 - i++ - } else if numbers[0] == '+' { - i++ - } - for ; i < len(numbers); i++ { - res = res*10 + int(numbers[i]) - '0' - } - - return sign * res -} - -func stringsToTrimAtoi(a []string) []string { - alpha := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789012345678901234567890123456789" - - for index := 0; index < 4; index++ { - s := "" - s += lib.RandStr(lib.RandIntBetween(0, 2), alpha) - x := lib.RandIntBetween(0, 14) - if x <= 4 { - s += "-" - } - s += lib.RandStr(lib.RandIntBetween(0, 10), alpha) - a = append(a, s) - } - return a -} - -func main() { - a := []string{ - "", - "12345", - "str123ing45", - "012 345", - "Hello World!", - "sd+x1fa2W3s4", - "sd-x1fa2W3s4", - "sdx1-fa2W3s4", - lib.RandAlnum(), - } - a = stringsToTrimAtoi(a) - for _, elem := range a { - lib.Challenge("TrimAtoi", student.TrimAtoi, trimAtoi, elem) - } -} - -// TODO: refactor, including the subject diff --git a/test-go/tests/twosum_test/main.go b/test-go/tests/twosum_test/main.go deleted file mode 100644 index ebb106461..000000000 --- a/test-go/tests/twosum_test/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "math/rand" - - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func twoSum(nums []int, target int) []int { - for i := 0; i < len(nums); i++ { - for j := i + 1; j < len(nums); j++ { - if nums[i]+nums[j] == target { - return []int{i, j} - } - } - } - return nil -} - -func main() { - for i := 0; i < 20; i++ { - token := rand.Perm(20) - target := rand.Intn(30) - lib.Challenge("TwoSum", student.TwoSum, twoSum, token, target) - } -} diff --git a/test-go/tests/ultimatedivmod_test/main.go b/test-go/tests/ultimatedivmod_test/main.go deleted file mode 100644 index a55c42b8c..000000000 --- a/test-go/tests/ultimatedivmod_test/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - i := 0 - for i < lib.SliceLen { - a := lib.RandInt() - b := lib.RandInt() - aCopy := a - bCopy := b - div := a / b - mod := a % b - student.UltimateDivMod(&a, &b) - if a != div { - lib.Fatalf("DivMod(%d, %d), a == %d instead of %d", aCopy, bCopy, a, div) - } - if b != mod { - lib.Fatalf("DivMod(%d, %d), b == %d instead of %d", aCopy, bCopy, b, mod) - } - i++ - } -} diff --git a/test-go/tests/ultimatepointone_test/main.go b/test-go/tests/ultimatepointone_test/main.go deleted file mode 100644 index 2e28fc5d0..000000000 --- a/test-go/tests/ultimatepointone_test/main.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - a := 0 - b := &a - n := &b - student.UltimatePointOne(&n) - if a != 1 { - lib.Fatalf("UltimatePointOne(&n), a == %d instead of 1", a) - } -} diff --git a/test-go/tests/union_test/main.go b/test-go/tests/union_test/main.go deleted file mode 100644 index 844bdab23..000000000 --- a/test-go/tests/union_test/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - s1 := lib.RandAlnum() - s2 := strings.Join([]string{lib.RandAlnum(), s1, lib.RandAlnum()}, "") - - args := [][]string{ - {"zpadinton", "paqefwtdjetyiytjneytjoeyjnejeyj"}, - {"ddf6vewg64f", "gtwthgdwthdwfteewhrtag6h4ffdhsd"}, - {""}, - {"rien", "cette phrase ne cache rien"}, - {" this is ", " wait shr"}, - {" more ", "then", "two", "arguments"}, - {s1, s2}, - {lib.RandAlnum(), lib.RandAlnum()}, - } - - for _, v := range args { - lib.ChallengeMain("union", v...) - } -} diff --git a/test-go/tests/uniqueoccurences_test/main.go b/test-go/tests/uniqueoccurences_test/main.go deleted file mode 100644 index 4432908b3..000000000 --- a/test-go/tests/uniqueoccurences_test/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := []string{ - "abbaac", - "ab", - "abcacccazb", - "", - } - - for i := 0; i < 15; i++ { - table = append(table, lib.RandStr(lib.RandIntBetween(5, 10), lib.Lower)) - } - - for _, arg := range table { - lib.ChallengeMain("uniqueoccurences", arg) - } -} diff --git a/test-go/tests/unmatch_test/main.go b/test-go/tests/unmatch_test/main.go deleted file mode 100644 index 610a1bf49..000000000 --- a/test-go/tests/unmatch_test/main.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -// Returns the element of the slice that doesn't have a correspondant pair -func unmatch(elems []int) int { - var quant int - for _, el := range elems { - quant = 0 - for _, v := range elems { - if v == el { - quant++ - } - } - if quant%2 != 0 { - return el - } - } - return -1 -} - -func main() { - i1 := lib.RandIntBetween(-100, 100) - i2 := lib.RandIntBetween(-1000, 1000) - i3 := lib.RandIntBetween(-10, 10) - args := [][]int{ - {1, 1, 2, 3, 4, 3, 4}, - {1, 1, 2, 4, 3, 4, 2, 3, 4}, - {1, 2, 1, 1, 4, 5, 5, 4, 1, 7}, - {1, 2, 3, 4, 5, 6, 7, 8}, - {0, 20, 91, 23, 10, 34}, - {1, 1, 2, 2, 3, 4, 3, 4, 5, 5, 8, 9, 8, 9}, - {i1, i2, i1, i2, i1 + i3, i1 + i3}, - {i1, i2, i1, i2, i1 + i3, i2 - i3}, - } - for _, v := range args { - lib.Challenge("Unmatch", student.Unmatch, unmatch, v) - } -} diff --git a/test-go/tests/volumechanger_test/main.go b/test-go/tests/volumechanger_test/main.go deleted file mode 100644 index c506bbc80..000000000 --- a/test-go/tests/volumechanger_test/main.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - student "student" - - "github.com/01-edu/public/test-go/lib" -) - -func abs(a int) int { - if a < 0 { - return -a - } - return a -} - -func volumechanger(a, b int) int { - return abs(a-b)/5 + abs(a-b)%5/2 + abs(a-b)%5%2 -} - -func main() { - table := [][2]int{ - {50, 43}, - {13, 13}, - {10, 9}, - {5, 9}, - } - for i := 0; i < 15; i++ { - table = append(table, [2]int{ - lib.RandIntBetween(0, 30), - lib.RandIntBetween(0, 100), - }) - } - for _, arg := range table { - lib.Challenge("Volumechanger", student.Volumechanger, volumechanger, arg[0], arg[1]) - } -} diff --git a/test-go/tests/wdmatch_test/main.go b/test-go/tests/wdmatch_test/main.go deleted file mode 100644 index 5b3a78e71..000000000 --- a/test-go/tests/wdmatch_test/main.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "strings" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - table := append(lib.MultRandWords(), - " ", - "faya fgvvfdxcacpolhyghbreda", - "faya fgvvfdxcacpolhyghbred", - "error rrerrrfiiljdfxjyuifrrvcoojh", - "error rrerrrfiiljdfxjyuifrrvcoojrh", - ) - - for _, s := range table { - lib.ChallengeMain("wdmatch", strings.Fields(s)...) - } -} diff --git a/test-go/tests/ztail_test/main.go b/test-go/tests/ztail_test/main.go deleted file mode 100644 index 6f9b42fcb..000000000 --- a/test-go/tests/ztail_test/main.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "io/ioutil" - "os" - - "github.com/01-edu/public/test-go/lib" -) - -func main() { - file1 := "quest8.txt" - file2 := "quest8T.txt" - if err := ioutil.WriteFile(file1, []byte(lib.RandWords()+"\n"), os.ModePerm); err != nil { - panic(err) - } - if err := ioutil.WriteFile(file2, []byte(lib.RandWords()+"\n"), os.ModePerm); err != nil { - panic(err) - } - table := [][]string{ - {"-c", "23", "src/student/ztail/main.go", file1}, - {"-c", "13", "src/student/ztail/main.go", "fjksdsf", file2}, - {"-c", "5", file1, file2}, - {"-c", "1", "fjksdsf"}, - {"-c", "1", file1, file2}, - } - for _, args := range table { - lib.ChallengeMain("ztail", args...) - } -}