From 3e90ae6cc74451837dddf2f5807dedc4a7f28900 Mon Sep 17 00:00:00 2001 From: Xavier Petit <32063953+xpetit@users.noreply.github.com> Date: Mon, 11 May 2020 17:57:20 +0200 Subject: [PATCH] This commit is messy, I merged, moved and modified so many files in a hurry I did not commit all the steps. So we will have to look at the state of the files before and after this PR if we want to understand things. I think it will be better afterwards, except for the tests I broke. --- .../func/createelem/main.go} | 12 ++- .../func/inverttree/main.go} | 31 ++++-- .../func/merge/main.go} | 26 +++-- .../func/reverse/main.go} | 5 - .../func/sametree/main.go} | 30 ++++-- .../func/sortlist/main.go} | 39 ++++++-- tests/go/func/abort/main.go | 26 +++++ tests/go/func/activebits/main.go | 22 +++++ .../addprimesum/correct}/main.go | 0 .../addprimesum/main.go} | 0 .../main.go} | 11 ++- .../main.go} | 15 ++- .../alphamirror/correct}/main.go | 0 .../alphamirror/main.go} | 0 tests/go/func/{test_any.go => any/main.go} | 27 ++++-- .../main.go} | 26 +++-- tests/go/func/{test_atoi.go => atoi/main.go} | 9 +- .../balancedstring/correct}/main.go | 0 .../balancedstring/main.go} | 0 .../{test_basicatoi.go => basicatoi/main.go} | 9 +- .../main.go} | 9 +- .../{test_basicjoin.go => basicjoin/main.go} | 15 +-- .../boolean => func/boolean/correct}/main.go | 0 .../test_boolean.go => func/boolean/main.go} | 0 .../brackets/correct}/main.go | 0 .../brackets/main.go} | 0 .../brainfuck/correct}/main.go | 0 .../brainfuck/main.go} | 0 tests/go/func/capitalize/main.go | 39 ++++++++ .../correct/cat => func/cat/correct}/main.go | 0 .../cat => func/cat/correct}/quest8.txt | 0 .../cat => func/cat/correct}/quest8T.txt | 0 .../go/{prog/test_cat.go => func/cat/main.go} | 0 .../go/func/{test_chunk.go => chunk/main.go} | 23 ++++- .../cleanstr/correct}/main.go | 0 .../cleanstr/main.go} | 0 .../main.go} | 27 ++++-- .../comcheck/correct}/main.go | 0 .../comcheck/main.go} | 0 tests/go/func/common/is.go | 37 ++++++++ .../func/{test_compact.go => compact/main.go} | 17 +++- .../func/{test_compare.go => compare/main.go} | 10 +- .../func/{test_concat.go => concat/main.go} | 12 +-- .../main.go} | 10 +- tests/go/func/correct/abort.go | 10 -- tests/go/func/correct/activebits.go | 10 -- tests/go/func/correct/advancedsortwordarr.go | 9 -- tests/go/func/correct/alphacount.go | 12 --- tests/go/func/correct/any.go | 11 --- tests/go/func/correct/appendrange.go | 16 ---- tests/go/func/correct/atoi.go | 8 -- tests/go/func/correct/basicatoi.go | 8 -- tests/go/func/correct/basicatoi2.go | 8 -- tests/go/func/correct/basicjoin.go | 8 -- tests/go/func/correct/capitalize.go | 21 ----- tests/go/func/correct/chunk.go | 20 ---- tests/go/func/correct/collatzcountdown.go | 20 ---- tests/go/func/correct/compact.go | 14 --- tests/go/func/correct/compare.go | 7 -- tests/go/func/correct/concat.go | 5 - tests/go/func/correct/concatparams.go | 7 -- tests/go/func/correct/countif.go | 12 --- tests/go/func/correct/createelem.go | 9 -- tests/go/func/correct/divmod.go | 6 -- tests/go/func/correct/doppelganger.go | 7 -- tests/go/func/correct/enigma.go | 23 ----- tests/go/func/correct/fib.go | 16 ---- tests/go/func/correct/fibonacci.go | 14 --- tests/go/func/correct/findnextprime.go | 8 -- tests/go/func/correct/findprevprime.go | 24 ----- tests/go/func/correct/firstrune.go | 6 -- tests/go/func/correct/foldint.go | 11 --- tests/go/func/correct/foreach.go | 7 -- tests/go/func/correct/game23.go | 17 ---- tests/go/func/correct/halfcontest.go | 10 -- tests/go/func/correct/index.go | 7 -- tests/go/func/correct/interestingnumber.go | 19 ---- tests/go/func/correct/inverttree.go | 23 ----- tests/go/func/correct/isalpha.go | 12 --- tests/go/func/correct/isanagram.go | 23 ----- tests/go/func/correct/islower.go | 12 --- tests/go/func/correct/isnegative.go | 11 --- tests/go/func/correct/isnumeric.go | 12 --- tests/go/func/correct/isprime.go | 18 ---- tests/go/func/correct/isprintable.go | 12 --- tests/go/func/correct/issorted.go | 20 ---- tests/go/func/correct/isupper.go | 10 -- tests/go/func/correct/iterativefactorial.go | 17 ---- tests/go/func/correct/iterativepower.go | 11 --- tests/go/func/correct/itoa.go | 7 -- tests/go/func/correct/itoabase.go | 14 --- tests/go/func/correct/join.go | 7 -- tests/go/func/correct/lastrune.go | 7 -- tests/go/func/correct/lcm.go | 12 --- tests/go/func/correct/makerange.go | 15 --- tests/go/func/correct/map.go | 19 ---- tests/go/func/correct/max.go | 11 --- tests/go/func/correct/merge.go | 20 ---- tests/go/func/correct/nauuo.go | 28 ------ tests/go/func/correct/nrune.go | 9 -- tests/go/func/correct/pilot.go | 10 -- tests/go/func/correct/pointone.go | 5 - tests/go/func/correct/printchessboard.go | 40 -------- tests/go/func/correct/printnbr.go | 7 -- tests/go/func/correct/printstr.go | 7 -- tests/go/func/correct/printwordstables.go | 9 -- tests/go/func/correct/priorprime.go | 18 ---- tests/go/func/correct/raid1b.go | 42 --------- tests/go/func/correct/raid1c.go | 42 --------- tests/go/func/correct/raid1d.go | 42 --------- tests/go/func/correct/raid1e.go | 42 --------- tests/go/func/correct/reachablenumber.go | 18 ---- tests/go/func/correct/recursivefactorial.go | 17 ---- tests/go/func/correct/recursivepower.go | 10 -- tests/go/func/correct/reduceint.go | 11 --- tests/go/func/correct/reversebits.go | 7 -- tests/go/func/correct/rot14.go | 21 ----- tests/go/func/correct/sametree.go | 24 ----- tests/go/func/correct/slice.go | 42 --------- tests/go/func/correct/sortintegertable.go | 7 -- tests/go/func/correct/sortlist.go | 33 ------- tests/go/func/correct/sortwordarr.go | 7 -- tests/go/func/correct/split.go | 7 -- tests/go/func/correct/splitwhitespaces.go | 7 -- tests/go/func/correct/sqrt.go | 11 --- tests/go/func/correct/strlen.go | 11 --- tests/go/func/correct/strrev.go | 13 --- tests/go/func/correct/swap.go | 5 - tests/go/func/correct/swapbits.go | 5 - tests/go/func/correct/sweetproblem.go | 57 ----------- tests/go/func/correct/tolower.go | 7 -- tests/go/func/correct/toupper.go | 7 -- tests/go/func/correct/trimatoi.go | 31 ------ tests/go/func/correct/twosum.go | 12 --- tests/go/func/correct/ultimatedivmod.go | 7 -- tests/go/func/correct/ultimatepointone.go | 5 - tests/go/func/correct/unmatch.go | 18 ---- tests/go/func/correct/volumechanger.go | 12 --- .../costumeprofit/correct}/main.go | 0 .../costumeprofit/main.go} | 0 .../countdown/correct}/main.go | 0 .../countdown/main.go} | 0 .../func/{test_countif.go => countif/main.go} | 28 ++++-- .../displaya/correct}/main.go | 0 .../displaya/main.go} | 0 .../displayalpham/correct}/main.go | 0 .../displayalpham/main.go} | 0 .../displayalrevm/correct}/main.go | 0 .../displayalrevm/main.go} | 0 .../displayfile/correct}/main.go | 0 .../displayfile/correct}/quest8.txt | 0 .../displayfile/main.go} | 0 .../displayfirstparam/correct}/main.go | 0 .../displayfirstparam/main.go} | 0 .../displaylastparam/correct}/main.go | 0 .../displaylastparam/main.go} | 0 .../displayz/correct}/main.go | 0 .../displayz/main.go} | 0 .../func/{test_divmod.go => divmod/main.go} | 10 +- .../doop => func/doop/correct}/main.go | 0 .../{prog/test_doop.go => func/doop/main.go} | 0 .../main.go} | 10 +- .../eightqueens.go => eightqueens/main.go} | 14 ++- .../func/{test_enigma.go => enigma/main.go} | 30 ++++-- .../expandstr/correct}/main.go | 0 .../expandstr/main.go} | 0 tests/go/func/fib/main.go | 31 ++++++ tests/go/func/fibonacci/main.go | 28 ++++++ .../main.go} | 12 ++- tests/go/func/findprevprime/main.go | 23 +++++ tests/go/func/firstrune/main.go | 21 +++++ .../firstword/correct}/main.go | 0 .../firstword/main.go} | 0 .../fixthemain/correct}/main.go | 0 .../fixthemain/main.go} | 0 .../flags => func/flags/correct}/main.go | 0 .../test_flags.go => func/flags/main.go} | 0 .../func/{test_foldint.go => foldint/main.go} | 14 ++- .../func/{test_foreach.go => foreach/main.go} | 10 +- .../fprime => func/fprime/correct}/main.go | 0 .../test_fprime.go => func/fprime/main.go} | 0 .../func/{test_game23.go => game23/main.go} | 24 +++-- .../correct/gcd => func/gcd/correct}/main.go | 0 .../go/{prog/test_gcd.go => func/gcd/main.go} | 0 .../grouping/correct}/main.go | 0 .../grouping/main.go} | 0 .../main.go} | 17 ++-- .../hello => func/hello/correct}/main.go | 0 .../test_hello.go => func/hello/main.go} | 0 .../hiddenp => func/hiddenp/correct}/main.go | 0 .../test_hiddenp.go => func/hiddenp/main.go} | 0 .../go/func/{test_index.go => index/main.go} | 10 +- .../inter => func/inter/correct}/main.go | 0 .../test_inter.go => func/inter/main.go} | 0 tests/go/func/interestingnumber/main.go | 35 +++++++ .../func/{test_isalpha.go => isalpha/main.go} | 15 ++- .../{test_isanagram.go => isanagram/main.go} | 30 ++++-- .../func/{test_islower.go => islower/main.go} | 5 +- tests/go/func/isnegative/main.go | 27 ++++++ .../{test_isnumeric.go => isnumeric/main.go} | 5 +- .../ispowerof2/correct}/main.go | 0 .../ispowerof2/main.go} | 0 .../func/{test_isprime.go => isprime/main.go} | 5 +- .../main.go} | 14 ++- .../{test_issorted.go => issorted/main.go} | 31 ++++-- .../func/{test_isupper.go => isupper/main.go} | 5 +- tests/go/func/iterativefactorial/main.go | 31 ++++++ .../main.go} | 14 ++- tests/go/func/{test_itoa.go => itoa/main.go} | 10 +- .../{test_itoabase.go => itoabase/main.go} | 15 ++- tests/go/func/{test_join.go => join/main.go} | 10 +- .../{test_lastrune.go => lastrune/main.go} | 14 +-- .../lastword/correct}/main.go | 0 .../lastword/main.go} | 0 tests/go/func/{test_lcm.go => lcm/main.go} | 19 ++-- .../main.go} | 25 +++-- tests/go/func/{test_map.go => map/main.go} | 27 +++++- tests/go/func/{test_max.go => max/main.go} | 14 ++- tests/go/func/nauuo/main.go | 55 +++++++++++ .../nbrconvertalpha/correct}/main.go | 0 .../nbrconvertalpha/main.go} | 0 .../nenokku => func/nenokku/correct}/main.go | 0 .../test_nenokku.go => func/nenokku/main.go} | 0 .../go/func/{test_nrune.go => nrune/main.go} | 12 ++- .../onlya => func/onlya/correct}/main.go | 0 .../test_onlya.go => func/onlya/main.go} | 0 .../onlyz => func/onlyz/correct}/main.go | 0 .../test_onlyz.go => func/onlyz/main.go} | 0 .../options => func/options/correct}/main.go | 0 .../test_options.go => func/options/main.go} | 0 .../paramcount/correct}/main.go | 0 .../paramcount/main.go} | 0 .../piglatin/correct}/main.go | 0 .../piglatin/main.go} | 0 .../point => func/point/correct}/main.go | 0 .../test_point.go => func/point/main.go} | 0 .../{test_pointone.go => pointone/main.go} | 9 +- .../printalphabet/correct}/main.go | 0 .../printalphabet/main.go} | 0 .../printbits/correct}/main.go | 0 .../printbits/main.go} | 0 .../printchessboard/correct}/main.go | 6 +- .../printchessboard/main.go} | 0 .../printcomb.go => printcomb/main.go} | 14 ++- .../printcomb2.go => printcomb2/main.go} | 14 ++- .../printcombn.go => printcombn/main.go} | 17 +++- .../printdigits/correct}/main.go | 0 .../printdigits/main.go} | 0 .../printhex/correct}/main.go | 0 .../printhex/main.go} | 0 .../printmemory.go => printmemory/main.go} | 21 ++++- .../{test_printnbr.go => printnbr/main.go} | 10 +- .../main.go} | 19 +++- .../printparams/correct}/main.go | 0 .../printparams/main.go} | 0 .../printprogramname/correct}/main.go | 0 .../printprogramname/main.go} | 0 .../printrevcomb/correct}/main.go | 0 .../printrevcomb/main.go} | 0 .../printreversealphabet/correct}/main.go | 0 .../printreversealphabet/main.go} | 0 .../{test_printstr.go => printstr/main.go} | 10 +- .../main.go} | 15 +-- tests/go/func/priorprime/main.go | 35 +++++++ .../{correct/raid1a.go => raid1a/main.go} | 35 ++++++- tests/go/func/raid1b/main.go | 71 ++++++++++++++ tests/go/func/raid1c/main.go | 71 ++++++++++++++ tests/go/func/raid1d/main.go | 71 ++++++++++++++ tests/go/func/raid1e/main.go | 71 ++++++++++++++ .../raid2 => func/raid2/correct}/main.go | 0 .../test_raid2.go => func/raid2/main.go} | 0 .../raid3 => func/raid3/correct}/main.go | 0 .../raid3/correct}/raid1aprog/raid1a.go | 0 .../raid3/correct}/raid1bprog/raid1b.go | 0 .../raid3/correct}/raid1cprog/raid1c.go | 0 .../raid3/correct}/raid1dprog/raid1d.go | 0 .../raid3/correct}/raid1eprog/raid1e.go | 0 .../test_raid3.go => func/raid3/main.go} | 0 .../range => func/range/correct}/main.go | 0 .../test_range.go => func/range/main.go} | 0 tests/go/func/reachablenumber/main.go | 35 +++++++ .../rectangle/correct}/main.go | 0 .../rectangle/main.go} | 0 tests/go/func/recursivefactorial/main.go | 31 ++++++ .../main.go} | 13 ++- .../{test_reduceint.go => reduceint/main.go} | 14 ++- .../repeatalpha/correct}/main.go | 0 .../repeatalpha/main.go} | 0 .../main.go} | 9 +- .../reverserange/correct}/main.go | 0 .../reverserange/main.go} | 0 .../reversestrcap/correct}/main.go | 0 .../reversestrcap/main.go} | 0 .../main.go} | 29 +++++- .../revparams/correct}/main.go | 0 .../revparams/main.go} | 0 .../revwstr => func/revwstr/correct}/main.go | 0 .../test_revwstr.go => func/revwstr/main.go} | 0 .../robottoorigin/correct}/main.go | 0 .../robottoorigin/main.go} | 0 .../romannumbers/correct}/main.go | 0 .../romannumbers/main.go} | 0 .../rostring/correct}/main.go | 0 .../rostring/main.go} | 0 .../rot13 => func/rot13/correct}/main.go | 0 .../test_rot13.go => func/rot13/main.go} | 0 tests/go/func/rot14/main.go | 43 +++++++++ .../rotatevowels/correct}/main.go | 0 .../rotatevowels/main.go} | 0 .../rpncalc => func/rpncalc/correct}/main.go | 0 .../test_rpncalc.go => func/rpncalc/main.go} | 0 .../searchreplace/correct}/main.go | 0 .../searchreplace/main.go} | 0 .../go/func/{test_slice.go => slice/main.go} | 49 ++++++++-- .../main.go} | 9 +- .../sortparams/correct}/main.go | 0 .../sortparams/main.go} | 0 .../main.go} | 9 +- .../go/func/{test_split.go => split/main.go} | 8 +- .../main.go} | 8 +- tests/go/func/{test_sqrt.go => sqrt/main.go} | 14 ++- .../func/{test_strlen.go => strlen/main.go} | 18 ++-- tests/go/func/strrev/main.go | 27 ++++++ tests/go/func/{test_swap.go => swap/main.go} | 9 +- .../{test_swapbits.go => swapbits/main.go} | 8 +- tests/go/func/sweetproblem/main.go | 94 +++++++++++++++++++ .../switchcase/correct}/main.go | 0 .../switchcase/main.go} | 0 .../tabmult => func/tabmult/correct}/main.go | 0 .../test_tabmult.go => func/tabmult/main.go} | 0 tests/go/func/test_abort.go | 17 ---- tests/go/func/test_activebits.go | 17 ---- tests/go/func/test_capitalize.go | 23 ----- tests/go/func/test_eightqueens.go | 11 --- tests/go/func/test_fib.go | 20 ---- tests/go/func/test_fibonacci.go | 19 ---- tests/go/func/test_findprevprime.go | 14 --- tests/go/func/test_firstrune.go | 20 ---- tests/go/func/test_interestingnumber.go | 21 ----- tests/go/func/test_isnegative.go | 19 ---- tests/go/func/test_iterativefactorial.go | 22 ----- tests/go/func/test_nauuo.go | 32 ------- tests/go/func/test_printcomb.go | 11 --- tests/go/func/test_printcomb2.go | 11 --- tests/go/func/test_printcombn.go | 14 --- tests/go/func/test_printmemory.go | 22 ----- tests/go/func/test_printnbrinorder.go | 20 ---- tests/go/func/test_priorprime.go | 22 ----- tests/go/func/test_raid1a.go | 32 ------- tests/go/func/test_raid1b.go | 32 ------- tests/go/func/test_raid1c.go | 32 ------- tests/go/func/test_raid1d.go | 32 ------- tests/go/func/test_raid1e.go | 32 ------- tests/go/func/test_reachablenumber.go | 22 ----- tests/go/func/test_recursivefactorial.go | 22 ----- tests/go/func/test_revivethreenums.go | 30 ------ tests/go/func/test_rot14.go | 27 ------ tests/go/func/test_strrev.go | 19 ---- tests/go/func/test_sweetproblem.go | 42 --------- tests/go/func/test_trimatoi.go | 41 -------- tests/go/func/test_twosum.go | 17 ---- .../tetrisoptimizer/correct}/board.go | 0 .../tetrisoptimizer/correct}/main.go | 0 .../correct}/samples/bad00.txt | 0 .../correct}/samples/bad01.txt | 0 .../correct}/samples/bad02.txt | 0 .../correct}/samples/bad03.txt | 0 .../correct}/samples/bad04.txt | 0 .../correct}/samples/badFormat.txt | 0 .../correct}/samples/good_01-1-2-0.00.txt | 0 .../correct}/samples/good_02-1-4-0.00.txt | 0 .../correct}/samples/good_03-2-4-0.00.txt | 0 .../correct}/samples/good_04-6-6-0.00.txt | 0 .../correct}/samples/good_05-21-10-0.00.txt | 0 .../correct}/samples/good_06-22-10-0.00.txt | 0 .../correct}/samples/good_07-26-11-0.00.txt | 0 .../correct}/samples/good_08-24-10-0.03.txt | 0 .../correct}/samples/good_09-11-7-0.07.txt | 0 .../correct}/samples/good_10-12-7-0.52.txt | 0 .../correct}/samples/good_11-12-8-0.83.txt | 0 .../correct}/samples/good_12-19-9-3.40.txt | 0 .../correct}/samples/good_13-23-10-4.72.txt | 0 .../correct}/samples/good_14-15-8-7.34.txt | 0 .../correct}/samples/good_15-26-11-72.22.txt | 0 .../tetrisoptimizer/correct}/solver.go | 0 .../tetrisoptimizer/correct}/tetrimino.go | 0 .../tetrisoptimizer/correct}/validation.go | 0 .../tetrisoptimizer/main.go} | 0 .../func/{test_tolower.go => tolower/main.go} | 10 +- .../func/{test_toupper.go => toupper/main.go} | 10 +- tests/go/func/trimatoi/main.go | 67 +++++++++++++ tests/go/func/twosum/main.go | 26 +++++ .../main.go} | 11 ++- .../main.go} | 9 +- .../union => func/union/correct}/main.go | 0 .../test_union.go => func/union/main.go} | 0 .../uniqueoccurences/correct}/main.go | 0 .../uniqueoccurences/main.go} | 0 .../func/{test_unmatch.go => unmatch/main.go} | 25 +++-- .../main.go} | 19 ++-- .../wdmatch => func/wdmatch/correct}/main.go | 0 .../test_wdmatch.go => func/wdmatch/main.go} | 0 .../ztail => func/ztail/correct}/main.go | 0 .../test_ztail.go => func/ztail/main.go} | 0 tests/go/lib/lib.go | 16 ++-- tests/go/prog/correct/lcm/main.go | 19 ---- tests/go/prog/correct/reversebits/main.go | 14 --- 407 files changed, 1960 insertions(+), 2480 deletions(-) rename tests/go/{func/test_createelem.go => broken/func/createelem/main.go} (87%) rename tests/go/{func/test_inverttree.go => broken/func/inverttree/main.go} (91%) rename tests/go/{func/test_merge.go => broken/func/merge/main.go} (91%) rename tests/go/{func/test_reverse.go => broken/func/reverse/main.go} (97%) rename tests/go/{func/test_sametree.go => broken/func/sametree/main.go} (84%) rename tests/go/{func/test_sortlist.go => broken/func/sortlist/main.go} (81%) create mode 100644 tests/go/func/abort/main.go create mode 100644 tests/go/func/activebits/main.go rename tests/go/{prog/correct/addprimesum => func/addprimesum/correct}/main.go (100%) rename tests/go/{prog/test_addprimesum.go => func/addprimesum/main.go} (100%) rename tests/go/func/{test_advancedsortwordarr.go => advancedsortwordarr/main.go} (77%) rename tests/go/func/{test_alphacount.go => alphacount/main.go} (59%) rename tests/go/{prog/correct/alphamirror => func/alphamirror/correct}/main.go (100%) rename tests/go/{prog/test_alphamirror.go => func/alphamirror/main.go} (100%) rename tests/go/func/{test_any.go => any/main.go} (65%) rename tests/go/func/{test_makerange.go => appendrange/main.go} (71%) rename tests/go/func/{test_atoi.go => atoi/main.go} (78%) rename tests/go/{prog/correct/balancedstring => func/balancedstring/correct}/main.go (100%) rename tests/go/{prog/test_balancedstring.go => func/balancedstring/main.go} (100%) rename tests/go/func/{test_basicatoi.go => basicatoi/main.go} (69%) rename tests/go/func/{test_basicatoi2.go => basicatoi2/main.go} (72%) rename tests/go/func/{test_basicjoin.go => basicjoin/main.go} (64%) rename tests/go/{prog/correct/boolean => func/boolean/correct}/main.go (100%) rename tests/go/{prog/test_boolean.go => func/boolean/main.go} (100%) rename tests/go/{prog/correct/brackets => func/brackets/correct}/main.go (100%) rename tests/go/{prog/test_brackets.go => func/brackets/main.go} (100%) rename tests/go/{prog/correct/brainfuck => func/brainfuck/correct}/main.go (100%) rename tests/go/{prog/test_brainfuck.go => func/brainfuck/main.go} (100%) create mode 100644 tests/go/func/capitalize/main.go rename tests/go/{prog/correct/cat => func/cat/correct}/main.go (100%) rename tests/go/{prog/correct/cat => func/cat/correct}/quest8.txt (100%) rename tests/go/{prog/correct/cat => func/cat/correct}/quest8T.txt (100%) rename tests/go/{prog/test_cat.go => func/cat/main.go} (100%) rename tests/go/func/{test_chunk.go => chunk/main.go} (61%) rename tests/go/{prog/correct/cleanstr => func/cleanstr/correct}/main.go (100%) rename tests/go/{prog/test_cleanstr.go => func/cleanstr/main.go} (100%) rename tests/go/func/{test_collatzcountdown.go => collatzcountdown/main.go} (52%) rename tests/go/{prog/correct/comcheck => func/comcheck/correct}/main.go (100%) rename tests/go/{prog/test_comcheck.go => func/comcheck/main.go} (100%) create mode 100644 tests/go/func/common/is.go rename tests/go/func/{test_compact.go => compact/main.go} (82%) rename tests/go/func/{test_compare.go => compare/main.go} (84%) rename tests/go/func/{test_concat.go => concat/main.go} (70%) rename tests/go/func/{test_concatparams.go => concatparams/main.go} (60%) delete mode 100644 tests/go/func/correct/abort.go delete mode 100644 tests/go/func/correct/activebits.go delete mode 100644 tests/go/func/correct/advancedsortwordarr.go delete mode 100644 tests/go/func/correct/alphacount.go delete mode 100644 tests/go/func/correct/any.go delete mode 100644 tests/go/func/correct/appendrange.go delete mode 100644 tests/go/func/correct/atoi.go delete mode 100644 tests/go/func/correct/basicatoi.go delete mode 100644 tests/go/func/correct/basicatoi2.go delete mode 100644 tests/go/func/correct/basicjoin.go delete mode 100644 tests/go/func/correct/capitalize.go delete mode 100644 tests/go/func/correct/chunk.go delete mode 100644 tests/go/func/correct/collatzcountdown.go delete mode 100644 tests/go/func/correct/compact.go delete mode 100644 tests/go/func/correct/compare.go delete mode 100644 tests/go/func/correct/concat.go delete mode 100644 tests/go/func/correct/concatparams.go delete mode 100644 tests/go/func/correct/countif.go delete mode 100644 tests/go/func/correct/createelem.go delete mode 100644 tests/go/func/correct/divmod.go delete mode 100644 tests/go/func/correct/doppelganger.go delete mode 100644 tests/go/func/correct/enigma.go delete mode 100644 tests/go/func/correct/fib.go delete mode 100644 tests/go/func/correct/fibonacci.go delete mode 100644 tests/go/func/correct/findnextprime.go delete mode 100644 tests/go/func/correct/findprevprime.go delete mode 100644 tests/go/func/correct/firstrune.go delete mode 100644 tests/go/func/correct/foldint.go delete mode 100644 tests/go/func/correct/foreach.go delete mode 100644 tests/go/func/correct/game23.go delete mode 100644 tests/go/func/correct/halfcontest.go delete mode 100644 tests/go/func/correct/index.go delete mode 100644 tests/go/func/correct/interestingnumber.go delete mode 100644 tests/go/func/correct/inverttree.go delete mode 100644 tests/go/func/correct/isalpha.go delete mode 100644 tests/go/func/correct/isanagram.go delete mode 100644 tests/go/func/correct/islower.go delete mode 100644 tests/go/func/correct/isnegative.go delete mode 100644 tests/go/func/correct/isnumeric.go delete mode 100644 tests/go/func/correct/isprime.go delete mode 100644 tests/go/func/correct/isprintable.go delete mode 100644 tests/go/func/correct/issorted.go delete mode 100644 tests/go/func/correct/isupper.go delete mode 100644 tests/go/func/correct/iterativefactorial.go delete mode 100644 tests/go/func/correct/iterativepower.go delete mode 100644 tests/go/func/correct/itoa.go delete mode 100644 tests/go/func/correct/itoabase.go delete mode 100644 tests/go/func/correct/join.go delete mode 100644 tests/go/func/correct/lastrune.go delete mode 100644 tests/go/func/correct/lcm.go delete mode 100644 tests/go/func/correct/makerange.go delete mode 100644 tests/go/func/correct/map.go delete mode 100644 tests/go/func/correct/max.go delete mode 100644 tests/go/func/correct/merge.go delete mode 100644 tests/go/func/correct/nauuo.go delete mode 100644 tests/go/func/correct/nrune.go delete mode 100644 tests/go/func/correct/pilot.go delete mode 100644 tests/go/func/correct/pointone.go delete mode 100644 tests/go/func/correct/printchessboard.go delete mode 100644 tests/go/func/correct/printnbr.go delete mode 100644 tests/go/func/correct/printstr.go delete mode 100644 tests/go/func/correct/printwordstables.go delete mode 100644 tests/go/func/correct/priorprime.go delete mode 100644 tests/go/func/correct/raid1b.go delete mode 100644 tests/go/func/correct/raid1c.go delete mode 100644 tests/go/func/correct/raid1d.go delete mode 100644 tests/go/func/correct/raid1e.go delete mode 100644 tests/go/func/correct/reachablenumber.go delete mode 100644 tests/go/func/correct/recursivefactorial.go delete mode 100644 tests/go/func/correct/recursivepower.go delete mode 100644 tests/go/func/correct/reduceint.go delete mode 100644 tests/go/func/correct/reversebits.go delete mode 100644 tests/go/func/correct/rot14.go delete mode 100644 tests/go/func/correct/sametree.go delete mode 100644 tests/go/func/correct/slice.go delete mode 100644 tests/go/func/correct/sortintegertable.go delete mode 100644 tests/go/func/correct/sortlist.go delete mode 100644 tests/go/func/correct/sortwordarr.go delete mode 100644 tests/go/func/correct/split.go delete mode 100644 tests/go/func/correct/splitwhitespaces.go delete mode 100644 tests/go/func/correct/sqrt.go delete mode 100644 tests/go/func/correct/strlen.go delete mode 100644 tests/go/func/correct/strrev.go delete mode 100644 tests/go/func/correct/swap.go delete mode 100644 tests/go/func/correct/swapbits.go delete mode 100644 tests/go/func/correct/sweetproblem.go delete mode 100644 tests/go/func/correct/tolower.go delete mode 100644 tests/go/func/correct/toupper.go delete mode 100644 tests/go/func/correct/trimatoi.go delete mode 100644 tests/go/func/correct/twosum.go delete mode 100644 tests/go/func/correct/ultimatedivmod.go delete mode 100644 tests/go/func/correct/ultimatepointone.go delete mode 100644 tests/go/func/correct/unmatch.go delete mode 100644 tests/go/func/correct/volumechanger.go rename tests/go/{prog/correct/costumeprofit => func/costumeprofit/correct}/main.go (100%) rename tests/go/{prog/test_costumeprofit.go => func/costumeprofit/main.go} (100%) rename tests/go/{prog/correct/countdown => func/countdown/correct}/main.go (100%) rename tests/go/{prog/test_countdown.go => func/countdown/main.go} (100%) rename tests/go/func/{test_countif.go => countif/main.go} (65%) rename tests/go/{prog/correct/displaya => func/displaya/correct}/main.go (100%) rename tests/go/{prog/test_displaya.go => func/displaya/main.go} (100%) rename tests/go/{prog/correct/displayalpham => func/displayalpham/correct}/main.go (100%) rename tests/go/{prog/test_displayalpham.go => func/displayalpham/main.go} (100%) rename tests/go/{prog/correct/displayalrevm => func/displayalrevm/correct}/main.go (100%) rename tests/go/{prog/test_displayalrevm.go => func/displayalrevm/main.go} (100%) rename tests/go/{prog/correct/displayfile => func/displayfile/correct}/main.go (100%) rename tests/go/{prog/correct/displayfile => func/displayfile/correct}/quest8.txt (100%) rename tests/go/{prog/test_displayfile.go => func/displayfile/main.go} (100%) rename tests/go/{prog/correct/displayfirstparam => func/displayfirstparam/correct}/main.go (100%) rename tests/go/{prog/test_displayfirstparam.go => func/displayfirstparam/main.go} (100%) rename tests/go/{prog/correct/displaylastparam => func/displaylastparam/correct}/main.go (100%) rename tests/go/{prog/test_displaylastparam.go => func/displaylastparam/main.go} (100%) rename tests/go/{prog/correct/displayz => func/displayz/correct}/main.go (100%) rename tests/go/{prog/test_displayz.go => func/displayz/main.go} (100%) rename tests/go/func/{test_divmod.go => divmod/main.go} (81%) rename tests/go/{prog/correct/doop => func/doop/correct}/main.go (100%) rename tests/go/{prog/test_doop.go => func/doop/main.go} (100%) rename tests/go/func/{test_doppelganger.go => doppelganger/main.go} (82%) rename tests/go/func/{correct/eightqueens.go => eightqueens/main.go} (93%) rename tests/go/func/{test_enigma.go => enigma/main.go} (62%) rename tests/go/{prog/correct/expandstr => func/expandstr/correct}/main.go (100%) rename tests/go/{prog/test_expandstr.go => func/expandstr/main.go} (100%) create mode 100644 tests/go/func/fib/main.go create mode 100644 tests/go/func/fibonacci/main.go rename tests/go/func/{test_findnextprime.go => findnextprime/main.go} (58%) create mode 100644 tests/go/func/findprevprime/main.go create mode 100644 tests/go/func/firstrune/main.go rename tests/go/{prog/correct/firstword => func/firstword/correct}/main.go (100%) rename tests/go/{prog/test_firstword.go => func/firstword/main.go} (100%) rename tests/go/{prog/correct/fixthemain => func/fixthemain/correct}/main.go (100%) rename tests/go/{prog/test_fixthemain.go => func/fixthemain/main.go} (100%) rename tests/go/{prog/correct/flags => func/flags/correct}/main.go (100%) rename tests/go/{prog/test_flags.go => func/flags/main.go} (100%) rename tests/go/func/{test_foldint.go => foldint/main.go} (81%) rename tests/go/func/{test_foreach.go => foreach/main.go} (83%) rename tests/go/{prog/correct/fprime => func/fprime/correct}/main.go (100%) rename tests/go/{prog/test_fprime.go => func/fprime/main.go} (100%) rename tests/go/func/{test_game23.go => game23/main.go} (69%) rename tests/go/{prog/correct/gcd => func/gcd/correct}/main.go (100%) rename tests/go/{prog/test_gcd.go => func/gcd/main.go} (100%) rename tests/go/{prog/correct/grouping => func/grouping/correct}/main.go (100%) rename tests/go/{prog/test_grouping.go => func/grouping/main.go} (100%) rename tests/go/func/{test_halfcontest.go => halfcontest/main.go} (60%) rename tests/go/{prog/correct/hello => func/hello/correct}/main.go (100%) rename tests/go/{prog/test_hello.go => func/hello/main.go} (100%) rename tests/go/{prog/correct/hiddenp => func/hiddenp/correct}/main.go (100%) rename tests/go/{prog/test_hiddenp.go => func/hiddenp/main.go} (100%) rename tests/go/func/{test_index.go => index/main.go} (86%) rename tests/go/{prog/correct/inter => func/inter/correct}/main.go (100%) rename tests/go/{prog/test_inter.go => func/inter/main.go} (100%) create mode 100644 tests/go/func/interestingnumber/main.go rename tests/go/func/{test_isalpha.go => isalpha/main.go} (64%) rename tests/go/func/{test_isanagram.go => isanagram/main.go} (60%) rename tests/go/func/{test_islower.go => islower/main.go} (90%) create mode 100644 tests/go/func/isnegative/main.go rename tests/go/func/{test_isnumeric.go => isnumeric/main.go} (87%) rename tests/go/{prog/correct/ispowerof2 => func/ispowerof2/correct}/main.go (100%) rename tests/go/{prog/test_ispowerof2.go => func/ispowerof2/main.go} (100%) rename tests/go/func/{test_isprime.go => isprime/main.go} (74%) rename tests/go/func/{test_isprintable.go => isprintable/main.go} (81%) rename tests/go/func/{test_issorted.go => issorted/main.go} (75%) rename tests/go/func/{test_isupper.go => isupper/main.go} (90%) create mode 100644 tests/go/func/iterativefactorial/main.go rename tests/go/func/{test_iterativepower.go => iterativepower/main.go} (58%) rename tests/go/func/{test_itoa.go => itoa/main.go} (54%) rename tests/go/func/{test_itoabase.go => itoabase/main.go} (62%) rename tests/go/func/{test_join.go => join/main.go} (72%) rename tests/go/func/{test_lastrune.go => lastrune/main.go} (54%) rename tests/go/{prog/correct/lastword => func/lastword/correct}/main.go (100%) rename tests/go/{prog/test_lastword.go => func/lastword/main.go} (100%) rename tests/go/func/{test_lcm.go => lcm/main.go} (50%) rename tests/go/func/{test_appendrange.go => makerange/main.go} (72%) rename tests/go/func/{test_map.go => map/main.go} (52%) rename tests/go/func/{test_max.go => max/main.go} (56%) create mode 100644 tests/go/func/nauuo/main.go rename tests/go/{prog/correct/nbrconvertalpha => func/nbrconvertalpha/correct}/main.go (100%) rename tests/go/{prog/test_nbrconvertalpha.go => func/nbrconvertalpha/main.go} (100%) rename tests/go/{prog/correct/nenokku => func/nenokku/correct}/main.go (100%) rename tests/go/{prog/test_nenokku.go => func/nenokku/main.go} (100%) rename tests/go/func/{test_nrune.go => nrune/main.go} (78%) rename tests/go/{prog/correct/onlya => func/onlya/correct}/main.go (100%) rename tests/go/{prog/test_onlya.go => func/onlya/main.go} (100%) rename tests/go/{prog/correct/onlyz => func/onlyz/correct}/main.go (100%) rename tests/go/{prog/test_onlyz.go => func/onlyz/main.go} (100%) rename tests/go/{prog/correct/options => func/options/correct}/main.go (100%) rename tests/go/{prog/test_options.go => func/options/main.go} (100%) rename tests/go/{prog/correct/paramcount => func/paramcount/correct}/main.go (100%) rename tests/go/{prog/test_paramcount.go => func/paramcount/main.go} (100%) rename tests/go/{prog/correct/piglatin => func/piglatin/correct}/main.go (100%) rename tests/go/{prog/test_piglatin.go => func/piglatin/main.go} (100%) rename tests/go/{prog/correct/point => func/point/correct}/main.go (100%) rename tests/go/{prog/test_point.go => func/point/main.go} (100%) rename tests/go/func/{test_pointone.go => pointone/main.go} (71%) rename tests/go/{prog/correct/printalphabet => func/printalphabet/correct}/main.go (100%) rename tests/go/{prog/test_printalphabet.go => func/printalphabet/main.go} (100%) rename tests/go/{prog/correct/printbits => func/printbits/correct}/main.go (100%) rename tests/go/{prog/test_printbits.go => func/printbits/main.go} (100%) rename tests/go/{prog/correct/printchessboard => func/printchessboard/correct}/main.go (80%) rename tests/go/{prog/test_printchessboard.go => func/printchessboard/main.go} (100%) rename tests/go/func/{correct/printcomb.go => printcomb/main.go} (62%) rename tests/go/func/{correct/printcomb2.go => printcomb2/main.go} (56%) rename tests/go/func/{correct/printcombn.go => printcombn/main.go} (79%) rename tests/go/{prog/correct/printdigits => func/printdigits/correct}/main.go (100%) rename tests/go/{prog/test_printdigits.go => func/printdigits/main.go} (100%) rename tests/go/{prog/correct/printhex => func/printhex/correct}/main.go (100%) rename tests/go/{prog/test_printhex.go => func/printhex/main.go} (100%) rename tests/go/func/{correct/printmemory.go => printmemory/main.go} (70%) rename tests/go/func/{test_printnbr.go => printnbr/main.go} (59%) rename tests/go/func/{correct/printnbrinorder.go => printnbrinorder/main.go} (56%) rename tests/go/{prog/correct/printparams => func/printparams/correct}/main.go (100%) rename tests/go/{prog/test_printparams.go => func/printparams/main.go} (100%) rename tests/go/{prog/correct/printprogramname => func/printprogramname/correct}/main.go (100%) rename tests/go/{prog/test_printprogramname.go => func/printprogramname/main.go} (100%) rename tests/go/{prog/correct/printrevcomb => func/printrevcomb/correct}/main.go (100%) rename tests/go/{prog/test_printrevcomb.go => func/printrevcomb/main.go} (100%) rename tests/go/{prog/correct/printreversealphabet => func/printreversealphabet/correct}/main.go (100%) rename tests/go/{prog/test_printreversealphabet.go => func/printreversealphabet/main.go} (100%) rename tests/go/func/{test_printstr.go => printstr/main.go} (58%) rename tests/go/func/{test_printwordstables.go => printwordstables/main.go} (52%) create mode 100644 tests/go/func/priorprime/main.go rename tests/go/func/{correct/raid1a.go => raid1a/main.go} (50%) create mode 100644 tests/go/func/raid1b/main.go create mode 100644 tests/go/func/raid1c/main.go create mode 100644 tests/go/func/raid1d/main.go create mode 100644 tests/go/func/raid1e/main.go rename tests/go/{prog/correct/raid2 => func/raid2/correct}/main.go (100%) rename tests/go/{prog/test_raid2.go => func/raid2/main.go} (100%) rename tests/go/{prog/correct/raid3 => func/raid3/correct}/main.go (100%) rename tests/go/{prog/correct/raid3 => func/raid3/correct}/raid1aprog/raid1a.go (100%) rename tests/go/{prog/correct/raid3 => func/raid3/correct}/raid1bprog/raid1b.go (100%) rename tests/go/{prog/correct/raid3 => func/raid3/correct}/raid1cprog/raid1c.go (100%) rename tests/go/{prog/correct/raid3 => func/raid3/correct}/raid1dprog/raid1d.go (100%) rename tests/go/{prog/correct/raid3 => func/raid3/correct}/raid1eprog/raid1e.go (100%) rename tests/go/{prog/test_raid3.go => func/raid3/main.go} (100%) rename tests/go/{prog/correct/range => func/range/correct}/main.go (100%) rename tests/go/{prog/test_range.go => func/range/main.go} (100%) create mode 100644 tests/go/func/reachablenumber/main.go rename tests/go/{prog/correct/rectangle => func/rectangle/correct}/main.go (100%) rename tests/go/{prog/test_rectangle.go => func/rectangle/main.go} (100%) create mode 100644 tests/go/func/recursivefactorial/main.go rename tests/go/func/{test_recursivepower.go => recursivepower/main.go} (60%) rename tests/go/func/{test_reduceint.go => reduceint/main.go} (75%) rename tests/go/{prog/correct/repeatalpha => func/repeatalpha/correct}/main.go (100%) rename tests/go/{prog/test_repeatalpha.go => func/repeatalpha/main.go} (100%) rename tests/go/func/{test_reversebits.go => reversebits/main.go} (78%) rename tests/go/{prog/correct/reverserange => func/reverserange/correct}/main.go (100%) rename tests/go/{prog/test_reverserange.go => func/reverserange/main.go} (100%) rename tests/go/{prog/correct/reversestrcap => func/reversestrcap/correct}/main.go (100%) rename tests/go/{prog/test_reversestrcap.go => func/reversestrcap/main.go} (100%) rename tests/go/func/{correct/revivethreenums.go => revivethreenums/main.go} (50%) rename tests/go/{prog/correct/revparams => func/revparams/correct}/main.go (100%) rename tests/go/{prog/test_revparams.go => func/revparams/main.go} (100%) rename tests/go/{prog/correct/revwstr => func/revwstr/correct}/main.go (100%) rename tests/go/{prog/test_revwstr.go => func/revwstr/main.go} (100%) rename tests/go/{prog/correct/robottoorigin => func/robottoorigin/correct}/main.go (100%) rename tests/go/{prog/test_robottoorigin.go => func/robottoorigin/main.go} (100%) rename tests/go/{prog/correct/romannumbers => func/romannumbers/correct}/main.go (100%) rename tests/go/{prog/test_romannumbers.go => func/romannumbers/main.go} (100%) rename tests/go/{prog/correct/rostring => func/rostring/correct}/main.go (100%) rename tests/go/{prog/test_rostring.go => func/rostring/main.go} (100%) rename tests/go/{prog/correct/rot13 => func/rot13/correct}/main.go (100%) rename tests/go/{prog/test_rot13.go => func/rot13/main.go} (100%) create mode 100644 tests/go/func/rot14/main.go rename tests/go/{prog/correct/rotatevowels => func/rotatevowels/correct}/main.go (100%) rename tests/go/{prog/test_rotatevowels.go => func/rotatevowels/main.go} (100%) rename tests/go/{prog/correct/rpncalc => func/rpncalc/correct}/main.go (100%) rename tests/go/{prog/test_rpncalc.go => func/rpncalc/main.go} (100%) rename tests/go/{prog/correct/searchreplace => func/searchreplace/correct}/main.go (100%) rename tests/go/{prog/test_searchreplace.go => func/searchreplace/main.go} (100%) rename tests/go/func/{test_slice.go => slice/main.go} (56%) rename tests/go/func/{test_sortintegertable.go => sortintegertable/main.go} (84%) rename tests/go/{prog/correct/sortparams => func/sortparams/correct}/main.go (100%) rename tests/go/{prog/test_sortparams.go => func/sortparams/main.go} (100%) rename tests/go/func/{test_sortwordarr.go => sortwordarr/main.go} (88%) rename tests/go/func/{test_split.go => split/main.go} (82%) rename tests/go/func/{test_splitwhitespaces.go => splitwhitespaces/main.go} (66%) rename tests/go/func/{test_sqrt.go => sqrt/main.go} (56%) rename tests/go/func/{test_strlen.go => strlen/main.go} (68%) create mode 100644 tests/go/func/strrev/main.go rename tests/go/func/{test_swap.go => swap/main.go} (84%) rename tests/go/func/{test_swapbits.go => swapbits/main.go} (84%) create mode 100644 tests/go/func/sweetproblem/main.go rename tests/go/{prog/correct/switchcase => func/switchcase/correct}/main.go (100%) rename tests/go/{prog/test_switchcase.go => func/switchcase/main.go} (100%) rename tests/go/{prog/correct/tabmult => func/tabmult/correct}/main.go (100%) rename tests/go/{prog/test_tabmult.go => func/tabmult/main.go} (100%) delete mode 100644 tests/go/func/test_abort.go delete mode 100644 tests/go/func/test_activebits.go delete mode 100644 tests/go/func/test_capitalize.go delete mode 100644 tests/go/func/test_eightqueens.go delete mode 100644 tests/go/func/test_fib.go delete mode 100644 tests/go/func/test_fibonacci.go delete mode 100644 tests/go/func/test_findprevprime.go delete mode 100644 tests/go/func/test_firstrune.go delete mode 100644 tests/go/func/test_interestingnumber.go delete mode 100644 tests/go/func/test_isnegative.go delete mode 100644 tests/go/func/test_iterativefactorial.go delete mode 100644 tests/go/func/test_nauuo.go delete mode 100644 tests/go/func/test_printcomb.go delete mode 100644 tests/go/func/test_printcomb2.go delete mode 100644 tests/go/func/test_printcombn.go delete mode 100644 tests/go/func/test_printmemory.go delete mode 100644 tests/go/func/test_printnbrinorder.go delete mode 100644 tests/go/func/test_priorprime.go delete mode 100644 tests/go/func/test_raid1a.go delete mode 100644 tests/go/func/test_raid1b.go delete mode 100644 tests/go/func/test_raid1c.go delete mode 100644 tests/go/func/test_raid1d.go delete mode 100644 tests/go/func/test_raid1e.go delete mode 100644 tests/go/func/test_reachablenumber.go delete mode 100644 tests/go/func/test_recursivefactorial.go delete mode 100644 tests/go/func/test_revivethreenums.go delete mode 100644 tests/go/func/test_rot14.go delete mode 100644 tests/go/func/test_strrev.go delete mode 100644 tests/go/func/test_sweetproblem.go delete mode 100644 tests/go/func/test_trimatoi.go delete mode 100644 tests/go/func/test_twosum.go rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/board.go (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/main.go (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/bad00.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/bad01.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/bad02.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/bad03.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/bad04.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/badFormat.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_01-1-2-0.00.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_02-1-4-0.00.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_03-2-4-0.00.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_04-6-6-0.00.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_05-21-10-0.00.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_06-22-10-0.00.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_07-26-11-0.00.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_08-24-10-0.03.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_09-11-7-0.07.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_10-12-7-0.52.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_11-12-8-0.83.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_12-19-9-3.40.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_13-23-10-4.72.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_14-15-8-7.34.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/samples/good_15-26-11-72.22.txt (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/solver.go (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/tetrimino.go (100%) rename tests/go/{prog/correct/tetrisoptimizer => func/tetrisoptimizer/correct}/validation.go (100%) rename tests/go/{prog/test_tetrisoptimizer.go => func/tetrisoptimizer/main.go} (100%) rename tests/go/func/{test_tolower.go => tolower/main.go} (54%) rename tests/go/func/{test_toupper.go => toupper/main.go} (56%) create mode 100644 tests/go/func/trimatoi/main.go create mode 100644 tests/go/func/twosum/main.go rename tests/go/func/{test_ultimatedivmod.go => ultimatedivmod/main.go} (80%) rename tests/go/func/{test_ultimatepointone.go => ultimatepointone/main.go} (71%) rename tests/go/{prog/correct/union => func/union/correct}/main.go (100%) rename tests/go/{prog/test_union.go => func/union/main.go} (100%) rename tests/go/{prog/correct/uniqueoccurences => func/uniqueoccurences/correct}/main.go (100%) rename tests/go/{prog/test_uniqueoccurences.go => func/uniqueoccurences/main.go} (100%) rename tests/go/func/{test_unmatch.go => unmatch/main.go} (66%) rename tests/go/func/{test_volumechanger.go => volumechanger/main.go} (50%) rename tests/go/{prog/correct/wdmatch => func/wdmatch/correct}/main.go (100%) rename tests/go/{prog/test_wdmatch.go => func/wdmatch/main.go} (100%) rename tests/go/{prog/correct/ztail => func/ztail/correct}/main.go (100%) rename tests/go/{prog/test_ztail.go => func/ztail/main.go} (100%) delete mode 100644 tests/go/prog/correct/lcm/main.go delete mode 100644 tests/go/prog/correct/reversebits/main.go diff --git a/tests/go/func/test_createelem.go b/tests/go/broken/func/createelem/main.go similarity index 87% rename from tests/go/func/test_createelem.go rename to tests/go/broken/func/createelem/main.go index cae82df6..c54cc600 100644 --- a/tests/go/func/test_createelem.go +++ b/tests/go/broken/func/createelem/main.go @@ -1,10 +1,12 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +type Node struct { + Data int +} + +func CreateElem(n *Node, value int) { + n.Data = value +} // the structs from the other packages // struct just for the first exercise diff --git a/tests/go/func/test_inverttree.go b/tests/go/broken/func/inverttree/main.go similarity index 91% rename from tests/go/func/test_inverttree.go rename to tests/go/broken/func/inverttree/main.go index 7ee667c1..86044985 100644 --- a/tests/go/func/test_inverttree.go +++ b/tests/go/broken/func/inverttree/main.go @@ -1,14 +1,27 @@ -package main +package correct -import ( - "fmt" - "io" - "math/rand" - "strconv" +type TNode struct { + Val int + Left *TNode + Right *TNode +} + +func Invert(root *TNode) { + if root != nil { + temp := root.Left + root.Left = root.Right + root.Right = temp + + Invert(root.Left) + Invert(root.Right) + } +} + +func InvertTree(root *TNode) *TNode { + Invert(root) + return root +} - "../lib" - "./correct" -) type stuNode = TNode type solNode = correct.TNode diff --git a/tests/go/func/test_merge.go b/tests/go/broken/func/merge/main.go similarity index 91% rename from tests/go/func/test_merge.go rename to tests/go/broken/func/merge/main.go index 226838a7..a8f7eefb 100644 --- a/tests/go/func/test_merge.go +++ b/tests/go/broken/func/merge/main.go @@ -1,12 +1,24 @@ -package main +package correct -import ( - "math/rand" - "strconv" +type TreeNodeM struct { + Left *TreeNodeM + Val int + Right *TreeNodeM +} + +func MergeTrees(t1 *TreeNodeM, t2 *TreeNodeM) *TreeNodeM { + if t1 == nil { + return t2 + } + if t2 == nil { + return t1 + } + t1.Val += t2.Val + t1.Left = MergeTrees(t1.Left, t2.Left) + t1.Right = MergeTrees(t1.Right, t2.Right) + return t1 +} - "../lib" - "./correct" -) type stuTreeNode = TreeNodeM type solTreeNode = correct.TreeNodeM diff --git a/tests/go/func/test_reverse.go b/tests/go/broken/func/reverse/main.go similarity index 97% rename from tests/go/func/test_reverse.go rename to tests/go/broken/func/reverse/main.go index 8ef9ce68..77cbf9b3 100644 --- a/tests/go/func/test_reverse.go +++ b/tests/go/broken/func/reverse/main.go @@ -1,9 +1,4 @@ -package main -import ( - "../lib" - "./correct" -) type stuNode = NodeAddL type solNode = correct.NodeAddL diff --git a/tests/go/func/test_sametree.go b/tests/go/broken/func/sametree/main.go similarity index 84% rename from tests/go/func/test_sametree.go rename to tests/go/broken/func/sametree/main.go index 1417f5af..1378d79e 100644 --- a/tests/go/func/test_sametree.go +++ b/tests/go/broken/func/sametree/main.go @@ -1,12 +1,28 @@ -package main +package correct -import ( - "math/rand" - "strconv" +type TreeNodeL struct { + Left *TreeNodeL + Val int + Right *TreeNodeL +} + +func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool { + if p == nil && q == nil { + return true + } + return checkIfEq(p, q) +} + +func checkIfEq(t1 *TreeNodeL, t2 *TreeNodeL) bool { + if t1 == nil && t2 == nil { + return true + } + if t1 == nil || t2 == nil { + return false + } + return t1.Val == t2.Val && checkIfEq(t1.Right, t2.Right) && checkIfEq(t1.Left, t2.Left) +} - "../lib" - "./correct" -) type stuTreeNode = TreeNodeL type solTreeNode = correct.TreeNodeL diff --git a/tests/go/func/test_sortlist.go b/tests/go/broken/func/sortlist/main.go similarity index 81% rename from tests/go/func/test_sortlist.go rename to tests/go/broken/func/sortlist/main.go index 6cfa143c..a7eefbd2 100644 --- a/tests/go/func/test_sortlist.go +++ b/tests/go/broken/func/sortlist/main.go @@ -1,12 +1,37 @@ -package main +package correct -import ( - "strconv" +type Nodelist struct { + Data int + Next *Nodelist +} + +func SortList(l *Nodelist, cmp func(a, b int) bool) *Nodelist { + head := l + if head == nil { + return nil + } + head.Next = SortList(head.Next, cmp) + + if head.Next != nil && cmp(head.Data, head.Next.Data) { + head = moveValue(head, cmp) + } + return head +} + +func moveValue(l *Nodelist, cmp func(a, b int) bool) *Nodelist { + p := l + n := l.Next + ret := n + + for n != nil && cmp(l.Data, n.Data) { + p = n + n = n.Next + } + p.Next = l + l.Next = n + return ret +} - "../lib" - "./correct" - "./student" -) func listToString4(n *correct.Nodelist) (res string) { it := n diff --git a/tests/go/func/abort/main.go b/tests/go/func/abort/main.go new file mode 100644 index 00000000..198d4cec --- /dev/null +++ b/tests/go/func/abort/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "sort" + + "github.com/01-edu/public/tests/go/lib" + + "./student" +) + +// 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/tests/go/func/activebits/main.go b/tests/go/func/activebits/main.go new file mode 100644 index 00000000..02fa1725 --- /dev/null +++ b/tests/go/func/activebits/main.go @@ -0,0 +1,22 @@ +package main + +import "./student" + +// 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 = 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/tests/go/prog/correct/addprimesum/main.go b/tests/go/func/addprimesum/correct/main.go similarity index 100% rename from tests/go/prog/correct/addprimesum/main.go rename to tests/go/func/addprimesum/correct/main.go diff --git a/tests/go/prog/test_addprimesum.go b/tests/go/func/addprimesum/main.go similarity index 100% rename from tests/go/prog/test_addprimesum.go rename to tests/go/func/addprimesum/main.go diff --git a/tests/go/func/test_advancedsortwordarr.go b/tests/go/func/advancedsortwordarr/main.go similarity index 77% rename from tests/go/func/test_advancedsortwordarr.go rename to tests/go/func/advancedsortwordarr/main.go index c7c62cad..41e05f13 100644 --- a/tests/go/func/test_advancedsortwordarr.go +++ b/tests/go/func/advancedsortwordarr/main.go @@ -2,13 +2,18 @@ package main import ( "reflect" + "sort" "strings" - "../lib" - "./correct" "./student" ) +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"}} @@ -23,7 +28,7 @@ func main() { copy(cp_sol, org) copy(cp_stu, org) - correct.AdvancedSortWordArr(cp_sol, strings.Compare) + advancedSortWordArr(cp_sol, strings.Compare) student.AdvancedSortWordArr(cp_stu, strings.Compare) if !reflect.DeepEqual(cp_stu, cp_sol) { diff --git a/tests/go/func/test_alphacount.go b/tests/go/func/alphacount/main.go similarity index 59% rename from tests/go/func/test_alphacount.go rename to tests/go/func/alphacount/main.go index 018a1c4d..30e21732 100644 --- a/tests/go/func/test_alphacount.go +++ b/tests/go/func/alphacount/main.go @@ -1,11 +1,20 @@ package main import ( - "../lib" - "./correct" + "unicode" + "./student" ) +func alphaCount(s string) (i int) { + for _, r := range s { + if unicode.IsLetter(r) { + i++ + } + } + return i +} + func main() { table := []string{ " ", @@ -18,6 +27,6 @@ func main() { } for _, arg := range table { - lib.Challenge("AlphaCount", student.AlphaCount, correct.AlphaCount, arg) + lib.Challenge("AlphaCount", student.AlphaCount, alphaCount, arg) } } diff --git a/tests/go/prog/correct/alphamirror/main.go b/tests/go/func/alphamirror/correct/main.go similarity index 100% rename from tests/go/prog/correct/alphamirror/main.go rename to tests/go/func/alphamirror/correct/main.go diff --git a/tests/go/prog/test_alphamirror.go b/tests/go/func/alphamirror/main.go similarity index 100% rename from tests/go/prog/test_alphamirror.go rename to tests/go/func/alphamirror/main.go diff --git a/tests/go/func/test_any.go b/tests/go/func/any/main.go similarity index 65% rename from tests/go/func/test_any.go rename to tests/go/func/any/main.go index 953406fe..f61cc05a 100644 --- a/tests/go/func/test_any.go +++ b/tests/go/func/any/main.go @@ -1,13 +1,22 @@ package main import ( - "../lib" - "./correct" + "../common" "./student" ) +func any(f func(string) bool, arr []string) bool { + for _, el := range arr { + if f(el) { + return true + } + } + + return false +} + func main() { - functions := []func(string) bool{correct.IsNumeric, correct.IsLower, correct.IsUpper} + functions := []func(string) bool{common.IsNumeric, common.IsLower, common.IsUpper} type node struct { f func(string) bool @@ -25,36 +34,36 @@ func main() { } for i := 0; i < 5; i++ { table = append(table, node{ - f: correct.IsNumeric, + f: common.IsNumeric, a: lib.MultRandDigit(), }) } for i := 0; i < 5; i++ { table = append(table, node{ - f: correct.IsLower, + f: common.IsLower, a: lib.MultRandLower(), }) } for i := 0; i < 5; i++ { table = append(table, node{ - f: correct.IsUpper, + f: common.IsUpper, a: lib.MultRandUpper(), }) } table = append(table, node{ - f: correct.IsNumeric, + f: common.IsNumeric, a: []string{"Hello", "how", "are", "you"}, }, node{ - f: correct.IsNumeric, + f: common.IsNumeric, a: []string{"This", "is", "4", "you"}, }, ) for _, arg := range table { - lib.Challenge("Any", student.Any, correct.Any, arg.f, arg.a) + lib.Challenge("Any", student.Any, any, arg.f, arg.a) } } diff --git a/tests/go/func/test_makerange.go b/tests/go/func/appendrange/main.go similarity index 71% rename from tests/go/func/test_makerange.go rename to tests/go/func/appendrange/main.go index d5156a24..3ba1b06b 100644 --- a/tests/go/func/test_makerange.go +++ b/tests/go/func/appendrange/main.go @@ -1,17 +1,27 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +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 @@ -24,6 +34,7 @@ func main() { } table = append(table, val) } + // 15 random pairs of ints with ||invalid range|| for i := 0; i < 15; i++ { minVal := lib.RandIntBetween(-10000000, 1000000) @@ -41,7 +52,8 @@ func main() { node{min: 5, max: 10}, node{min: 10, max: 5}, ) + for _, arg := range table { - lib.Challenge("MakeRange", student.MakeRange, correct.MakeRange, arg.min, arg.max) + lib.Challenge("AppendRange", student.AppendRange, appendRange, arg.min, arg.max) } } diff --git a/tests/go/func/test_atoi.go b/tests/go/func/atoi/main.go similarity index 78% rename from tests/go/func/test_atoi.go rename to tests/go/func/atoi/main.go index bea07a12..7880b39a 100644 --- a/tests/go/func/test_atoi.go +++ b/tests/go/func/atoi/main.go @@ -3,11 +3,14 @@ package main import ( "strconv" - "../lib" - "./correct" "./student" ) +func atoi(s string) int { + n, _ := strconv.Atoi(s) + return n +} + func main() { table := make([]string, 30) for i := range table { @@ -32,6 +35,6 @@ func main() { "123a45", ) for _, arg := range table { - lib.Challenge("Atoi", student.Atoi, correct.Atoi, arg) + lib.Challenge("Atoi", student.Atoi, atoi, arg) } } diff --git a/tests/go/prog/correct/balancedstring/main.go b/tests/go/func/balancedstring/correct/main.go similarity index 100% rename from tests/go/prog/correct/balancedstring/main.go rename to tests/go/func/balancedstring/correct/main.go diff --git a/tests/go/prog/test_balancedstring.go b/tests/go/func/balancedstring/main.go similarity index 100% rename from tests/go/prog/test_balancedstring.go rename to tests/go/func/balancedstring/main.go diff --git a/tests/go/func/test_basicatoi.go b/tests/go/func/basicatoi/main.go similarity index 69% rename from tests/go/func/test_basicatoi.go rename to tests/go/func/basicatoi/main.go index 1d92c44c..52834dee 100644 --- a/tests/go/func/test_basicatoi.go +++ b/tests/go/func/basicatoi/main.go @@ -3,11 +3,14 @@ package main import ( "strconv" - "../lib" - "./correct" "./student" ) +func basicAtoi(s string) int { + n, _ := strconv.Atoi(s) + return n +} + func main() { table := make([]string, 30) for i := range table { @@ -22,6 +25,6 @@ func main() { "000000", ) for _, arg := range table { - lib.Challenge("BasicAtoi", student.BasicAtoi, correct.BasicAtoi, arg) + lib.Challenge("BasicAtoi", student.BasicAtoi, basicAtoi, arg) } } diff --git a/tests/go/func/test_basicatoi2.go b/tests/go/func/basicatoi2/main.go similarity index 72% rename from tests/go/func/test_basicatoi2.go rename to tests/go/func/basicatoi2/main.go index 763b3346..22349181 100644 --- a/tests/go/func/test_basicatoi2.go +++ b/tests/go/func/basicatoi2/main.go @@ -3,11 +3,14 @@ package main import ( "strconv" - "../lib" - "./correct" "./student" ) +func basicAtoi2(s string) int { + n, _ := strconv.Atoi(s) + return n +} + func main() { table := make([]string, 30) for i := range table { @@ -26,6 +29,6 @@ func main() { "123.0", ) for _, arg := range table { - lib.Challenge("BasicAtoi2", student.BasicAtoi2, correct.BasicAtoi2, arg) + lib.Challenge("BasicAtoi2", student.BasicAtoi2, basicAtoi2, arg) } } diff --git a/tests/go/func/test_basicjoin.go b/tests/go/func/basicjoin/main.go similarity index 64% rename from tests/go/func/test_basicjoin.go rename to tests/go/func/basicjoin/main.go index a66e1f69..6d01a1f8 100644 --- a/tests/go/func/test_basicjoin.go +++ b/tests/go/func/basicjoin/main.go @@ -1,10 +1,13 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +func basicJoin(a []string) (b string) { + for _, s := range a { + b += s + } + return b +} func main() { table := [][]string{} @@ -17,6 +20,6 @@ func main() { []string{"Hello!", " How are you?", "well and yourself?"}, ) for _, arg := range table { - lib.Challenge("BasicJoin", student.BasicJoin, correct.BasicJoin, arg) + lib.Challenge("BasicJoin", student.BasicJoin, basicJoin, arg) } } diff --git a/tests/go/prog/correct/boolean/main.go b/tests/go/func/boolean/correct/main.go similarity index 100% rename from tests/go/prog/correct/boolean/main.go rename to tests/go/func/boolean/correct/main.go diff --git a/tests/go/prog/test_boolean.go b/tests/go/func/boolean/main.go similarity index 100% rename from tests/go/prog/test_boolean.go rename to tests/go/func/boolean/main.go diff --git a/tests/go/prog/correct/brackets/main.go b/tests/go/func/brackets/correct/main.go similarity index 100% rename from tests/go/prog/correct/brackets/main.go rename to tests/go/func/brackets/correct/main.go diff --git a/tests/go/prog/test_brackets.go b/tests/go/func/brackets/main.go similarity index 100% rename from tests/go/prog/test_brackets.go rename to tests/go/func/brackets/main.go diff --git a/tests/go/prog/correct/brainfuck/main.go b/tests/go/func/brainfuck/correct/main.go similarity index 100% rename from tests/go/prog/correct/brainfuck/main.go rename to tests/go/func/brainfuck/correct/main.go diff --git a/tests/go/prog/test_brainfuck.go b/tests/go/func/brainfuck/main.go similarity index 100% rename from tests/go/prog/test_brainfuck.go rename to tests/go/func/brainfuck/main.go diff --git a/tests/go/func/capitalize/main.go b/tests/go/func/capitalize/main.go new file mode 100644 index 00000000..614fe1f5 --- /dev/null +++ b/tests/go/func/capitalize/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "strings" + "unicode" + + "./student" +) + +func capitalize(s string) string { + r := []rune(strings.ToLower(s)) + + if unicode.IsLower(r[0]) { + r[0] = unicode.ToUpper(r[0]) + } + + for i := 1; i < len(r); i++ { + if !unicode.Is(unicode.ASCII_Hex_Digit, r[i-1]) && unicode.IsLower(r[i]) { + 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/tests/go/prog/correct/cat/main.go b/tests/go/func/cat/correct/main.go similarity index 100% rename from tests/go/prog/correct/cat/main.go rename to tests/go/func/cat/correct/main.go diff --git a/tests/go/prog/correct/cat/quest8.txt b/tests/go/func/cat/correct/quest8.txt similarity index 100% rename from tests/go/prog/correct/cat/quest8.txt rename to tests/go/func/cat/correct/quest8.txt diff --git a/tests/go/prog/correct/cat/quest8T.txt b/tests/go/func/cat/correct/quest8T.txt similarity index 100% rename from tests/go/prog/correct/cat/quest8T.txt rename to tests/go/func/cat/correct/quest8T.txt diff --git a/tests/go/prog/test_cat.go b/tests/go/func/cat/main.go similarity index 100% rename from tests/go/prog/test_cat.go rename to tests/go/func/cat/main.go diff --git a/tests/go/func/test_chunk.go b/tests/go/func/chunk/main.go similarity index 61% rename from tests/go/func/test_chunk.go rename to tests/go/func/chunk/main.go index 18e97a26..432848d9 100644 --- a/tests/go/func/test_chunk.go +++ b/tests/go/func/chunk/main.go @@ -1,11 +1,28 @@ package main import ( - "../lib" - "./correct" + "fmt" + "./student" ) +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[:len(a)]) + } + fmt.Println(result) +} + func randomSize() []int { randSlice := []int{} for i := 0; i <= lib.RandIntBetween(0, 20); i++ { @@ -36,6 +53,6 @@ func main() { ch: 0, }) for _, args := range table { - lib.Challenge("Chunk", student.Chunk, correct.Chunk, args.slice, args.ch) + lib.Challenge("Chunk", student.Chunk, chunk, args.slice, args.ch) } } diff --git a/tests/go/prog/correct/cleanstr/main.go b/tests/go/func/cleanstr/correct/main.go similarity index 100% rename from tests/go/prog/correct/cleanstr/main.go rename to tests/go/func/cleanstr/correct/main.go diff --git a/tests/go/prog/test_cleanstr.go b/tests/go/func/cleanstr/main.go similarity index 100% rename from tests/go/prog/test_cleanstr.go rename to tests/go/func/cleanstr/main.go diff --git a/tests/go/func/test_collatzcountdown.go b/tests/go/func/collatzcountdown/main.go similarity index 52% rename from tests/go/func/test_collatzcountdown.go rename to tests/go/func/collatzcountdown/main.go index be3b9121..37b49624 100644 --- a/tests/go/func/test_collatzcountdown.go +++ b/tests/go/func/collatzcountdown/main.go @@ -1,10 +1,25 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +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 := []int{lib.RandIntBetween(-6, 20)} @@ -14,6 +29,6 @@ func main() { } for _, v := range args { - lib.Challenge("CollatzCountdown", student.CollatzCountdown, correct.CollatzCountdown, v) + lib.Challenge("CollatzCountdown", student.CollatzCountdown, collatzCountdown, v) } } diff --git a/tests/go/prog/correct/comcheck/main.go b/tests/go/func/comcheck/correct/main.go similarity index 100% rename from tests/go/prog/correct/comcheck/main.go rename to tests/go/func/comcheck/correct/main.go diff --git a/tests/go/prog/test_comcheck.go b/tests/go/func/comcheck/main.go similarity index 100% rename from tests/go/prog/test_comcheck.go rename to tests/go/func/comcheck/main.go diff --git a/tests/go/func/common/is.go b/tests/go/func/common/is.go new file mode 100644 index 00000000..af9acc50 --- /dev/null +++ b/tests/go/func/common/is.go @@ -0,0 +1,37 @@ +package common + +import ( + "math/big" + "unicode" +) + +func IsNumeric(s string) bool { + for _, r := range s { + if !unicode.IsDigit(r) { + return false + } + } + return true +} + +func IsLower(s string) bool { + for _, r := range s { + if !unicode.IsLower(r) { + return false + } + } + return true +} + +func IsUpper(s string) bool { + for _, r := range s { + if !(r >= 'A' && r <= 'Z') { + return false + } + } + return true +} + +func IsPrime(i int) bool { + return big.NewInt(int64(i)).ProbablyPrime(0) +} diff --git a/tests/go/func/test_compact.go b/tests/go/func/compact/main.go similarity index 82% rename from tests/go/func/test_compact.go rename to tests/go/func/compact/main.go index f2353980..befbb5b5 100644 --- a/tests/go/func/test_compact.go +++ b/tests/go/func/compact/main.go @@ -3,11 +3,22 @@ package main import ( "reflect" - "../lib" - "./correct" "./student" ) +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", "", ""}} @@ -33,7 +44,7 @@ func main() { copy(sli_sol, v) copy(sli_stu, v) - sol_size := correct.Compact(&sli_sol) + sol_size := compact(&sli_sol) stu_size := student.Compact(&sli_stu) if !reflect.DeepEqual(sli_stu, sli_sol) { diff --git a/tests/go/func/test_compare.go b/tests/go/func/compare/main.go similarity index 84% rename from tests/go/func/test_compare.go rename to tests/go/func/compare/main.go index c9d81535..6e914a35 100644 --- a/tests/go/func/test_compare.go +++ b/tests/go/func/compare/main.go @@ -1,11 +1,15 @@ package main import ( - "../lib" - "./correct" + "strings" + "./student" ) +func compare(a, b string) int { + return strings.Compare(a, b) +} + func main() { type node struct { s string @@ -44,6 +48,6 @@ func main() { ) for _, arg := range table { - lib.Challenge("Compare", student.Compare, correct.Compare, arg.s, arg.toCompare) + lib.Challenge("Compare", student.Compare, compare, arg.s, arg.toCompare) } } diff --git a/tests/go/func/test_concat.go b/tests/go/func/concat/main.go similarity index 70% rename from tests/go/func/test_concat.go rename to tests/go/func/concat/main.go index 2d014914..3154b1f6 100644 --- a/tests/go/func/test_concat.go +++ b/tests/go/func/concat/main.go @@ -1,10 +1,10 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +func concat(a, b string) string { + return a + b +} func main() { table := [][]string{} @@ -18,6 +18,6 @@ func main() { []string{"Hello!", " How are you?"}, ) for _, arg := range table { - lib.Challenge("Concat", student.Concat, correct.Concat, arg[0], arg[1]) + lib.Challenge("Concat", student.Concat, concat, arg[0], arg[1]) } } diff --git a/tests/go/func/test_concatparams.go b/tests/go/func/concatparams/main.go similarity index 60% rename from tests/go/func/test_concatparams.go rename to tests/go/func/concatparams/main.go index c76e728c..79ec69e1 100644 --- a/tests/go/func/test_concatparams.go +++ b/tests/go/func/concatparams/main.go @@ -1,11 +1,15 @@ package main import ( - "../lib" - "./correct" + "strings" + "./student" ) +func concatParams(args []string) string { + return strings.Join(args, "\n") +} + func main() { table := [][]string{{"Hello", "how", "are", "you?"}} @@ -14,6 +18,6 @@ func main() { table = append(table, lib.MultRandASCII()) } for _, arg := range table { - lib.Challenge("ConcatParams", student.ConcatParams, correct.ConcatParams, arg) + lib.Challenge("ConcatParams", student.ConcatParams, concatParams, arg) } } diff --git a/tests/go/func/correct/abort.go b/tests/go/func/correct/abort.go deleted file mode 100644 index 248f5b8f..00000000 --- a/tests/go/func/correct/abort.go +++ /dev/null @@ -1,10 +0,0 @@ -package correct - -import "sort" - -// 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] -} diff --git a/tests/go/func/correct/activebits.go b/tests/go/func/correct/activebits.go deleted file mode 100644 index f909c536..00000000 --- a/tests/go/func/correct/activebits.go +++ /dev/null @@ -1,10 +0,0 @@ -package correct - -// 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 = n / 2 { - total += n % 2 - } - total += n - return -} diff --git a/tests/go/func/correct/advancedsortwordarr.go b/tests/go/func/correct/advancedsortwordarr.go deleted file mode 100644 index 05c01734..00000000 --- a/tests/go/func/correct/advancedsortwordarr.go +++ /dev/null @@ -1,9 +0,0 @@ -package correct - -import "sort" - -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 - }) -} diff --git a/tests/go/func/correct/alphacount.go b/tests/go/func/correct/alphacount.go deleted file mode 100644 index 84d942cd..00000000 --- a/tests/go/func/correct/alphacount.go +++ /dev/null @@ -1,12 +0,0 @@ -package correct - -import "unicode" - -func AlphaCount(s string) (i int) { - for _, r := range s { - if unicode.IsLetter(r) { - i++ - } - } - return i -} diff --git a/tests/go/func/correct/any.go b/tests/go/func/correct/any.go deleted file mode 100644 index b108de72..00000000 --- a/tests/go/func/correct/any.go +++ /dev/null @@ -1,11 +0,0 @@ -package correct - -func Any(f func(string) bool, arr []string) bool { - for _, el := range arr { - if f(el) { - return true - } - } - - return false -} diff --git a/tests/go/func/correct/appendrange.go b/tests/go/func/correct/appendrange.go deleted file mode 100644 index af43bbcc..00000000 --- a/tests/go/func/correct/appendrange.go +++ /dev/null @@ -1,16 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/atoi.go b/tests/go/func/correct/atoi.go deleted file mode 100644 index 03874724..00000000 --- a/tests/go/func/correct/atoi.go +++ /dev/null @@ -1,8 +0,0 @@ -package correct - -import "strconv" - -func Atoi(s string) int { - n, _ := strconv.Atoi(s) - return n -} diff --git a/tests/go/func/correct/basicatoi.go b/tests/go/func/correct/basicatoi.go deleted file mode 100644 index a91f8947..00000000 --- a/tests/go/func/correct/basicatoi.go +++ /dev/null @@ -1,8 +0,0 @@ -package correct - -import "strconv" - -func BasicAtoi(s string) int { - n, _ := strconv.Atoi(s) - return n -} diff --git a/tests/go/func/correct/basicatoi2.go b/tests/go/func/correct/basicatoi2.go deleted file mode 100644 index b45995df..00000000 --- a/tests/go/func/correct/basicatoi2.go +++ /dev/null @@ -1,8 +0,0 @@ -package correct - -import "strconv" - -func BasicAtoi2(s string) int { - n, _ := strconv.Atoi(s) - return n -} diff --git a/tests/go/func/correct/basicjoin.go b/tests/go/func/correct/basicjoin.go deleted file mode 100644 index eec0d95f..00000000 --- a/tests/go/func/correct/basicjoin.go +++ /dev/null @@ -1,8 +0,0 @@ -package correct - -func BasicJoin(a []string) (b string) { - for _, s := range a { - b += s - } - return b -} diff --git a/tests/go/func/correct/capitalize.go b/tests/go/func/correct/capitalize.go deleted file mode 100644 index 26091b17..00000000 --- a/tests/go/func/correct/capitalize.go +++ /dev/null @@ -1,21 +0,0 @@ -package correct - -import ( - "strings" - "unicode" -) - -func Capitalize(s string) string { - r := []rune(strings.ToLower(s)) - - if unicode.IsLower(r[0]) { - r[0] = unicode.ToUpper(r[0]) - } - - for i := 1; i < len(r); i++ { - if !unicode.Is(unicode.ASCII_Hex_Digit, r[i-1]) && unicode.IsLower(r[i]) { - r[i] = unicode.ToUpper(r[i]) - } - } - return string(r) -} diff --git a/tests/go/func/correct/chunk.go b/tests/go/func/correct/chunk.go deleted file mode 100644 index 17f229f2..00000000 --- a/tests/go/func/correct/chunk.go +++ /dev/null @@ -1,20 +0,0 @@ -package correct - -import "fmt" - -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[:len(a)]) - } - fmt.Println(result) -} diff --git a/tests/go/func/correct/collatzcountdown.go b/tests/go/func/correct/collatzcountdown.go deleted file mode 100644 index ec538bc1..00000000 --- a/tests/go/func/correct/collatzcountdown.go +++ /dev/null @@ -1,20 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/compact.go b/tests/go/func/correct/compact.go deleted file mode 100644 index caaea44f..00000000 --- a/tests/go/func/correct/compact.go +++ /dev/null @@ -1,14 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/compare.go b/tests/go/func/correct/compare.go deleted file mode 100644 index 3767df43..00000000 --- a/tests/go/func/correct/compare.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "strings" - -func Compare(a, b string) int { - return strings.Compare(a, b) -} diff --git a/tests/go/func/correct/concat.go b/tests/go/func/correct/concat.go deleted file mode 100644 index dc47e9b8..00000000 --- a/tests/go/func/correct/concat.go +++ /dev/null @@ -1,5 +0,0 @@ -package correct - -func Concat(a, b string) string { - return a + b -} diff --git a/tests/go/func/correct/concatparams.go b/tests/go/func/correct/concatparams.go deleted file mode 100644 index b2aadd6d..00000000 --- a/tests/go/func/correct/concatparams.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "strings" - -func ConcatParams(args []string) string { - return strings.Join(args, "\n") -} diff --git a/tests/go/func/correct/countif.go b/tests/go/func/correct/countif.go deleted file mode 100644 index d756aed6..00000000 --- a/tests/go/func/correct/countif.go +++ /dev/null @@ -1,12 +0,0 @@ -package correct - -func CountIf(f func(string) bool, arr []string) int { - counter := 0 - for _, el := range arr { - if f(el) { - counter++ - } - } - - return counter -} diff --git a/tests/go/func/correct/createelem.go b/tests/go/func/correct/createelem.go deleted file mode 100644 index 64cb0d6f..00000000 --- a/tests/go/func/correct/createelem.go +++ /dev/null @@ -1,9 +0,0 @@ -package correct - -type Node struct { - Data int -} - -func CreateElem(n *Node, value int) { - n.Data = value -} diff --git a/tests/go/func/correct/divmod.go b/tests/go/func/correct/divmod.go deleted file mode 100644 index 7ccf7b1b..00000000 --- a/tests/go/func/correct/divmod.go +++ /dev/null @@ -1,6 +0,0 @@ -package correct - -func DivMod(a, b int, div, mod *int) { - *div = a / b - *mod = a % b -} diff --git a/tests/go/func/correct/doppelganger.go b/tests/go/func/correct/doppelganger.go deleted file mode 100644 index 8711186e..00000000 --- a/tests/go/func/correct/doppelganger.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "strings" - -func DoppelGanger(s, substr string) int { - return strings.LastIndex(s, substr) -} diff --git a/tests/go/func/correct/enigma.go b/tests/go/func/correct/enigma.go deleted file mode 100644 index 64827485..00000000 --- a/tests/go/func/correct/enigma.go +++ /dev/null @@ -1,23 +0,0 @@ -package correct - -// this function will put a in c; c in d; d in b and b in a -func Enigma(a ***int, b *int, c *******int, d ****int) { - valc := *******c - *******c = ***a - vald := ****d - ****d = valc - valb := *b - *b = vald - ***a = valb -} - -// Helper function used in the test for checking the function Enigma() -func Decript(a ***int, b *int, c *******int, d ****int) { - vala := ***a - ***a = *******c - valb := *b - *b = vala - vald := ****d - ****d = valb - *******c = vald -} diff --git a/tests/go/func/correct/fib.go b/tests/go/func/correct/fib.go deleted file mode 100644 index c788cde5..00000000 --- a/tests/go/func/correct/fib.go +++ /dev/null @@ -1,16 +0,0 @@ -package correct - -func Fib(n int) int { - if n <= 0 { - return 0 - } - t1 := 0 - t2 := 1 - for i := 2; i <= n; i++ { - t1 += t2 - tmp := t1 - t1 = t2 - t2 = tmp - } - return t2 -} diff --git a/tests/go/func/correct/fibonacci.go b/tests/go/func/correct/fibonacci.go deleted file mode 100644 index 9dd6bc23..00000000 --- a/tests/go/func/correct/fibonacci.go +++ /dev/null @@ -1,14 +0,0 @@ -package correct - -func Fibonacci(value int) int { - if value < 0 { - return -1 - } - if value == 0 { - return 0 - } - if value == 1 { - return 1 - } - return Fibonacci(value-1) + Fibonacci(value-2) -} diff --git a/tests/go/func/correct/findnextprime.go b/tests/go/func/correct/findnextprime.go deleted file mode 100644 index 42a6fa89..00000000 --- a/tests/go/func/correct/findnextprime.go +++ /dev/null @@ -1,8 +0,0 @@ -package correct - -func FindNextPrime(nb int) int { - if isPrime(nb) { - return nb - } - return FindNextPrime(nb + 1) -} diff --git a/tests/go/func/correct/findprevprime.go b/tests/go/func/correct/findprevprime.go deleted file mode 100644 index 5fbab881..00000000 --- a/tests/go/func/correct/findprevprime.go +++ /dev/null @@ -1,24 +0,0 @@ -package correct - -func isPrime(nb int) bool { - if nb <= 0 || nb == 1 { - return false - } - - for i := 2; i <= nb/2; i++ { - if nb%i == 0 { - return false - } - } - return true -} - -func FindPrevPrime(nb int) int { - if nb < 2 { - return 0 - } - if isPrime(nb) { - return nb - } - return FindPrevPrime(nb - 1) -} diff --git a/tests/go/func/correct/firstrune.go b/tests/go/func/correct/firstrune.go deleted file mode 100644 index 1125939d..00000000 --- a/tests/go/func/correct/firstrune.go +++ /dev/null @@ -1,6 +0,0 @@ -package correct - -func FirstRune(s string) rune { - runes := []rune(s) - return runes[0] -} diff --git a/tests/go/func/correct/foldint.go b/tests/go/func/correct/foldint.go deleted file mode 100644 index a9d42418..00000000 --- a/tests/go/func/correct/foldint.go +++ /dev/null @@ -1,11 +0,0 @@ -package correct - -import "fmt" - -func FoldInt(f func(int, int) int, a []int, n int) { - result := n - for _, v := range a { - result = f(result, v) - } - fmt.Println(result) -} diff --git a/tests/go/func/correct/foreach.go b/tests/go/func/correct/foreach.go deleted file mode 100644 index 89465cc1..00000000 --- a/tests/go/func/correct/foreach.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -func ForEach(f func(int), a []int) { - for _, el := range a { - f(el) - } -} diff --git a/tests/go/func/correct/game23.go b/tests/go/func/correct/game23.go deleted file mode 100644 index 2a383c75..00000000 --- a/tests/go/func/correct/game23.go +++ /dev/null @@ -1,17 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/halfcontest.go b/tests/go/func/correct/halfcontest.go deleted file mode 100644 index 159b8b45..00000000 --- a/tests/go/func/correct/halfcontest.go +++ /dev/null @@ -1,10 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/index.go b/tests/go/func/correct/index.go deleted file mode 100644 index baa47ebb..00000000 --- a/tests/go/func/correct/index.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "strings" - -func Index(s string, substr string) int { - return strings.Index(s, substr) -} diff --git a/tests/go/func/correct/interestingnumber.go b/tests/go/func/correct/interestingnumber.go deleted file mode 100644 index 179b83bc..00000000 --- a/tests/go/func/correct/interestingnumber.go +++ /dev/null @@ -1,19 +0,0 @@ -package correct - -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++ - } -} diff --git a/tests/go/func/correct/inverttree.go b/tests/go/func/correct/inverttree.go deleted file mode 100644 index 3a36460d..00000000 --- a/tests/go/func/correct/inverttree.go +++ /dev/null @@ -1,23 +0,0 @@ -package correct - -type TNode struct { - Val int - Left *TNode - Right *TNode -} - -func Invert(root *TNode) { - if root != nil { - temp := root.Left - root.Left = root.Right - root.Right = temp - - Invert(root.Left) - Invert(root.Right) - } -} - -func InvertTree(root *TNode) *TNode { - Invert(root) - return root -} diff --git a/tests/go/func/correct/isalpha.go b/tests/go/func/correct/isalpha.go deleted file mode 100644 index a7c52170..00000000 --- a/tests/go/func/correct/isalpha.go +++ /dev/null @@ -1,12 +0,0 @@ -package correct - -import "unicode" - -func IsAlpha(s string) bool { - for _, r := range s { - if !unicode.Is(unicode.Hex_Digit, r) { - return false - } - } - return true -} diff --git a/tests/go/func/correct/isanagram.go b/tests/go/func/correct/isanagram.go deleted file mode 100644 index 6e11fb99..00000000 --- a/tests/go/func/correct/isanagram.go +++ /dev/null @@ -1,23 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/islower.go b/tests/go/func/correct/islower.go deleted file mode 100644 index e351ac8c..00000000 --- a/tests/go/func/correct/islower.go +++ /dev/null @@ -1,12 +0,0 @@ -package correct - -import "unicode" - -func IsLower(s string) bool { - for _, r := range s { - if !unicode.IsLower(r) { - return false - } - } - return true -} diff --git a/tests/go/func/correct/isnegative.go b/tests/go/func/correct/isnegative.go deleted file mode 100644 index ba8db97d..00000000 --- a/tests/go/func/correct/isnegative.go +++ /dev/null @@ -1,11 +0,0 @@ -package correct - -import "fmt" - -func IsNegative(n int) { - if n < 0 { - fmt.Println("T") - } else { - fmt.Println("F") - } -} diff --git a/tests/go/func/correct/isnumeric.go b/tests/go/func/correct/isnumeric.go deleted file mode 100644 index 6adb267b..00000000 --- a/tests/go/func/correct/isnumeric.go +++ /dev/null @@ -1,12 +0,0 @@ -package correct - -import "unicode" - -func IsNumeric(s string) bool { - for _, r := range s { - if !unicode.IsDigit(r) { - return false - } - } - return true -} diff --git a/tests/go/func/correct/isprime.go b/tests/go/func/correct/isprime.go deleted file mode 100644 index aadae4cd..00000000 --- a/tests/go/func/correct/isprime.go +++ /dev/null @@ -1,18 +0,0 @@ -package correct - -import "math" - -func IsPrime(value int) bool { - if value < 2 { - return false - } - limit := int(math.Floor(math.Sqrt(float64(value)))) - i := 2 - for i <= limit { - if value%i == 0 { - return false - } - i++ - } - return true -} diff --git a/tests/go/func/correct/isprintable.go b/tests/go/func/correct/isprintable.go deleted file mode 100644 index c92e209a..00000000 --- a/tests/go/func/correct/isprintable.go +++ /dev/null @@ -1,12 +0,0 @@ -package correct - -import "unicode" - -func IsPrintable(s string) bool { - for _, r := range s { - if !unicode.IsPrint(r) { - return false - } - } - return true -} diff --git a/tests/go/func/correct/issorted.go b/tests/go/func/correct/issorted.go deleted file mode 100644 index a10c0d6c..00000000 --- a/tests/go/func/correct/issorted.go +++ /dev/null @@ -1,20 +0,0 @@ -package correct - -func IsSorted(f func(int, int) int, arr []int) bool { - ascendingOrdered := true - descendingOrdered := true - - for i := 1; i < len(arr); i++ { - if !(f(arr[i-1], arr[i]) >= 0) { - ascendingOrdered = false - } - } - - for i := 1; i < len(arr); i++ { - if !(f(arr[i-1], arr[i]) <= 0) { - descendingOrdered = false - } - } - - return ascendingOrdered || descendingOrdered -} diff --git a/tests/go/func/correct/isupper.go b/tests/go/func/correct/isupper.go deleted file mode 100644 index b686c5b3..00000000 --- a/tests/go/func/correct/isupper.go +++ /dev/null @@ -1,10 +0,0 @@ -package correct - -func IsUpper(s string) bool { - for _, r := range s { - if !(r >= 'A' && r <= 'Z') { - return false - } - } - return true -} diff --git a/tests/go/func/correct/iterativefactorial.go b/tests/go/func/correct/iterativefactorial.go deleted file mode 100644 index 4c90b6b2..00000000 --- a/tests/go/func/correct/iterativefactorial.go +++ /dev/null @@ -1,17 +0,0 @@ -package correct - -import "math/bits" - -func IterativeFactorial(nb int) int { - limit := 12 - if bits.UintSize == 64 { - limit = 20 - } - if nb < 0 || nb > limit { - return 0 - } - if nb == 0 { - return 1 - } - return nb * IterativeFactorial(nb-1) -} diff --git a/tests/go/func/correct/iterativepower.go b/tests/go/func/correct/iterativepower.go deleted file mode 100644 index 09749bdc..00000000 --- a/tests/go/func/correct/iterativepower.go +++ /dev/null @@ -1,11 +0,0 @@ -package correct - -import "math" - -func IterativePower(nb int, power int) int { - if power < 0 { - return 0 - } - result := math.Pow(float64(nb), float64(power)) - return int(result) -} diff --git a/tests/go/func/correct/itoa.go b/tests/go/func/correct/itoa.go deleted file mode 100644 index c2abbf6b..00000000 --- a/tests/go/func/correct/itoa.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "strconv" - -func Itoa(i int) string { - return strconv.Itoa(i) -} diff --git a/tests/go/func/correct/itoabase.go b/tests/go/func/correct/itoabase.go deleted file mode 100644 index d595a2b1..00000000 --- a/tests/go/func/correct/itoabase.go +++ /dev/null @@ -1,14 +0,0 @@ -package correct - -import ( - "strconv" - "strings" -) - -func ItoaBase(value, base int) string { - if base < 2 || base > 16 { - return "" - } - - return strings.ToUpper(strconv.FormatInt(int64(value), base)) -} diff --git a/tests/go/func/correct/join.go b/tests/go/func/correct/join.go deleted file mode 100644 index 7504c1a0..00000000 --- a/tests/go/func/correct/join.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "strings" - -func Join(elems []string, sep string) string { - return strings.Join(elems, sep) -} diff --git a/tests/go/func/correct/lastrune.go b/tests/go/func/correct/lastrune.go deleted file mode 100644 index 00b0824b..00000000 --- a/tests/go/func/correct/lastrune.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -func LastRune(s string) rune { - runes := []rune(s) - index := len(runes) - 1 - return runes[index] -} diff --git a/tests/go/func/correct/lcm.go b/tests/go/func/correct/lcm.go deleted file mode 100644 index e84b62e5..00000000 --- a/tests/go/func/correct/lcm.go +++ /dev/null @@ -1,12 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/makerange.go b/tests/go/func/correct/makerange.go deleted file mode 100644 index 9d10ec80..00000000 --- a/tests/go/func/correct/makerange.go +++ /dev/null @@ -1,15 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/map.go b/tests/go/func/correct/map.go deleted file mode 100644 index 05004a4e..00000000 --- a/tests/go/func/correct/map.go +++ /dev/null @@ -1,19 +0,0 @@ -package correct - -func IsPositive(value int) bool { - return value > 0 -} - -func IsNegative0(value int) bool { - return value < 0 -} - -func Map(f func(int) bool, arr []int) []bool { - arrBool := make([]bool, len(arr)) - - for i, el := range arr { - arrBool[i] = f(el) - } - - return arrBool -} diff --git a/tests/go/func/correct/max.go b/tests/go/func/correct/max.go deleted file mode 100644 index c5d44518..00000000 --- a/tests/go/func/correct/max.go +++ /dev/null @@ -1,11 +0,0 @@ -package correct - -import "sort" - -func Max(a []int) int { - if len(a) == 0 { - return 0 - } - sort.Ints(a) - return a[len(a)-1] -} diff --git a/tests/go/func/correct/merge.go b/tests/go/func/correct/merge.go deleted file mode 100644 index 9dcb69dc..00000000 --- a/tests/go/func/correct/merge.go +++ /dev/null @@ -1,20 +0,0 @@ -package correct - -type TreeNodeM struct { - Left *TreeNodeM - Val int - Right *TreeNodeM -} - -func MergeTrees(t1 *TreeNodeM, t2 *TreeNodeM) *TreeNodeM { - if t1 == nil { - return t2 - } - if t2 == nil { - return t1 - } - t1.Val += t2.Val - t1.Left = MergeTrees(t1.Left, t2.Left) - t1.Right = MergeTrees(t1.Right, t2.Right) - return t1 -} diff --git a/tests/go/func/correct/nauuo.go b/tests/go/func/correct/nauuo.go deleted file mode 100644 index 1e38c59b..00000000 --- a/tests/go/func/correct/nauuo.go +++ /dev/null @@ -1,28 +0,0 @@ -package correct - -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 "?" -} diff --git a/tests/go/func/correct/nrune.go b/tests/go/func/correct/nrune.go deleted file mode 100644 index 40662d0a..00000000 --- a/tests/go/func/correct/nrune.go +++ /dev/null @@ -1,9 +0,0 @@ -package correct - -func NRune(s string, n int) rune { - if n > len(s) || n < 1 { - return 0 - } - runes := []rune(s) - return runes[n-1] -} diff --git a/tests/go/func/correct/pilot.go b/tests/go/func/correct/pilot.go deleted file mode 100644 index c2e06410..00000000 --- a/tests/go/func/correct/pilot.go +++ /dev/null @@ -1,10 +0,0 @@ -package correct - -type Pilot struct { - Name string - Life float32 - Age int - Aircraft int -} - -const AIRCRAFT1 = 1 diff --git a/tests/go/func/correct/pointone.go b/tests/go/func/correct/pointone.go deleted file mode 100644 index 906de418..00000000 --- a/tests/go/func/correct/pointone.go +++ /dev/null @@ -1,5 +0,0 @@ -package correct - -func PointOne(n *int) { - *n = 1 -} diff --git a/tests/go/func/correct/printchessboard.go b/tests/go/func/correct/printchessboard.go deleted file mode 100644 index 45c588fe..00000000 --- a/tests/go/func/correct/printchessboard.go +++ /dev/null @@ -1,40 +0,0 @@ -package correct - -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") - return - } - solve(x, y) -} diff --git a/tests/go/func/correct/printnbr.go b/tests/go/func/correct/printnbr.go deleted file mode 100644 index 6d332a99..00000000 --- a/tests/go/func/correct/printnbr.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "fmt" - -func PrintNbr(n int) { - fmt.Print(n) -} diff --git a/tests/go/func/correct/printstr.go b/tests/go/func/correct/printstr.go deleted file mode 100644 index 7c56225e..00000000 --- a/tests/go/func/correct/printstr.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "fmt" - -func PrintStr(s string) { - fmt.Print(s) -} diff --git a/tests/go/func/correct/printwordstables.go b/tests/go/func/correct/printwordstables.go deleted file mode 100644 index 3993568d..00000000 --- a/tests/go/func/correct/printwordstables.go +++ /dev/null @@ -1,9 +0,0 @@ -package correct - -import "fmt" - -func PrintWordsTables(a []string) { - for _, s := range a { - fmt.Println(s) - } -} diff --git a/tests/go/func/correct/priorprime.go b/tests/go/func/correct/priorprime.go deleted file mode 100644 index 210833e0..00000000 --- a/tests/go/func/correct/priorprime.go +++ /dev/null @@ -1,18 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/raid1b.go b/tests/go/func/correct/raid1b.go deleted file mode 100644 index a7629dcf..00000000 --- a/tests/go/func/correct/raid1b.go +++ /dev/null @@ -1,42 +0,0 @@ -package correct - -import "fmt" - -func drawLineRaid1b(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 Raid1b(x, y int) { - if x < 1 || y < 1 { - return - } - strBeg := "/*\\" - strMed := "* *" - strEnd := "\\*/" - - if y >= 1 { - drawLineRaid1b(x, strBeg) - } - if y > 2 { - for i := 0; i < y-2; i++ { - drawLineRaid1b(x, strMed) - } - } - if y > 1 { - drawLineRaid1b(x, strEnd) - } -} diff --git a/tests/go/func/correct/raid1c.go b/tests/go/func/correct/raid1c.go deleted file mode 100644 index bb61d9ba..00000000 --- a/tests/go/func/correct/raid1c.go +++ /dev/null @@ -1,42 +0,0 @@ -package correct - -import "fmt" - -func drawLineRaid1c(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 Raid1c(x, y int) { - if x < 1 || y < 1 { - return - } - strBeg := "ABA" - strMed := "B B" - strEnd := "CBC" - - if y >= 1 { - drawLineRaid1c(x, strBeg) - } - if y > 2 { - for i := 0; i < y-2; i++ { - drawLineRaid1c(x, strMed) - } - } - if y > 1 { - drawLineRaid1c(x, strEnd) - } -} diff --git a/tests/go/func/correct/raid1d.go b/tests/go/func/correct/raid1d.go deleted file mode 100644 index eedf5e74..00000000 --- a/tests/go/func/correct/raid1d.go +++ /dev/null @@ -1,42 +0,0 @@ -package correct - -import "fmt" - -func drawLineRaid1d(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 Raid1d(x, y int) { - if x < 1 || y < 1 { - return - } - strBeg := "ABC" - strMed := "B B" - strEnd := "ABC" - - if y >= 1 { - drawLineRaid1d(x, strBeg) - } - if y > 2 { - for i := 0; i < y-2; i++ { - drawLineRaid1d(x, strMed) - } - } - if y > 1 { - drawLineRaid1d(x, strEnd) - } -} diff --git a/tests/go/func/correct/raid1e.go b/tests/go/func/correct/raid1e.go deleted file mode 100644 index 4eb967e9..00000000 --- a/tests/go/func/correct/raid1e.go +++ /dev/null @@ -1,42 +0,0 @@ -package correct - -import "fmt" - -func drawLineRaid1e(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 Raid1e(x, y int) { - if x < 1 || y < 1 { - return - } - strBeg := "ABC" - strMed := "B B" - strEnd := "CBA" - - if y >= 1 { - drawLineRaid1e(x, strBeg) - } - if y > 2 { - for i := 0; i < y-2; i++ { - drawLineRaid1e(x, strMed) - } - } - if y > 1 { - drawLineRaid1e(x, strEnd) - } -} diff --git a/tests/go/func/correct/reachablenumber.go b/tests/go/func/correct/reachablenumber.go deleted file mode 100644 index 589843b3..00000000 --- a/tests/go/func/correct/reachablenumber.go +++ /dev/null @@ -1,18 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/recursivefactorial.go b/tests/go/func/correct/recursivefactorial.go deleted file mode 100644 index bcabf782..00000000 --- a/tests/go/func/correct/recursivefactorial.go +++ /dev/null @@ -1,17 +0,0 @@ -package correct - -import "math/bits" - -func RecursiveFactorial(nb int) int { - limit := 12 - if bits.UintSize == 64 { - limit = 20 - } - if nb < 0 || nb > limit { - return 0 - } - if nb == 0 { - return 1 - } - return nb * RecursiveFactorial(nb-1) -} diff --git a/tests/go/func/correct/recursivepower.go b/tests/go/func/correct/recursivepower.go deleted file mode 100644 index f3762203..00000000 --- a/tests/go/func/correct/recursivepower.go +++ /dev/null @@ -1,10 +0,0 @@ -package correct - -import "math" - -func RecursivePower(nb, power int) int { - if power < 0 { - return 0 - } - return int(math.Pow(float64(nb), float64(power))) -} diff --git a/tests/go/func/correct/reduceint.go b/tests/go/func/correct/reduceint.go deleted file mode 100644 index 8967d456..00000000 --- a/tests/go/func/correct/reduceint.go +++ /dev/null @@ -1,11 +0,0 @@ -package correct - -import "fmt" - -func ReduceInt(f func(int, int) int, a []int) { - acc := a[0] - for i := 1; i < len(a); i++ { - acc = f(acc, a[i]) - } - fmt.Println(acc) -} diff --git a/tests/go/func/correct/reversebits.go b/tests/go/func/correct/reversebits.go deleted file mode 100644 index e7250b1a..00000000 --- a/tests/go/func/correct/reversebits.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "math/bits" - -func ReverseBits(octet byte) byte { - return bits.Reverse8(uint8(octet)) -} diff --git a/tests/go/func/correct/rot14.go b/tests/go/func/correct/rot14.go deleted file mode 100644 index c32c5ed3..00000000 --- a/tests/go/func/correct/rot14.go +++ /dev/null @@ -1,21 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/sametree.go b/tests/go/func/correct/sametree.go deleted file mode 100644 index 9d6bd33c..00000000 --- a/tests/go/func/correct/sametree.go +++ /dev/null @@ -1,24 +0,0 @@ -package correct - -type TreeNodeL struct { - Left *TreeNodeL - Val int - Right *TreeNodeL -} - -func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool { - if p == nil && q == nil { - return true - } - return checkIfEq(p, q) -} - -func checkIfEq(t1 *TreeNodeL, t2 *TreeNodeL) bool { - if t1 == nil && t2 == nil { - return true - } - if t1 == nil || t2 == nil { - return false - } - return t1.Val == t2.Val && checkIfEq(t1.Right, t2.Right) && checkIfEq(t1.Left, t2.Left) -} diff --git a/tests/go/func/correct/slice.go b/tests/go/func/correct/slice.go deleted file mode 100644 index 44365480..00000000 --- a/tests/go/func/correct/slice.go +++ /dev/null @@ -1,42 +0,0 @@ -package correct - -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] -} diff --git a/tests/go/func/correct/sortintegertable.go b/tests/go/func/correct/sortintegertable.go deleted file mode 100644 index 69d86551..00000000 --- a/tests/go/func/correct/sortintegertable.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "sort" - -func SortIntegerTable(a []int) { - sort.Ints(a) -} diff --git a/tests/go/func/correct/sortlist.go b/tests/go/func/correct/sortlist.go deleted file mode 100644 index c4d08cf2..00000000 --- a/tests/go/func/correct/sortlist.go +++ /dev/null @@ -1,33 +0,0 @@ -package correct - -type Nodelist struct { - Data int - Next *Nodelist -} - -func SortList(l *Nodelist, cmp func(a, b int) bool) *Nodelist { - head := l - if head == nil { - return nil - } - head.Next = SortList(head.Next, cmp) - - if head.Next != nil && cmp(head.Data, head.Next.Data) { - head = moveValue(head, cmp) - } - return head -} - -func moveValue(l *Nodelist, cmp func(a, b int) bool) *Nodelist { - p := l - n := l.Next - ret := n - - for n != nil && cmp(l.Data, n.Data) { - p = n - n = n.Next - } - p.Next = l - l.Next = n - return ret -} diff --git a/tests/go/func/correct/sortwordarr.go b/tests/go/func/correct/sortwordarr.go deleted file mode 100644 index 31d070e2..00000000 --- a/tests/go/func/correct/sortwordarr.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "sort" - -func SortWordArr(a []string) { - sort.Strings(a) -} diff --git a/tests/go/func/correct/split.go b/tests/go/func/correct/split.go deleted file mode 100644 index c8001eea..00000000 --- a/tests/go/func/correct/split.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "strings" - -func Split(s, sep string) []string { - return strings.Split(s, sep) -} diff --git a/tests/go/func/correct/splitwhitespaces.go b/tests/go/func/correct/splitwhitespaces.go deleted file mode 100644 index f42dc1e0..00000000 --- a/tests/go/func/correct/splitwhitespaces.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "strings" - -func SplitWhiteSpaces(s string) []string { - return strings.Fields(s) -} diff --git a/tests/go/func/correct/sqrt.go b/tests/go/func/correct/sqrt.go deleted file mode 100644 index 822d31a8..00000000 --- a/tests/go/func/correct/sqrt.go +++ /dev/null @@ -1,11 +0,0 @@ -package correct - -import "math" - -func Sqrt(value int) int { - sr := math.Sqrt(float64(value)) - if math.Mod(sr, 1) == 0 { - return int(sr) - } - return 0 -} diff --git a/tests/go/func/correct/strlen.go b/tests/go/func/correct/strlen.go deleted file mode 100644 index e5281d5d..00000000 --- a/tests/go/func/correct/strlen.go +++ /dev/null @@ -1,11 +0,0 @@ -package correct - -func StrLen(str string) int { - len := 0 - - strConverted := []rune(str) - for i, _ := range strConverted { - len = i + 1 - } - return len -} diff --git a/tests/go/func/correct/strrev.go b/tests/go/func/correct/strrev.go deleted file mode 100644 index 8dd5f13c..00000000 --- a/tests/go/func/correct/strrev.go +++ /dev/null @@ -1,13 +0,0 @@ -package correct - -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) -} diff --git a/tests/go/func/correct/swap.go b/tests/go/func/correct/swap.go deleted file mode 100644 index 58c5dcdd..00000000 --- a/tests/go/func/correct/swap.go +++ /dev/null @@ -1,5 +0,0 @@ -package correct - -func Swap(a, b *int) { - *a, *b = *b, *a -} diff --git a/tests/go/func/correct/swapbits.go b/tests/go/func/correct/swapbits.go deleted file mode 100644 index df24d925..00000000 --- a/tests/go/func/correct/swapbits.go +++ /dev/null @@ -1,5 +0,0 @@ -package correct - -func SwapBits(n byte) byte { - return (n >> 4) | (n << 4) -} diff --git a/tests/go/func/correct/sweetproblem.go b/tests/go/func/correct/sweetproblem.go deleted file mode 100644 index f28e48ab..00000000 --- a/tests/go/func/correct/sweetproblem.go +++ /dev/null @@ -1,57 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/tolower.go b/tests/go/func/correct/tolower.go deleted file mode 100644 index 61813e32..00000000 --- a/tests/go/func/correct/tolower.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "strings" - -func ToLower(s string) string { - return strings.ToLower(s) -} diff --git a/tests/go/func/correct/toupper.go b/tests/go/func/correct/toupper.go deleted file mode 100644 index 48181da7..00000000 --- a/tests/go/func/correct/toupper.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -import "strings" - -func ToUpper(s string) string { - return strings.ToUpper(s) -} diff --git a/tests/go/func/correct/trimatoi.go b/tests/go/func/correct/trimatoi.go deleted file mode 100644 index 5ced4194..00000000 --- a/tests/go/func/correct/trimatoi.go +++ /dev/null @@ -1,31 +0,0 @@ -package correct - -func TrimAtoi(str string) int { - chars := []rune(str) - for i := range str { - chars[i] = rune(str[i]) - } - var numbers []rune - for i := range chars { - if (chars[i] >= '0' && chars[i] <= '9') || (len(numbers) == 0 && (chars[i]) == '-' || chars[i] == '+') { - numbers = append(numbers, chars[i]) - } - } - 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 -} diff --git a/tests/go/func/correct/twosum.go b/tests/go/func/correct/twosum.go deleted file mode 100644 index e83d8af2..00000000 --- a/tests/go/func/correct/twosum.go +++ /dev/null @@ -1,12 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/func/correct/ultimatedivmod.go b/tests/go/func/correct/ultimatedivmod.go deleted file mode 100644 index 3d068804..00000000 --- a/tests/go/func/correct/ultimatedivmod.go +++ /dev/null @@ -1,7 +0,0 @@ -package correct - -func UltimateDivMod(a, b *int) { - temp := *a - *a = *a / *b - *b = temp % *b -} diff --git a/tests/go/func/correct/ultimatepointone.go b/tests/go/func/correct/ultimatepointone.go deleted file mode 100644 index 392e1493..00000000 --- a/tests/go/func/correct/ultimatepointone.go +++ /dev/null @@ -1,5 +0,0 @@ -package correct - -func UltimatePointOne(n ***int) { - ***n = 1 -} diff --git a/tests/go/func/correct/unmatch.go b/tests/go/func/correct/unmatch.go deleted file mode 100644 index 87e8399b..00000000 --- a/tests/go/func/correct/unmatch.go +++ /dev/null @@ -1,18 +0,0 @@ -package correct - -// Returns the element of the slice that doesn't have a correspondant pair -func Unmatch(arr []int) int { - var quant int - for _, el := range arr { - quant = 0 - for _, v := range arr { - if v == el { - quant++ - } - } - if quant%2 != 0 { - return el - } - } - return -1 -} diff --git a/tests/go/func/correct/volumechanger.go b/tests/go/func/correct/volumechanger.go deleted file mode 100644 index 1f45617d..00000000 --- a/tests/go/func/correct/volumechanger.go +++ /dev/null @@ -1,12 +0,0 @@ -package correct - -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 -} diff --git a/tests/go/prog/correct/costumeprofit/main.go b/tests/go/func/costumeprofit/correct/main.go similarity index 100% rename from tests/go/prog/correct/costumeprofit/main.go rename to tests/go/func/costumeprofit/correct/main.go diff --git a/tests/go/prog/test_costumeprofit.go b/tests/go/func/costumeprofit/main.go similarity index 100% rename from tests/go/prog/test_costumeprofit.go rename to tests/go/func/costumeprofit/main.go diff --git a/tests/go/prog/correct/countdown/main.go b/tests/go/func/countdown/correct/main.go similarity index 100% rename from tests/go/prog/correct/countdown/main.go rename to tests/go/func/countdown/correct/main.go diff --git a/tests/go/prog/test_countdown.go b/tests/go/func/countdown/main.go similarity index 100% rename from tests/go/prog/test_countdown.go rename to tests/go/func/countdown/main.go diff --git a/tests/go/func/test_countif.go b/tests/go/func/countif/main.go similarity index 65% rename from tests/go/func/test_countif.go rename to tests/go/func/countif/main.go index 32d2b422..f1e6f453 100644 --- a/tests/go/func/test_countif.go +++ b/tests/go/func/countif/main.go @@ -1,13 +1,23 @@ package main import ( - "../lib" - "./correct" + "../common" "./student" ) +func countIf(f func(string) bool, arr []string) int { + counter := 0 + for _, el := range arr { + if f(el) { + counter++ + } + } + + return counter +} + func main() { - functions := []func(string) bool{correct.IsNumeric, correct.IsLower, correct.IsUpper} + functions := []func(string) bool{common.IsNumeric, common.IsLower, common.IsUpper} type node struct { f func(string) bool @@ -26,7 +36,7 @@ func main() { } for i := 0; i < 5; i++ { val := node{ - f: correct.IsNumeric, + f: common.IsNumeric, arr: lib.MultRandDigit(), } table = append(table, val) @@ -34,14 +44,14 @@ func main() { for i := 0; i < 5; i++ { val := node{ - f: correct.IsLower, + f: common.IsLower, arr: lib.MultRandLower(), } table = append(table, val) } for i := 0; i < 5; i++ { val := node{ - f: correct.IsUpper, + f: common.IsUpper, arr: lib.MultRandUpper(), } table = append(table, val) @@ -49,16 +59,16 @@ func main() { table = append(table, node{ - f: correct.IsNumeric, + f: common.IsNumeric, arr: []string{"Hello", "how", "are", "you"}, }, node{ - f: correct.IsNumeric, + f: common.IsNumeric, arr: []string{"This", "is", "4", "you"}, }, ) for _, arg := range table { - lib.Challenge("CountIf", student.CountIf, correct.CountIf, arg.f, arg.arr) + lib.Challenge("CountIf", student.CountIf, countIf, arg.f, arg.arr) } } diff --git a/tests/go/prog/correct/displaya/main.go b/tests/go/func/displaya/correct/main.go similarity index 100% rename from tests/go/prog/correct/displaya/main.go rename to tests/go/func/displaya/correct/main.go diff --git a/tests/go/prog/test_displaya.go b/tests/go/func/displaya/main.go similarity index 100% rename from tests/go/prog/test_displaya.go rename to tests/go/func/displaya/main.go diff --git a/tests/go/prog/correct/displayalpham/main.go b/tests/go/func/displayalpham/correct/main.go similarity index 100% rename from tests/go/prog/correct/displayalpham/main.go rename to tests/go/func/displayalpham/correct/main.go diff --git a/tests/go/prog/test_displayalpham.go b/tests/go/func/displayalpham/main.go similarity index 100% rename from tests/go/prog/test_displayalpham.go rename to tests/go/func/displayalpham/main.go diff --git a/tests/go/prog/correct/displayalrevm/main.go b/tests/go/func/displayalrevm/correct/main.go similarity index 100% rename from tests/go/prog/correct/displayalrevm/main.go rename to tests/go/func/displayalrevm/correct/main.go diff --git a/tests/go/prog/test_displayalrevm.go b/tests/go/func/displayalrevm/main.go similarity index 100% rename from tests/go/prog/test_displayalrevm.go rename to tests/go/func/displayalrevm/main.go diff --git a/tests/go/prog/correct/displayfile/main.go b/tests/go/func/displayfile/correct/main.go similarity index 100% rename from tests/go/prog/correct/displayfile/main.go rename to tests/go/func/displayfile/correct/main.go diff --git a/tests/go/prog/correct/displayfile/quest8.txt b/tests/go/func/displayfile/correct/quest8.txt similarity index 100% rename from tests/go/prog/correct/displayfile/quest8.txt rename to tests/go/func/displayfile/correct/quest8.txt diff --git a/tests/go/prog/test_displayfile.go b/tests/go/func/displayfile/main.go similarity index 100% rename from tests/go/prog/test_displayfile.go rename to tests/go/func/displayfile/main.go diff --git a/tests/go/prog/correct/displayfirstparam/main.go b/tests/go/func/displayfirstparam/correct/main.go similarity index 100% rename from tests/go/prog/correct/displayfirstparam/main.go rename to tests/go/func/displayfirstparam/correct/main.go diff --git a/tests/go/prog/test_displayfirstparam.go b/tests/go/func/displayfirstparam/main.go similarity index 100% rename from tests/go/prog/test_displayfirstparam.go rename to tests/go/func/displayfirstparam/main.go diff --git a/tests/go/prog/correct/displaylastparam/main.go b/tests/go/func/displaylastparam/correct/main.go similarity index 100% rename from tests/go/prog/correct/displaylastparam/main.go rename to tests/go/func/displaylastparam/correct/main.go diff --git a/tests/go/prog/test_displaylastparam.go b/tests/go/func/displaylastparam/main.go similarity index 100% rename from tests/go/prog/test_displaylastparam.go rename to tests/go/func/displaylastparam/main.go diff --git a/tests/go/prog/correct/displayz/main.go b/tests/go/func/displayz/correct/main.go similarity index 100% rename from tests/go/prog/correct/displayz/main.go rename to tests/go/func/displayz/correct/main.go diff --git a/tests/go/prog/test_displayz.go b/tests/go/func/displayz/main.go similarity index 100% rename from tests/go/prog/test_displayz.go rename to tests/go/func/displayz/main.go diff --git a/tests/go/func/test_divmod.go b/tests/go/func/divmod/main.go similarity index 81% rename from tests/go/func/test_divmod.go rename to tests/go/func/divmod/main.go index 86694749..fba0e85d 100644 --- a/tests/go/func/test_divmod.go +++ b/tests/go/func/divmod/main.go @@ -1,9 +1,11 @@ package main -import ( - "../lib" - "./student" -) +import "./student" + +func DivMod(a, b int, div, mod *int) { + *div = a / b + *mod = a % b +} func main() { i := 0 diff --git a/tests/go/prog/correct/doop/main.go b/tests/go/func/doop/correct/main.go similarity index 100% rename from tests/go/prog/correct/doop/main.go rename to tests/go/func/doop/correct/main.go diff --git a/tests/go/prog/test_doop.go b/tests/go/func/doop/main.go similarity index 100% rename from tests/go/prog/test_doop.go rename to tests/go/func/doop/main.go diff --git a/tests/go/func/test_doppelganger.go b/tests/go/func/doppelganger/main.go similarity index 82% rename from tests/go/func/test_doppelganger.go rename to tests/go/func/doppelganger/main.go index 56d62189..162a4078 100644 --- a/tests/go/func/test_doppelganger.go +++ b/tests/go/func/doppelganger/main.go @@ -1,11 +1,15 @@ package main import ( - "../lib" - "./correct" + "strings" + "./student" ) +func doppelGanger(s, substr string) int { + return strings.LastIndex(s, substr) +} + type node struct { big, little string } @@ -47,6 +51,6 @@ func main() { } for _, arg := range table { - lib.Challenge("DoppelGanger", student.DoppelGanger, correct.DoppelGanger, arg.big, arg.little) + lib.Challenge("DoppelGanger", student.DoppelGanger, doppelGanger, arg.big, arg.little) } } diff --git a/tests/go/func/correct/eightqueens.go b/tests/go/func/eightqueens/main.go similarity index 93% rename from tests/go/func/correct/eightqueens.go rename to tests/go/func/eightqueens/main.go index 7b2961e0..00126b88 100644 --- a/tests/go/func/correct/eightqueens.go +++ b/tests/go/func/eightqueens/main.go @@ -1,6 +1,10 @@ -package correct +package main -import "fmt" +import ( + "fmt" + + "./student" +) const size = 8 @@ -78,7 +82,11 @@ func tryX(x int) { } } -func EightQueens() { +func eightQueens() { // try the first column tryX(0) } + +func main() { + lib.Challenge("EightQueens", student.EightQueens, eightQueens) +} diff --git a/tests/go/func/test_enigma.go b/tests/go/func/enigma/main.go similarity index 62% rename from tests/go/func/test_enigma.go rename to tests/go/func/enigma/main.go index f841a463..46520b2e 100644 --- a/tests/go/func/test_enigma.go +++ b/tests/go/func/enigma/main.go @@ -1,10 +1,28 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +// this function will put a in c; c in d; d in b and b in a +func Enigma(a ***int, b *int, c *******int, d ****int) { + valc := *******c + *******c = ***a + vald := ****d + ****d = valc + valb := *b + *b = vald + ***a = valb +} + +// Helper function used in the test for checking the function Enigma() +func decript(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 := append([]int, lib.MultRandIntBetween(2, 20)...) @@ -37,7 +55,7 @@ func main() { d := &n student.Enigma(a, b, c, d) - correct.Decript(a, b, c, d) + decript(a, b, c, d) if aval != ***a { lib.Fatalf("Expected ***a = %d instead of %d\n", diff --git a/tests/go/prog/correct/expandstr/main.go b/tests/go/func/expandstr/correct/main.go similarity index 100% rename from tests/go/prog/correct/expandstr/main.go rename to tests/go/func/expandstr/correct/main.go diff --git a/tests/go/prog/test_expandstr.go b/tests/go/func/expandstr/main.go similarity index 100% rename from tests/go/prog/test_expandstr.go rename to tests/go/func/expandstr/main.go diff --git a/tests/go/func/fib/main.go b/tests/go/func/fib/main.go new file mode 100644 index 00000000..09ff2547 --- /dev/null +++ b/tests/go/func/fib/main.go @@ -0,0 +1,31 @@ +package main + +import "./student" + +func fib(n int) int { + if n <= 0 { + return 0 + } + t1 := 0 + t2 := 1 + for i := 2; i <= n; i++ { + t1 += t2 + tmp := t1 + t1 = t2 + t2 = tmp + } + return t2 +} + +func main() { + table := []int{ + 20, + 0, + 9, + 2, + } + table = append(table, lib.MultRandIntBetween(-100, 150)...) + for _, arg := range table { + lib.Challenge("Fib", student.Fib, fib, arg) + } +} diff --git a/tests/go/func/fibonacci/main.go b/tests/go/func/fibonacci/main.go new file mode 100644 index 00000000..f14dc79f --- /dev/null +++ b/tests/go/func/fibonacci/main.go @@ -0,0 +1,28 @@ +package main + +import "./student" + +func fibonacci(value int) int { + if value < 0 { + return -1 + } + if value == 0 { + return 0 + } + if value == 1 { + return 1 + } + return Fibonacci(value-1) + Fibonacci(value-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/tests/go/func/test_findnextprime.go b/tests/go/func/findnextprime/main.go similarity index 58% rename from tests/go/func/test_findnextprime.go rename to tests/go/func/findnextprime/main.go index a9fa6273..b8a2a37f 100644 --- a/tests/go/func/test_findnextprime.go +++ b/tests/go/func/findnextprime/main.go @@ -1,11 +1,17 @@ package main import ( - "../lib" - "./correct" + "../common" "./student" ) +func findNextPrime(nb int) int { + if common.IsPrime(nb) { + return nb + } + return findNextPrime(nb + 1) +} + func main() { table := append( lib.MultRandIntBetween(-1000000, 1000000), @@ -28,6 +34,6 @@ func main() { 1000000088, ) for _, arg := range table { - lib.Challenge("FindNextPrime", student.FindNextPrime, correct.FindNextPrime, arg) + lib.Challenge("FindNextPrime", student.FindNextPrime, findNextPrime, arg) } } diff --git a/tests/go/func/findprevprime/main.go b/tests/go/func/findprevprime/main.go new file mode 100644 index 00000000..1d3fccbd --- /dev/null +++ b/tests/go/func/findprevprime/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "../common" + "./student" +) + +func findPrevPrime(nb int) int { + if nb < 2 { + return 0 + } + if common.IsPrime(nb) { + return nb + } + return findPrevPrime(nb - 1) +} + +func main() { + a := append(lib.MultRandIntBetween(0, 99999), 5, 4, 1) + for _, elem := range a { + lib.Challenge("FindPrevPrime", student.FindPrevPrime, findPrevPrime, elem) + } +} diff --git a/tests/go/func/firstrune/main.go b/tests/go/func/firstrune/main.go new file mode 100644 index 00000000..9d552496 --- /dev/null +++ b/tests/go/func/firstrune/main.go @@ -0,0 +1,21 @@ +package main + +import "./student" + +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/tests/go/prog/correct/firstword/main.go b/tests/go/func/firstword/correct/main.go similarity index 100% rename from tests/go/prog/correct/firstword/main.go rename to tests/go/func/firstword/correct/main.go diff --git a/tests/go/prog/test_firstword.go b/tests/go/func/firstword/main.go similarity index 100% rename from tests/go/prog/test_firstword.go rename to tests/go/func/firstword/main.go diff --git a/tests/go/prog/correct/fixthemain/main.go b/tests/go/func/fixthemain/correct/main.go similarity index 100% rename from tests/go/prog/correct/fixthemain/main.go rename to tests/go/func/fixthemain/correct/main.go diff --git a/tests/go/prog/test_fixthemain.go b/tests/go/func/fixthemain/main.go similarity index 100% rename from tests/go/prog/test_fixthemain.go rename to tests/go/func/fixthemain/main.go diff --git a/tests/go/prog/correct/flags/main.go b/tests/go/func/flags/correct/main.go similarity index 100% rename from tests/go/prog/correct/flags/main.go rename to tests/go/func/flags/correct/main.go diff --git a/tests/go/prog/test_flags.go b/tests/go/func/flags/main.go similarity index 100% rename from tests/go/prog/test_flags.go rename to tests/go/func/flags/main.go diff --git a/tests/go/func/test_foldint.go b/tests/go/func/foldint/main.go similarity index 81% rename from tests/go/func/test_foldint.go rename to tests/go/func/foldint/main.go index d89f801a..3061cb5b 100644 --- a/tests/go/func/test_foldint.go +++ b/tests/go/func/foldint/main.go @@ -1,11 +1,19 @@ package main import ( - "../lib" - "./correct" + "fmt" + "./student" ) +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 { @@ -50,7 +58,7 @@ func main() { for _, v := range table { for _, f := range v.functions { - lib.Challenge("FoldInt", student.FoldInt, correct.FoldInt, f, v.a, v.n) + lib.Challenge("FoldInt", student.FoldInt, foldInt, f, v.a, v.n) } } } diff --git a/tests/go/func/test_foreach.go b/tests/go/func/foreach/main.go similarity index 83% rename from tests/go/func/test_foreach.go rename to tests/go/func/foreach/main.go index 2170983a..ca008381 100644 --- a/tests/go/func/test_foreach.go +++ b/tests/go/func/foreach/main.go @@ -3,11 +3,15 @@ package main import ( "fmt" - "../lib" - "./correct" "./student" ) +func forEach(f func(int), a []int) { + for _, el := range a { + f(el) + } +} + func add0(i int) { fmt.Println(i) } @@ -46,6 +50,6 @@ func main() { }) for _, arg := range table { - lib.Challenge("ForEach", student.ForEach, correct.ForEach, arg.f, arg.a) + lib.Challenge("ForEach", student.ForEach, forEach, arg.f, arg.a) } } diff --git a/tests/go/prog/correct/fprime/main.go b/tests/go/func/fprime/correct/main.go similarity index 100% rename from tests/go/prog/correct/fprime/main.go rename to tests/go/func/fprime/correct/main.go diff --git a/tests/go/prog/test_fprime.go b/tests/go/func/fprime/main.go similarity index 100% rename from tests/go/prog/test_fprime.go rename to tests/go/func/fprime/main.go diff --git a/tests/go/func/test_game23.go b/tests/go/func/game23/main.go similarity index 69% rename from tests/go/func/test_game23.go rename to tests/go/func/game23/main.go index 2a0fc413..89ce705b 100644 --- a/tests/go/func/test_game23.go +++ b/tests/go/func/game23/main.go @@ -1,10 +1,22 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +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 { @@ -55,6 +67,6 @@ func main() { table = append(table, value) } for _, arg := range table { - lib.Challenge("Game23", student.Game23, correct.Game23, arg.init, arg.fin) + lib.Challenge("Game23", student.Game23, game23, arg.init, arg.fin) } } diff --git a/tests/go/prog/correct/gcd/main.go b/tests/go/func/gcd/correct/main.go similarity index 100% rename from tests/go/prog/correct/gcd/main.go rename to tests/go/func/gcd/correct/main.go diff --git a/tests/go/prog/test_gcd.go b/tests/go/func/gcd/main.go similarity index 100% rename from tests/go/prog/test_gcd.go rename to tests/go/func/gcd/main.go diff --git a/tests/go/prog/correct/grouping/main.go b/tests/go/func/grouping/correct/main.go similarity index 100% rename from tests/go/prog/correct/grouping/main.go rename to tests/go/func/grouping/correct/main.go diff --git a/tests/go/prog/test_grouping.go b/tests/go/func/grouping/main.go similarity index 100% rename from tests/go/prog/test_grouping.go rename to tests/go/func/grouping/main.go diff --git a/tests/go/func/test_halfcontest.go b/tests/go/func/halfcontest/main.go similarity index 60% rename from tests/go/func/test_halfcontest.go rename to tests/go/func/halfcontest/main.go index 766a4f58..fcf0ec13 100644 --- a/tests/go/func/test_halfcontest.go +++ b/tests/go/func/halfcontest/main.go @@ -1,10 +1,15 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +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 { @@ -28,6 +33,6 @@ func main() { } for _, arg := range table { - lib.Challenge("HalfContest", student.HalfContest, correct.HalfContest, arg.h1, arg.m1, arg.h2, arg.m2) + lib.Challenge("HalfContest", student.HalfContest, halfContest, arg.h1, arg.m1, arg.h2, arg.m2) } } diff --git a/tests/go/prog/correct/hello/main.go b/tests/go/func/hello/correct/main.go similarity index 100% rename from tests/go/prog/correct/hello/main.go rename to tests/go/func/hello/correct/main.go diff --git a/tests/go/prog/test_hello.go b/tests/go/func/hello/main.go similarity index 100% rename from tests/go/prog/test_hello.go rename to tests/go/func/hello/main.go diff --git a/tests/go/prog/correct/hiddenp/main.go b/tests/go/func/hiddenp/correct/main.go similarity index 100% rename from tests/go/prog/correct/hiddenp/main.go rename to tests/go/func/hiddenp/correct/main.go diff --git a/tests/go/prog/test_hiddenp.go b/tests/go/func/hiddenp/main.go similarity index 100% rename from tests/go/prog/test_hiddenp.go rename to tests/go/func/hiddenp/main.go diff --git a/tests/go/func/test_index.go b/tests/go/func/index/main.go similarity index 86% rename from tests/go/func/test_index.go rename to tests/go/func/index/main.go index 5cbccec0..24c47563 100644 --- a/tests/go/func/test_index.go +++ b/tests/go/func/index/main.go @@ -1,11 +1,15 @@ package main import ( - "../lib" - "./correct" + "strings" + "./student" ) +func index(s string, substr string) int { + return strings.Index(s, substr) +} + func main() { type node struct { s string @@ -46,6 +50,6 @@ func main() { ) for _, arg := range table { - lib.Challenge("Index", student.Index, correct.Index, arg.s, arg.toFind) + lib.Challenge("Index", student.Index, index, arg.s, arg.toFind) } } diff --git a/tests/go/prog/correct/inter/main.go b/tests/go/func/inter/correct/main.go similarity index 100% rename from tests/go/prog/correct/inter/main.go rename to tests/go/func/inter/correct/main.go diff --git a/tests/go/prog/test_inter.go b/tests/go/func/inter/main.go similarity index 100% rename from tests/go/prog/test_inter.go rename to tests/go/func/inter/main.go diff --git a/tests/go/func/interestingnumber/main.go b/tests/go/func/interestingnumber/main.go new file mode 100644 index 00000000..159c7e2f --- /dev/null +++ b/tests/go/func/interestingnumber/main.go @@ -0,0 +1,35 @@ +package main + +import "./student" + +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/tests/go/func/test_isalpha.go b/tests/go/func/isalpha/main.go similarity index 64% rename from tests/go/func/test_isalpha.go rename to tests/go/func/isalpha/main.go index 93bded2d..977b8b2d 100644 --- a/tests/go/func/test_isalpha.go +++ b/tests/go/func/isalpha/main.go @@ -1,11 +1,20 @@ package main import ( - "../lib" - "./correct" + "unicode" + "./student" ) +func isAlpha(s string) bool { + for _, r := range s { + if !unicode.Is(unicode.Hex_Digit, r) { + return false + } + } + return true +} + func main() { table := append( lib.MultRandASCII(), @@ -20,6 +29,6 @@ func main() { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!", ) for _, arg := range table { - lib.Challenge("IsAlpha", student.IsAlpha, correct.IsAlpha, arg) + lib.Challenge("IsAlpha", student.IsAlpha, isAlpha, arg) } } diff --git a/tests/go/func/test_isanagram.go b/tests/go/func/isanagram/main.go similarity index 60% rename from tests/go/func/test_isanagram.go rename to tests/go/func/isanagram/main.go index f3c7675f..38e4ca74 100644 --- a/tests/go/func/test_isanagram.go +++ b/tests/go/func/isanagram/main.go @@ -1,10 +1,28 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +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{ @@ -33,6 +51,6 @@ func main() { } for _, arg := range table { - lib.Challenge("IsAnagram", student.IsAnagram, correct.IsAnagram, arg[0], arg[1]) + lib.Challenge("IsAnagram", student.IsAnagram, isAnagram, arg[0], arg[1]) } } diff --git a/tests/go/func/test_islower.go b/tests/go/func/islower/main.go similarity index 90% rename from tests/go/func/test_islower.go rename to tests/go/func/islower/main.go index 69221982..63dc0157 100644 --- a/tests/go/func/test_islower.go +++ b/tests/go/func/islower/main.go @@ -1,8 +1,7 @@ package main import ( - "../lib" - "./correct" + "../common" "./student" ) @@ -39,6 +38,6 @@ func main() { "hello!", ) for _, arg := range table { - lib.Challenge("IsLower", student.IsLower, correct.IsLower, arg) + lib.Challenge("IsLower", student.IsLower, common.IsLower, arg) } } diff --git a/tests/go/func/isnegative/main.go b/tests/go/func/isnegative/main.go new file mode 100644 index 00000000..43d4bd8a --- /dev/null +++ b/tests/go/func/isnegative/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + + "./student" +) + +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/tests/go/func/test_isnumeric.go b/tests/go/func/isnumeric/main.go similarity index 87% rename from tests/go/func/test_isnumeric.go rename to tests/go/func/isnumeric/main.go index b11e30ce..48480c32 100644 --- a/tests/go/func/test_isnumeric.go +++ b/tests/go/func/isnumeric/main.go @@ -3,8 +3,7 @@ package main import ( "strconv" - "../lib" - "./correct" + "../common" "./student" ) @@ -33,6 +32,6 @@ func main() { "01,02,03", ) for _, arg := range table { - lib.Challenge("IsNumeric", student.IsNumeric, correct.IsNumeric, arg) + lib.Challenge("IsNumeric", student.IsNumeric, common.IsNumeric, arg) } } diff --git a/tests/go/prog/correct/ispowerof2/main.go b/tests/go/func/ispowerof2/correct/main.go similarity index 100% rename from tests/go/prog/correct/ispowerof2/main.go rename to tests/go/func/ispowerof2/correct/main.go diff --git a/tests/go/prog/test_ispowerof2.go b/tests/go/func/ispowerof2/main.go similarity index 100% rename from tests/go/prog/test_ispowerof2.go rename to tests/go/func/ispowerof2/main.go diff --git a/tests/go/func/test_isprime.go b/tests/go/func/isprime/main.go similarity index 74% rename from tests/go/func/test_isprime.go rename to tests/go/func/isprime/main.go index 056cadff..ede62bba 100644 --- a/tests/go/func/test_isprime.go +++ b/tests/go/func/isprime/main.go @@ -1,8 +1,7 @@ package main import ( - "../lib" - "./correct" + "../common" "./student" ) @@ -27,6 +26,6 @@ func main() { 1000000087, ) for _, arg := range table { - lib.Challenge("IsPrime", student.IsPrime, correct.IsPrime, arg) + lib.Challenge("IsPrime", student.IsPrime, common.IsPrime, arg) } } diff --git a/tests/go/func/test_isprintable.go b/tests/go/func/isprintable/main.go similarity index 81% rename from tests/go/func/test_isprintable.go rename to tests/go/func/isprintable/main.go index b4bebf84..9b724403 100644 --- a/tests/go/func/test_isprintable.go +++ b/tests/go/func/isprintable/main.go @@ -2,12 +2,20 @@ package main import ( "math/rand" + "unicode" - "../lib" - "./correct" "./student" ) +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() @@ -43,6 +51,6 @@ func main() { "\n", ) for _, arg := range table { - lib.Challenge("IsPrintable", student.IsPrintable, correct.IsPrintable, arg) + lib.Challenge("IsPrintable", student.IsPrintable, isPrintable, arg) } } diff --git a/tests/go/func/test_issorted.go b/tests/go/func/issorted/main.go similarity index 75% rename from tests/go/func/test_issorted.go rename to tests/go/func/issorted/main.go index 934cb28e..319ccba0 100644 --- a/tests/go/func/test_issorted.go +++ b/tests/go/func/issorted/main.go @@ -3,11 +3,28 @@ package main import ( "sort" - "../lib" - "./correct" "./student" ) +func isSorted(f func(int, int) int, arr []int) bool { + ascendingOrdered := true + descendingOrdered := true + + for i := 1; i < len(arr); i++ { + if !(f(arr[i-1], arr[i]) >= 0) { + ascendingOrdered = false + } + } + + for i := 1; i < len(arr); i++ { + if !(f(arr[i-1], arr[i]) <= 0) { + descendingOrdered = false + } + } + + return ascendingOrdered || descendingOrdered +} + func isSortedBy1(a, b int) int { if a-b < 0 { return -1 @@ -78,26 +95,26 @@ func main() { } table = append(table, node{ - f: correct.IsSortedByDiff, + f: isSortedByDiff, a: []int{1, 2, 3, 4, 5, 6}, }) table = append(table, node{ - f: correct.IsSortedByDiff, + f: isSortedByDiff, a: []int{6, 5, 4, 3, 2, 1}, }) table = append(table, node{ - f: correct.IsSortedByDiff, + f: isSortedByDiff, a: []int{0, 0, 0, 0, 0, 0, 0}, }) table = append(table, node{ - f: correct.IsSortedByDiff, + f: isSortedByDiff, a: []int{0}, }) for _, arg := range table { - lib.Challenge("IsSorted", student.IsSorted, correct.IsSorted, arg.f, arg.a) + lib.Challenge("IsSorted", student.IsSorted, isSorted, arg.f, arg.a) } } diff --git a/tests/go/func/test_isupper.go b/tests/go/func/isupper/main.go similarity index 90% rename from tests/go/func/test_isupper.go rename to tests/go/func/isupper/main.go index dbd75813..81da9f64 100644 --- a/tests/go/func/test_isupper.go +++ b/tests/go/func/isupper/main.go @@ -1,8 +1,7 @@ package main import ( - "../lib" - "./correct" + "../common" "./student" ) @@ -41,6 +40,6 @@ func main() { "HELLO!", ) for _, arg := range table { - lib.Challenge("IsUpper", student.IsUpper, correct.IsUpper, arg) + lib.Challenge("IsUpper", student.IsUpper, common.IsUpper, arg) } } diff --git a/tests/go/func/iterativefactorial/main.go b/tests/go/func/iterativefactorial/main.go new file mode 100644 index 00000000..59be1e09 --- /dev/null +++ b/tests/go/func/iterativefactorial/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "math/bits" + + "./student" +) + +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/tests/go/func/test_iterativepower.go b/tests/go/func/iterativepower/main.go similarity index 58% rename from tests/go/func/test_iterativepower.go rename to tests/go/func/iterativepower/main.go index e91d0592..b379c9aa 100644 --- a/tests/go/func/test_iterativepower.go +++ b/tests/go/func/iterativepower/main.go @@ -1,17 +1,25 @@ package main import ( - "../lib" - "./correct" + "math" + "./student" ) +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, correct.IterativePower, nb, power) + lib.Challenge("IterativePower", student.IterativePower, iterativePower, nb, power) i++ } lib.Challenge("IterativePower", student.IterativePower, correct.IterativePower, 0, 0) diff --git a/tests/go/func/test_itoa.go b/tests/go/func/itoa/main.go similarity index 54% rename from tests/go/func/test_itoa.go rename to tests/go/func/itoa/main.go index 36c08d6a..26ff3f17 100644 --- a/tests/go/func/test_itoa.go +++ b/tests/go/func/itoa/main.go @@ -1,14 +1,18 @@ package main import ( - "../lib" - "./correct" + "strconv" + "./student" ) +func itoa(i int) string { + return strconv.Itoa(i) +} + func main() { for i := 0; i < 50; i++ { arg := lib.RandIntBetween(-2000000000, 2000000000) - lib.Challenge("Itoa", student.Itoa, correct.Itoa, arg) + lib.Challenge("Itoa", student.Itoa, itoa, arg) } } diff --git a/tests/go/func/test_itoabase.go b/tests/go/func/itoabase/main.go similarity index 62% rename from tests/go/func/test_itoabase.go rename to tests/go/func/itoabase/main.go index a6951dc0..f86ac050 100644 --- a/tests/go/func/test_itoabase.go +++ b/tests/go/func/itoabase/main.go @@ -1,16 +1,25 @@ package main import ( - "../lib" - "./correct" + "strconv" + "strings" + "./student" ) +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, correct.ItoaBase, value, base) + lib.Challenge("ItoaBase", student.ItoaBase, itoaBase, value, base) } for i := 0; i < 5; i++ { base := lib.RandIntBetween(2, 16) diff --git a/tests/go/func/test_join.go b/tests/go/func/join/main.go similarity index 72% rename from tests/go/func/test_join.go rename to tests/go/func/join/main.go index 9538e745..e7cc0a78 100644 --- a/tests/go/func/test_join.go +++ b/tests/go/func/join/main.go @@ -1,11 +1,15 @@ package main import ( - "../lib" - "./correct" + "strings" + "./student" ) +func join(elems []string, sep string) string { + return strings.Join(elems, sep) +} + func main() { seps := []string{" ", "-", " ,", "_", "SPC", " . "} @@ -21,6 +25,6 @@ func main() { // random position for the slice of separators posS := lib.RandIntBetween(0, len(seps)-1) - lib.Challenge("Join", student.Join, correct.Join, args[posA], seps[posS]) + lib.Challenge("Join", student.Join, join, args[posA], seps[posS]) } } diff --git a/tests/go/func/test_lastrune.go b/tests/go/func/lastrune/main.go similarity index 54% rename from tests/go/func/test_lastrune.go rename to tests/go/func/lastrune/main.go index 97648ae0..e9715ec0 100644 --- a/tests/go/func/test_lastrune.go +++ b/tests/go/func/lastrune/main.go @@ -1,10 +1,12 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +func lastRune(s string) rune { + runes := []rune(s) + index := len(runes) - 1 + return runes[index] +} func main() { table := lib.MultRandASCII() @@ -15,6 +17,6 @@ func main() { lib.RandStr(lib.RandIntBetween(1, 15), lib.RandAlnum()), ) for _, arg := range table { - lib.Challenge("LastRune", student.LastRune, correct.LastRune, arg) + lib.Challenge("LastRune", student.LastRune, lastRune, arg) } } diff --git a/tests/go/prog/correct/lastword/main.go b/tests/go/func/lastword/correct/main.go similarity index 100% rename from tests/go/prog/correct/lastword/main.go rename to tests/go/func/lastword/correct/main.go diff --git a/tests/go/prog/test_lastword.go b/tests/go/func/lastword/main.go similarity index 100% rename from tests/go/prog/test_lastword.go rename to tests/go/func/lastword/main.go diff --git a/tests/go/func/test_lcm.go b/tests/go/func/lcm/main.go similarity index 50% rename from tests/go/func/test_lcm.go rename to tests/go/func/lcm/main.go index c5cdbe40..187d0117 100644 --- a/tests/go/func/test_lcm.go +++ b/tests/go/func/lcm/main.go @@ -1,10 +1,17 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +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{ @@ -23,6 +30,6 @@ func main() { } for _, arg := range table { - lib.Challenge("Lcm", student.Lcm, correct.Lcm, arg[0], arg[1]) + lib.Challenge("Lcm", student.Lcm, lcm, arg[0], arg[1]) } } diff --git a/tests/go/func/test_appendrange.go b/tests/go/func/makerange/main.go similarity index 72% rename from tests/go/func/test_appendrange.go rename to tests/go/func/makerange/main.go index d180ffe7..7b59cf3f 100644 --- a/tests/go/func/test_appendrange.go +++ b/tests/go/func/makerange/main.go @@ -1,16 +1,27 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +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 @@ -23,7 +34,6 @@ func main() { } table = append(table, val) } - // 15 random pairs of ints with ||invalid range|| for i := 0; i < 15; i++ { minVal := lib.RandIntBetween(-10000000, 1000000) @@ -41,8 +51,7 @@ func main() { node{min: 5, max: 10}, node{min: 10, max: 5}, ) - for _, arg := range table { - lib.Challenge("AppendRange", student.AppendRange, correct.AppendRange, arg.min, arg.max) + lib.Challenge("MakeRange", student.MakeRange, makeRange, arg.min, arg.max) } } diff --git a/tests/go/func/test_map.go b/tests/go/func/map/main.go similarity index 52% rename from tests/go/func/test_map.go rename to tests/go/func/map/main.go index 8beac636..211a38b0 100644 --- a/tests/go/func/test_map.go +++ b/tests/go/func/map/main.go @@ -1,13 +1,30 @@ package main import ( - "../lib" - "./correct" + "../common" "./student" ) +func isPositive(i int) bool { + return i > 0 +} + +func isNegative0(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{correct.IsPositive, correct.IsNegative0, correct.IsPrime} + functions := []func(int) bool{isPositive, isNegative0, common.IsPrime} type node struct { f func(int) bool @@ -26,11 +43,11 @@ func main() { } table = append(table, node{ - f: correct.IsPrime, + f: common.IsPrime, arr: []int{1, 2, 3, 4, 5, 6}, }) for _, arg := range table { - lib.Challenge("Map", student.Map, correct.Map, arg.f, arg.arr) + lib.Challenge("Map", student.Map, _map, arg.f, arg.arr) } } diff --git a/tests/go/func/test_max.go b/tests/go/func/max/main.go similarity index 56% rename from tests/go/func/test_max.go rename to tests/go/func/max/main.go index 828e41d4..d9fe5d41 100644 --- a/tests/go/func/test_max.go +++ b/tests/go/func/max/main.go @@ -1,11 +1,19 @@ package main import ( - "../lib" - "./correct" + "sort" + "./student" ) +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) @@ -13,5 +21,5 @@ func main() { args = append(args, lib.RandInt()) } - lib.Challenge("Max", student.Max, correct.Max, args) + lib.Challenge("Max", student.Max, max, args) } diff --git a/tests/go/func/nauuo/main.go b/tests/go/func/nauuo/main.go new file mode 100644 index 00000000..56cd1dfd --- /dev/null +++ b/tests/go/func/nauuo/main.go @@ -0,0 +1,55 @@ +package main + +import "./student" + +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/tests/go/prog/correct/nbrconvertalpha/main.go b/tests/go/func/nbrconvertalpha/correct/main.go similarity index 100% rename from tests/go/prog/correct/nbrconvertalpha/main.go rename to tests/go/func/nbrconvertalpha/correct/main.go diff --git a/tests/go/prog/test_nbrconvertalpha.go b/tests/go/func/nbrconvertalpha/main.go similarity index 100% rename from tests/go/prog/test_nbrconvertalpha.go rename to tests/go/func/nbrconvertalpha/main.go diff --git a/tests/go/prog/correct/nenokku/main.go b/tests/go/func/nenokku/correct/main.go similarity index 100% rename from tests/go/prog/correct/nenokku/main.go rename to tests/go/func/nenokku/correct/main.go diff --git a/tests/go/prog/test_nenokku.go b/tests/go/func/nenokku/main.go similarity index 100% rename from tests/go/prog/test_nenokku.go rename to tests/go/func/nenokku/main.go diff --git a/tests/go/func/test_nrune.go b/tests/go/func/nrune/main.go similarity index 78% rename from tests/go/func/test_nrune.go rename to tests/go/func/nrune/main.go index bba8e86f..dc7462ba 100644 --- a/tests/go/func/test_nrune.go +++ b/tests/go/func/nrune/main.go @@ -3,11 +3,17 @@ package main import ( "math/rand" - "../lib" - "./correct" "./student" ) +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 @@ -38,6 +44,6 @@ func main() { ) for _, arg := range table { - lib.Challenge("NRune", student.NRune, correct.NRune, arg.word, arg.n) + lib.Challenge("NRune", student.NRune, nRune, arg.word, arg.n) } } diff --git a/tests/go/prog/correct/onlya/main.go b/tests/go/func/onlya/correct/main.go similarity index 100% rename from tests/go/prog/correct/onlya/main.go rename to tests/go/func/onlya/correct/main.go diff --git a/tests/go/prog/test_onlya.go b/tests/go/func/onlya/main.go similarity index 100% rename from tests/go/prog/test_onlya.go rename to tests/go/func/onlya/main.go diff --git a/tests/go/prog/correct/onlyz/main.go b/tests/go/func/onlyz/correct/main.go similarity index 100% rename from tests/go/prog/correct/onlyz/main.go rename to tests/go/func/onlyz/correct/main.go diff --git a/tests/go/prog/test_onlyz.go b/tests/go/func/onlyz/main.go similarity index 100% rename from tests/go/prog/test_onlyz.go rename to tests/go/func/onlyz/main.go diff --git a/tests/go/prog/correct/options/main.go b/tests/go/func/options/correct/main.go similarity index 100% rename from tests/go/prog/correct/options/main.go rename to tests/go/func/options/correct/main.go diff --git a/tests/go/prog/test_options.go b/tests/go/func/options/main.go similarity index 100% rename from tests/go/prog/test_options.go rename to tests/go/func/options/main.go diff --git a/tests/go/prog/correct/paramcount/main.go b/tests/go/func/paramcount/correct/main.go similarity index 100% rename from tests/go/prog/correct/paramcount/main.go rename to tests/go/func/paramcount/correct/main.go diff --git a/tests/go/prog/test_paramcount.go b/tests/go/func/paramcount/main.go similarity index 100% rename from tests/go/prog/test_paramcount.go rename to tests/go/func/paramcount/main.go diff --git a/tests/go/prog/correct/piglatin/main.go b/tests/go/func/piglatin/correct/main.go similarity index 100% rename from tests/go/prog/correct/piglatin/main.go rename to tests/go/func/piglatin/correct/main.go diff --git a/tests/go/prog/test_piglatin.go b/tests/go/func/piglatin/main.go similarity index 100% rename from tests/go/prog/test_piglatin.go rename to tests/go/func/piglatin/main.go diff --git a/tests/go/prog/correct/point/main.go b/tests/go/func/point/correct/main.go similarity index 100% rename from tests/go/prog/correct/point/main.go rename to tests/go/func/point/correct/main.go diff --git a/tests/go/prog/test_point.go b/tests/go/func/point/main.go similarity index 100% rename from tests/go/prog/test_point.go rename to tests/go/func/point/main.go diff --git a/tests/go/func/test_pointone.go b/tests/go/func/pointone/main.go similarity index 71% rename from tests/go/func/test_pointone.go rename to tests/go/func/pointone/main.go index a6d9c187..49fd3adf 100644 --- a/tests/go/func/test_pointone.go +++ b/tests/go/func/pointone/main.go @@ -1,9 +1,10 @@ package main -import ( - "../lib" - "./student" -) +import "./student" + +func PointOne(n *int) { + *n = 1 +} func main() { n := 0 diff --git a/tests/go/prog/correct/printalphabet/main.go b/tests/go/func/printalphabet/correct/main.go similarity index 100% rename from tests/go/prog/correct/printalphabet/main.go rename to tests/go/func/printalphabet/correct/main.go diff --git a/tests/go/prog/test_printalphabet.go b/tests/go/func/printalphabet/main.go similarity index 100% rename from tests/go/prog/test_printalphabet.go rename to tests/go/func/printalphabet/main.go diff --git a/tests/go/prog/correct/printbits/main.go b/tests/go/func/printbits/correct/main.go similarity index 100% rename from tests/go/prog/correct/printbits/main.go rename to tests/go/func/printbits/correct/main.go diff --git a/tests/go/prog/test_printbits.go b/tests/go/func/printbits/main.go similarity index 100% rename from tests/go/prog/test_printbits.go rename to tests/go/func/printbits/main.go diff --git a/tests/go/prog/correct/printchessboard/main.go b/tests/go/func/printchessboard/correct/main.go similarity index 80% rename from tests/go/prog/correct/printchessboard/main.go rename to tests/go/func/printchessboard/correct/main.go index 349b3e4b..3971380b 100644 --- a/tests/go/prog/correct/printchessboard/main.go +++ b/tests/go/func/printchessboard/correct/main.go @@ -10,11 +10,11 @@ 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) { + if i%2 == 0 && j%2 == 0 { line += "#" - } else if (i%2 == 0) && (j%2 == 1) { + } else if i%2 == 0 && j%2 == 1 { line += " " - } else if (i%2 == 1) && (j%2 == 1) { + } else if i%2 == 1 && j%2 == 1 { line += "#" } else { line += " " diff --git a/tests/go/prog/test_printchessboard.go b/tests/go/func/printchessboard/main.go similarity index 100% rename from tests/go/prog/test_printchessboard.go rename to tests/go/func/printchessboard/main.go diff --git a/tests/go/func/correct/printcomb.go b/tests/go/func/printcomb/main.go similarity index 62% rename from tests/go/func/correct/printcomb.go rename to tests/go/func/printcomb/main.go index 3a81cd9f..a15abc11 100644 --- a/tests/go/func/correct/printcomb.go +++ b/tests/go/func/printcomb/main.go @@ -1,8 +1,12 @@ -package correct +package main -import "fmt" +import ( + "fmt" -func PrintComb() { + "./student" +) + +func printComb() { for i := '0'; i <= '7'; i++ { for j := i + 1; j <= '8'; j++ { for k := j + 1; k <= '9'; k++ { @@ -16,3 +20,7 @@ func PrintComb() { } } } + +func main() { + lib.Challenge("PrintComb", student.PrintComb, printComb) +} diff --git a/tests/go/func/correct/printcomb2.go b/tests/go/func/printcomb2/main.go similarity index 56% rename from tests/go/func/correct/printcomb2.go rename to tests/go/func/printcomb2/main.go index 72296ed6..c31ad631 100644 --- a/tests/go/func/correct/printcomb2.go +++ b/tests/go/func/printcomb2/main.go @@ -1,8 +1,12 @@ -package correct +package main -import "fmt" +import ( + "fmt" -func PrintComb2() { + "./student" +) + +func printComb2() { a := 0 b := 1 for a <= 98 { @@ -18,3 +22,7 @@ func PrintComb2() { } fmt.Println() } + +func main() { + lib.Challenge("PrintComb2", student.PrintComb2, printComb2) +} diff --git a/tests/go/func/correct/printcombn.go b/tests/go/func/printcombn/main.go similarity index 79% rename from tests/go/func/correct/printcombn.go rename to tests/go/func/printcombn/main.go index ea354588..f1c953bd 100644 --- a/tests/go/func/correct/printcombn.go +++ b/tests/go/func/printcombn/main.go @@ -1,6 +1,10 @@ -package correct +package main -import "fmt" +import ( + "fmt" + + "./student" +) func show(n int, table [9]int, tmax [9]int) { i := 0 @@ -22,7 +26,7 @@ func printComb1() { } } -func PrintCombN(n int) { +func printCombN(n int) { table := [9]int{0, 1, 2, 3, 4, 5, 6, 7, 8} tmax := [9]int{} @@ -62,3 +66,10 @@ func PrintCombN(n int) { } 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/tests/go/prog/correct/printdigits/main.go b/tests/go/func/printdigits/correct/main.go similarity index 100% rename from tests/go/prog/correct/printdigits/main.go rename to tests/go/func/printdigits/correct/main.go diff --git a/tests/go/prog/test_printdigits.go b/tests/go/func/printdigits/main.go similarity index 100% rename from tests/go/prog/test_printdigits.go rename to tests/go/func/printdigits/main.go diff --git a/tests/go/prog/correct/printhex/main.go b/tests/go/func/printhex/correct/main.go similarity index 100% rename from tests/go/prog/correct/printhex/main.go rename to tests/go/func/printhex/correct/main.go diff --git a/tests/go/prog/test_printhex.go b/tests/go/func/printhex/main.go similarity index 100% rename from tests/go/prog/test_printhex.go rename to tests/go/func/printhex/main.go diff --git a/tests/go/func/correct/printmemory.go b/tests/go/func/printmemory/main.go similarity index 70% rename from tests/go/func/correct/printmemory.go rename to tests/go/func/printmemory/main.go index 309a4b0f..2345b17a 100644 --- a/tests/go/func/correct/printmemory.go +++ b/tests/go/func/printmemory/main.go @@ -1,8 +1,10 @@ -package correct +package main import ( "fmt" "unicode" + + "./student" ) func printBase(nbr int) int { @@ -72,10 +74,25 @@ func printLine(arr [10]int, start int) { fmt.Println() } -func PrintMemory(a [10]int) { +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, correct.PrintMemory, table2) +} + +// TODO: this can be simplified a lot diff --git a/tests/go/func/test_printnbr.go b/tests/go/func/printnbr/main.go similarity index 59% rename from tests/go/func/test_printnbr.go rename to tests/go/func/printnbr/main.go index 5a86388b..c3d45bd0 100644 --- a/tests/go/func/test_printnbr.go +++ b/tests/go/func/printnbr/main.go @@ -1,11 +1,15 @@ package main import ( - "../lib" - "./correct" + "fmt" + "./student" ) +func printNbr(n int) { + fmt.Print(n) +} + func main() { table := append( lib.MultRandInt(), @@ -14,6 +18,6 @@ func main() { 0, ) for _, arg := range table { - lib.Challenge("PrintNbr", student.PrintNbr, correct.PrintNbr, arg) + lib.Challenge("PrintNbr", student.PrintNbr, printNbr, arg) } } diff --git a/tests/go/func/correct/printnbrinorder.go b/tests/go/func/printnbrinorder/main.go similarity index 56% rename from tests/go/func/correct/printnbrinorder.go rename to tests/go/func/printnbrinorder/main.go index 1a435b3a..2b2f8bfc 100644 --- a/tests/go/func/correct/printnbrinorder.go +++ b/tests/go/func/printnbrinorder/main.go @@ -1,8 +1,10 @@ -package correct +package main import ( "fmt" "sort" + + "./student" ) func intToDigits(n int) (digits []int) { @@ -17,7 +19,7 @@ func intToDigits(n int) (digits []int) { return } -func PrintNbrInOrder(n int) { +func printNbrInOrder(n int) { if n == 0 { fmt.Print("0") return @@ -29,3 +31,16 @@ func PrintNbrInOrder(n int) { } fmt.Println() } + +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/tests/go/prog/correct/printparams/main.go b/tests/go/func/printparams/correct/main.go similarity index 100% rename from tests/go/prog/correct/printparams/main.go rename to tests/go/func/printparams/correct/main.go diff --git a/tests/go/prog/test_printparams.go b/tests/go/func/printparams/main.go similarity index 100% rename from tests/go/prog/test_printparams.go rename to tests/go/func/printparams/main.go diff --git a/tests/go/prog/correct/printprogramname/main.go b/tests/go/func/printprogramname/correct/main.go similarity index 100% rename from tests/go/prog/correct/printprogramname/main.go rename to tests/go/func/printprogramname/correct/main.go diff --git a/tests/go/prog/test_printprogramname.go b/tests/go/func/printprogramname/main.go similarity index 100% rename from tests/go/prog/test_printprogramname.go rename to tests/go/func/printprogramname/main.go diff --git a/tests/go/prog/correct/printrevcomb/main.go b/tests/go/func/printrevcomb/correct/main.go similarity index 100% rename from tests/go/prog/correct/printrevcomb/main.go rename to tests/go/func/printrevcomb/correct/main.go diff --git a/tests/go/prog/test_printrevcomb.go b/tests/go/func/printrevcomb/main.go similarity index 100% rename from tests/go/prog/test_printrevcomb.go rename to tests/go/func/printrevcomb/main.go diff --git a/tests/go/prog/correct/printreversealphabet/main.go b/tests/go/func/printreversealphabet/correct/main.go similarity index 100% rename from tests/go/prog/correct/printreversealphabet/main.go rename to tests/go/func/printreversealphabet/correct/main.go diff --git a/tests/go/prog/test_printreversealphabet.go b/tests/go/func/printreversealphabet/main.go similarity index 100% rename from tests/go/prog/test_printreversealphabet.go rename to tests/go/func/printreversealphabet/main.go diff --git a/tests/go/func/test_printstr.go b/tests/go/func/printstr/main.go similarity index 58% rename from tests/go/func/test_printstr.go rename to tests/go/func/printstr/main.go index 70aa45b1..19030ccc 100644 --- a/tests/go/func/test_printstr.go +++ b/tests/go/func/printstr/main.go @@ -1,15 +1,19 @@ package main import ( - "../lib" - "./correct" + "fmt" + "./student" ) +func printStr(s string) { + fmt.Print(s) +} + func main() { table := lib.MultRandASCII() table = append(table, "Hello World!") for _, arg := range table { - lib.Challenge("PrintStr", student.PrintStr, correct.PrintStr, arg) + lib.Challenge("PrintStr", student.PrintStr, printStr, arg) } } diff --git a/tests/go/func/test_printwordstables.go b/tests/go/func/printwordstables/main.go similarity index 52% rename from tests/go/func/test_printwordstables.go rename to tests/go/func/printwordstables/main.go index 70b53066..92f5b818 100644 --- a/tests/go/func/test_printwordstables.go +++ b/tests/go/func/printwordstables/main.go @@ -1,26 +1,29 @@ package main import ( - "strings" + "fmt" - "../lib" - "./correct" "./student" ) +func printWordsTables(a []string) { + for _, s := range a { + fmt.Println(s) + } +} + func main() { table := [][]string{} // 30 random slice of slice of strings for i := 0; i < 30; i++ { - val := correct.SplitWhiteSpaces(strings.Join(lib.MultRandASCII(), " ")) - table = append(table, val) + table = append(table, lib.MultRandASCII()) } table = append(table, []string{"Hello", "how", "are", "you?"}) for _, arg := range table { - lib.Challenge("PrintWordsTables", student.PrintWordsTables, correct.PrintWordsTables, arg) + lib.Challenge("PrintWordsTables", student.PrintWordsTables, printWordsTables, arg) } } diff --git a/tests/go/func/priorprime/main.go b/tests/go/func/priorprime/main.go new file mode 100644 index 00000000..28b229ed --- /dev/null +++ b/tests/go/func/priorprime/main.go @@ -0,0 +1,35 @@ +package main + +import "./student" + +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 := []int{ + 50, + 13, + 10, + 0, + 1, + 2, + } + table = append(table, lib.MultRandIntBetween(0, 1000)) + for _, arg := range table { + lib.Challenge("PriorPrime", student.PriorPrime, priorPrime, arg) + } +} diff --git a/tests/go/func/correct/raid1a.go b/tests/go/func/raid1a/main.go similarity index 50% rename from tests/go/func/correct/raid1a.go rename to tests/go/func/raid1a/main.go index c32d2184..60aa5571 100644 --- a/tests/go/func/correct/raid1a.go +++ b/tests/go/func/raid1a/main.go @@ -1,6 +1,10 @@ -package correct +package main -import "fmt" +import ( + "fmt" + + "./student" +) func drawLine(x int, s string) { beg := s[0] @@ -34,9 +38,34 @@ func printTheLines(x, y int, strBeg, strMed, strEnd string) { } } -func Raid1a(x, y int) { +func raid1a(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("Raid1a", raid1a, student.Raid1a, table[i], table[i+1]) + } + } +} diff --git a/tests/go/func/raid1b/main.go b/tests/go/func/raid1b/main.go new file mode 100644 index 00000000..b1266e5f --- /dev/null +++ b/tests/go/func/raid1b/main.go @@ -0,0 +1,71 @@ +package main + +import ( + "fmt" + + "./student" +) + +func drawLineRaid1b(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 raid1b(x, y int) { + if x < 1 || y < 1 { + return + } + strBeg := "/*\\" + strMed := "* *" + strEnd := "\\*/" + + if y >= 1 { + drawLineRaid1b(x, strBeg) + } + if y > 2 { + for i := 0; i < y-2; i++ { + drawLineRaid1b(x, strMed) + } + } + if y > 1 { + drawLineRaid1b(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("Raid1b", raid1b, student.Raid1b, table[i], table[i+1]) + } + } +} diff --git a/tests/go/func/raid1c/main.go b/tests/go/func/raid1c/main.go new file mode 100644 index 00000000..3334a95b --- /dev/null +++ b/tests/go/func/raid1c/main.go @@ -0,0 +1,71 @@ +package main + +import ( + "fmt" + + "./student" +) + +func drawLineRaid1c(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 raid1c(x, y int) { + if x < 1 || y < 1 { + return + } + strBeg := "ABA" + strMed := "B B" + strEnd := "CBC" + + if y >= 1 { + drawLineRaid1c(x, strBeg) + } + if y > 2 { + for i := 0; i < y-2; i++ { + drawLineRaid1c(x, strMed) + } + } + if y > 1 { + drawLineRaid1c(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("Raid1c", raid1c, student.Raid1c, table[i], table[i+1]) + } + } +} diff --git a/tests/go/func/raid1d/main.go b/tests/go/func/raid1d/main.go new file mode 100644 index 00000000..6c1b1cf2 --- /dev/null +++ b/tests/go/func/raid1d/main.go @@ -0,0 +1,71 @@ +package main + +import ( + "fmt" + + "./student" +) + +func drawLineRaid1d(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 raid1d(x, y int) { + if x < 1 || y < 1 { + return + } + strBeg := "ABC" + strMed := "B B" + strEnd := "ABC" + + if y >= 1 { + drawLineRaid1d(x, strBeg) + } + if y > 2 { + for i := 0; i < y-2; i++ { + drawLineRaid1d(x, strMed) + } + } + if y > 1 { + drawLineRaid1d(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("Raid1d", raid1d, student.Raid1d, table[i], table[i+1]) + } + } +} diff --git a/tests/go/func/raid1e/main.go b/tests/go/func/raid1e/main.go new file mode 100644 index 00000000..ca71e828 --- /dev/null +++ b/tests/go/func/raid1e/main.go @@ -0,0 +1,71 @@ +package main + +import ( + "fmt" + + "./student" +) + +func drawLineRaid1e(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 raid1e(x, y int) { + if x < 1 || y < 1 { + return + } + strBeg := "ABC" + strMed := "B B" + strEnd := "CBA" + + if y >= 1 { + drawLineRaid1e(x, strBeg) + } + if y > 2 { + for i := 0; i < y-2; i++ { + drawLineRaid1e(x, strMed) + } + } + if y > 1 { + drawLineRaid1e(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("Raid1e", raid1e, student.Raid1e, table[i], table[i+1]) + } + } +} diff --git a/tests/go/prog/correct/raid2/main.go b/tests/go/func/raid2/correct/main.go similarity index 100% rename from tests/go/prog/correct/raid2/main.go rename to tests/go/func/raid2/correct/main.go diff --git a/tests/go/prog/test_raid2.go b/tests/go/func/raid2/main.go similarity index 100% rename from tests/go/prog/test_raid2.go rename to tests/go/func/raid2/main.go diff --git a/tests/go/prog/correct/raid3/main.go b/tests/go/func/raid3/correct/main.go similarity index 100% rename from tests/go/prog/correct/raid3/main.go rename to tests/go/func/raid3/correct/main.go diff --git a/tests/go/prog/correct/raid3/raid1aprog/raid1a.go b/tests/go/func/raid3/correct/raid1aprog/raid1a.go similarity index 100% rename from tests/go/prog/correct/raid3/raid1aprog/raid1a.go rename to tests/go/func/raid3/correct/raid1aprog/raid1a.go diff --git a/tests/go/prog/correct/raid3/raid1bprog/raid1b.go b/tests/go/func/raid3/correct/raid1bprog/raid1b.go similarity index 100% rename from tests/go/prog/correct/raid3/raid1bprog/raid1b.go rename to tests/go/func/raid3/correct/raid1bprog/raid1b.go diff --git a/tests/go/prog/correct/raid3/raid1cprog/raid1c.go b/tests/go/func/raid3/correct/raid1cprog/raid1c.go similarity index 100% rename from tests/go/prog/correct/raid3/raid1cprog/raid1c.go rename to tests/go/func/raid3/correct/raid1cprog/raid1c.go diff --git a/tests/go/prog/correct/raid3/raid1dprog/raid1d.go b/tests/go/func/raid3/correct/raid1dprog/raid1d.go similarity index 100% rename from tests/go/prog/correct/raid3/raid1dprog/raid1d.go rename to tests/go/func/raid3/correct/raid1dprog/raid1d.go diff --git a/tests/go/prog/correct/raid3/raid1eprog/raid1e.go b/tests/go/func/raid3/correct/raid1eprog/raid1e.go similarity index 100% rename from tests/go/prog/correct/raid3/raid1eprog/raid1e.go rename to tests/go/func/raid3/correct/raid1eprog/raid1e.go diff --git a/tests/go/prog/test_raid3.go b/tests/go/func/raid3/main.go similarity index 100% rename from tests/go/prog/test_raid3.go rename to tests/go/func/raid3/main.go diff --git a/tests/go/prog/correct/range/main.go b/tests/go/func/range/correct/main.go similarity index 100% rename from tests/go/prog/correct/range/main.go rename to tests/go/func/range/correct/main.go diff --git a/tests/go/prog/test_range.go b/tests/go/func/range/main.go similarity index 100% rename from tests/go/prog/test_range.go rename to tests/go/func/range/main.go diff --git a/tests/go/func/reachablenumber/main.go b/tests/go/func/reachablenumber/main.go new file mode 100644 index 00000000..018685f9 --- /dev/null +++ b/tests/go/func/reachablenumber/main.go @@ -0,0 +1,35 @@ +package main + +import "./student" + +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/tests/go/prog/correct/rectangle/main.go b/tests/go/func/rectangle/correct/main.go similarity index 100% rename from tests/go/prog/correct/rectangle/main.go rename to tests/go/func/rectangle/correct/main.go diff --git a/tests/go/prog/test_rectangle.go b/tests/go/func/rectangle/main.go similarity index 100% rename from tests/go/prog/test_rectangle.go rename to tests/go/func/rectangle/main.go diff --git a/tests/go/func/recursivefactorial/main.go b/tests/go/func/recursivefactorial/main.go new file mode 100644 index 00000000..e62296c8 --- /dev/null +++ b/tests/go/func/recursivefactorial/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "math/bits" + + "./student" +) + +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/tests/go/func/test_recursivepower.go b/tests/go/func/recursivepower/main.go similarity index 60% rename from tests/go/func/test_recursivepower.go rename to tests/go/func/recursivepower/main.go index c2f895a0..e3c649e8 100644 --- a/tests/go/func/test_recursivepower.go +++ b/tests/go/func/recursivepower/main.go @@ -1,17 +1,24 @@ package main import ( - "../lib" - "./correct" + "math" + "./student" ) +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, correct.RecursivePower, nb, power) + lib.Challenge("RecursivePower", student.RecursivePower, recursivePower, nb, power) i++ } lib.Challenge("RecursivePower", student.RecursivePower, correct.RecursivePower, 0, 0) diff --git a/tests/go/func/test_reduceint.go b/tests/go/func/reduceint/main.go similarity index 75% rename from tests/go/func/test_reduceint.go rename to tests/go/func/reduceint/main.go index fdbb34d1..97a485ac 100644 --- a/tests/go/func/test_reduceint.go +++ b/tests/go/func/reduceint/main.go @@ -1,11 +1,19 @@ package main import ( - "../lib" - "./correct" + "fmt" + "./student" ) +func reduceInt(f func(int, int) int, a []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 { @@ -36,7 +44,7 @@ func main() { for _, v := range table { for _, f := range v.functions { - lib.Challenge("ReduceInt", student.ReduceInt, correct.ReduceInt, f, v.a) + lib.Challenge("ReduceInt", student.ReduceInt, reduceInt, f, v.a) } } } diff --git a/tests/go/prog/correct/repeatalpha/main.go b/tests/go/func/repeatalpha/correct/main.go similarity index 100% rename from tests/go/prog/correct/repeatalpha/main.go rename to tests/go/func/repeatalpha/correct/main.go diff --git a/tests/go/prog/test_repeatalpha.go b/tests/go/func/repeatalpha/main.go similarity index 100% rename from tests/go/prog/test_repeatalpha.go rename to tests/go/func/repeatalpha/main.go diff --git a/tests/go/func/test_reversebits.go b/tests/go/func/reversebits/main.go similarity index 78% rename from tests/go/func/test_reversebits.go rename to tests/go/func/reversebits/main.go index f2890fe2..ed91bfd5 100644 --- a/tests/go/func/test_reversebits.go +++ b/tests/go/func/reversebits/main.go @@ -1,12 +1,17 @@ package main import ( + "math/bits" "reflect" "../lib" - "./correct" + "./student" ) +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) @@ -29,6 +34,6 @@ func main() { } for _, v := range args { - challengeBytes(ReverseBits, correct.ReverseBits, v) + challengeBytes(student.ReverseBits, reverseBits, v) } } diff --git a/tests/go/prog/correct/reverserange/main.go b/tests/go/func/reverserange/correct/main.go similarity index 100% rename from tests/go/prog/correct/reverserange/main.go rename to tests/go/func/reverserange/correct/main.go diff --git a/tests/go/prog/test_reverserange.go b/tests/go/func/reverserange/main.go similarity index 100% rename from tests/go/prog/test_reverserange.go rename to tests/go/func/reverserange/main.go diff --git a/tests/go/prog/correct/reversestrcap/main.go b/tests/go/func/reversestrcap/correct/main.go similarity index 100% rename from tests/go/prog/correct/reversestrcap/main.go rename to tests/go/func/reversestrcap/correct/main.go diff --git a/tests/go/prog/test_reversestrcap.go b/tests/go/func/reversestrcap/main.go similarity index 100% rename from tests/go/prog/test_reversestrcap.go rename to tests/go/func/reversestrcap/main.go diff --git a/tests/go/func/correct/revivethreenums.go b/tests/go/func/revivethreenums/main.go similarity index 50% rename from tests/go/func/correct/revivethreenums.go rename to tests/go/func/revivethreenums/main.go index 1fd492de..54f8ea57 100644 --- a/tests/go/func/correct/revivethreenums.go +++ b/tests/go/func/revivethreenums/main.go @@ -1,4 +1,6 @@ -package correct +package main + +import "./student" func more(a, b int) int { if a < b { @@ -23,7 +25,7 @@ func max(a, b, c, d int) int { return -1 } -func ReviveThreeNums(a, b, c, d int) int { +func reviveThreeNums(a, b, c, d int) int { maxi := -111 if a != max(a, b, c, d) { maxi = more(maxi, max(a, b, c, d)-a) @@ -39,3 +41,26 @@ func ReviveThreeNums(a, b, c, d int) int { } 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/tests/go/prog/correct/revparams/main.go b/tests/go/func/revparams/correct/main.go similarity index 100% rename from tests/go/prog/correct/revparams/main.go rename to tests/go/func/revparams/correct/main.go diff --git a/tests/go/prog/test_revparams.go b/tests/go/func/revparams/main.go similarity index 100% rename from tests/go/prog/test_revparams.go rename to tests/go/func/revparams/main.go diff --git a/tests/go/prog/correct/revwstr/main.go b/tests/go/func/revwstr/correct/main.go similarity index 100% rename from tests/go/prog/correct/revwstr/main.go rename to tests/go/func/revwstr/correct/main.go diff --git a/tests/go/prog/test_revwstr.go b/tests/go/func/revwstr/main.go similarity index 100% rename from tests/go/prog/test_revwstr.go rename to tests/go/func/revwstr/main.go diff --git a/tests/go/prog/correct/robottoorigin/main.go b/tests/go/func/robottoorigin/correct/main.go similarity index 100% rename from tests/go/prog/correct/robottoorigin/main.go rename to tests/go/func/robottoorigin/correct/main.go diff --git a/tests/go/prog/test_robottoorigin.go b/tests/go/func/robottoorigin/main.go similarity index 100% rename from tests/go/prog/test_robottoorigin.go rename to tests/go/func/robottoorigin/main.go diff --git a/tests/go/prog/correct/romannumbers/main.go b/tests/go/func/romannumbers/correct/main.go similarity index 100% rename from tests/go/prog/correct/romannumbers/main.go rename to tests/go/func/romannumbers/correct/main.go diff --git a/tests/go/prog/test_romannumbers.go b/tests/go/func/romannumbers/main.go similarity index 100% rename from tests/go/prog/test_romannumbers.go rename to tests/go/func/romannumbers/main.go diff --git a/tests/go/prog/correct/rostring/main.go b/tests/go/func/rostring/correct/main.go similarity index 100% rename from tests/go/prog/correct/rostring/main.go rename to tests/go/func/rostring/correct/main.go diff --git a/tests/go/prog/test_rostring.go b/tests/go/func/rostring/main.go similarity index 100% rename from tests/go/prog/test_rostring.go rename to tests/go/func/rostring/main.go diff --git a/tests/go/prog/correct/rot13/main.go b/tests/go/func/rot13/correct/main.go similarity index 100% rename from tests/go/prog/correct/rot13/main.go rename to tests/go/func/rot13/correct/main.go diff --git a/tests/go/prog/test_rot13.go b/tests/go/func/rot13/main.go similarity index 100% rename from tests/go/prog/test_rot13.go rename to tests/go/func/rot13/main.go diff --git a/tests/go/func/rot14/main.go b/tests/go/func/rot14/main.go new file mode 100644 index 00000000..0ff8652f --- /dev/null +++ b/tests/go/func/rot14/main.go @@ -0,0 +1,43 @@ +package main + +import "./student" + +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/tests/go/prog/correct/rotatevowels/main.go b/tests/go/func/rotatevowels/correct/main.go similarity index 100% rename from tests/go/prog/correct/rotatevowels/main.go rename to tests/go/func/rotatevowels/correct/main.go diff --git a/tests/go/prog/test_rotatevowels.go b/tests/go/func/rotatevowels/main.go similarity index 100% rename from tests/go/prog/test_rotatevowels.go rename to tests/go/func/rotatevowels/main.go diff --git a/tests/go/prog/correct/rpncalc/main.go b/tests/go/func/rpncalc/correct/main.go similarity index 100% rename from tests/go/prog/correct/rpncalc/main.go rename to tests/go/func/rpncalc/correct/main.go diff --git a/tests/go/prog/test_rpncalc.go b/tests/go/func/rpncalc/main.go similarity index 100% rename from tests/go/prog/test_rpncalc.go rename to tests/go/func/rpncalc/main.go diff --git a/tests/go/prog/correct/searchreplace/main.go b/tests/go/func/searchreplace/correct/main.go similarity index 100% rename from tests/go/prog/correct/searchreplace/main.go rename to tests/go/func/searchreplace/correct/main.go diff --git a/tests/go/prog/test_searchreplace.go b/tests/go/func/searchreplace/main.go similarity index 100% rename from tests/go/prog/test_searchreplace.go rename to tests/go/func/searchreplace/main.go diff --git a/tests/go/func/test_slice.go b/tests/go/func/slice/main.go similarity index 56% rename from tests/go/func/test_slice.go rename to tests/go/func/slice/main.go index 74dd9339..a7f7bfd0 100644 --- a/tests/go/func/test_slice.go +++ b/tests/go/func/slice/main.go @@ -1,10 +1,47 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +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() { arr := [][]interface{}{ @@ -40,6 +77,6 @@ func main() { } for _, a := range arr { - lib.Challenge("Slice", student.Slice, correct.Slice, a...) + lib.Challenge("Slice", student.Slice, slice, a...) } } diff --git a/tests/go/func/test_sortintegertable.go b/tests/go/func/sortintegertable/main.go similarity index 84% rename from tests/go/func/test_sortintegertable.go rename to tests/go/func/sortintegertable/main.go index ecaf7af3..ca5522b3 100644 --- a/tests/go/func/test_sortintegertable.go +++ b/tests/go/func/sortintegertable/main.go @@ -2,12 +2,15 @@ package main import ( "reflect" + "sort" - "../lib" - "./correct" "./student" ) +func sortIntegerTable(a []int) { + sort.Ints(a) +} + func main() { i := 0 for i < lib.SliceLen { @@ -20,7 +23,7 @@ func main() { copy(table2, table1) student.SortIntegerTable(table1) - correct.SortIntegerTable(table2) + sortIntegerTable(table2) if !reflect.DeepEqual(table1, table2) { lib.Fatalf("SortIntegerTable(%v), table1 == %v instead of %v ", tableCopyBefore, table1, table2) } diff --git a/tests/go/prog/correct/sortparams/main.go b/tests/go/func/sortparams/correct/main.go similarity index 100% rename from tests/go/prog/correct/sortparams/main.go rename to tests/go/func/sortparams/correct/main.go diff --git a/tests/go/prog/test_sortparams.go b/tests/go/func/sortparams/main.go similarity index 100% rename from tests/go/prog/test_sortparams.go rename to tests/go/func/sortparams/main.go diff --git a/tests/go/func/test_sortwordarr.go b/tests/go/func/sortwordarr/main.go similarity index 88% rename from tests/go/func/test_sortwordarr.go rename to tests/go/func/sortwordarr/main.go index 220606cc..d59c552f 100644 --- a/tests/go/func/test_sortwordarr.go +++ b/tests/go/func/sortwordarr/main.go @@ -2,12 +2,15 @@ package main import ( "reflect" + "sort" - "../lib" - "./correct" "./student" ) +func sortWordArr(a []string) { + sort.Strings(a) +} + func main() { table := [][]string{{"a", "A", "1", "b", "B", "2", "c", "C", "3"}} @@ -24,7 +27,7 @@ func main() { copy(cp_sol, org) copy(cp_stu, org) - correct.SortWordArr(cp_sol) + sortWordArr(cp_sol) student.SortWordArr(cp_stu) if !reflect.DeepEqual(cp_stu, cp_sol) { diff --git a/tests/go/func/test_split.go b/tests/go/func/split/main.go similarity index 82% rename from tests/go/func/test_split.go rename to tests/go/func/split/main.go index 01530664..91a7b770 100644 --- a/tests/go/func/test_split.go +++ b/tests/go/func/split/main.go @@ -4,11 +4,13 @@ import ( "math/rand" "strings" - "../lib" - "./correct" "./student" ) +func split(s, sep string) []string { + return strings.Split(s, sep) +} + func main() { separators := []string{"!=HA=!", "!==!", @@ -39,6 +41,6 @@ func main() { node{str: "HelloHAhowHAareHAyou?", sep: "HA"}) for _, arg := range table { - lib.Challenge("Split", student.Split, correct.Split, arg.str, arg.sep) + lib.Challenge("Split", student.Split, split, arg.str, arg.sep) } } diff --git a/tests/go/func/test_splitwhitespaces.go b/tests/go/func/splitwhitespaces/main.go similarity index 66% rename from tests/go/func/test_splitwhitespaces.go rename to tests/go/func/splitwhitespaces/main.go index b99b9571..807df720 100644 --- a/tests/go/func/test_splitwhitespaces.go +++ b/tests/go/func/splitwhitespaces/main.go @@ -3,11 +3,13 @@ package main import ( "strings" - "../lib" - "./correct" "./student" ) +func splitWhiteSpaces(s string) []string { + return strings.Fields(s) +} + func main() { table := []string{} // 30 random slice of strings @@ -21,6 +23,6 @@ func main() { "Hello how are you?") for _, arg := range table { - lib.Challenge("SplitWhiteSpaces", student.SplitWhiteSpaces, correct.SplitWhiteSpaces, arg) + lib.Challenge("SplitWhiteSpaces", student.SplitWhiteSpaces, splitWhiteSpaces, arg) } } diff --git a/tests/go/func/test_sqrt.go b/tests/go/func/sqrt/main.go similarity index 56% rename from tests/go/func/test_sqrt.go rename to tests/go/func/sqrt/main.go index bb899d13..708a4049 100644 --- a/tests/go/func/test_sqrt.go +++ b/tests/go/func/sqrt/main.go @@ -1,11 +1,19 @@ package main import ( - "../lib" - "./correct" + "math" + "./student" ) +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), @@ -25,6 +33,6 @@ func main() { 100, ) for _, arg := range table { - lib.Challenge("Sqrt", student.Sqrt, correct.Sqrt, arg) + lib.Challenge("Sqrt", student.Sqrt, sqrt, arg) } } diff --git a/tests/go/func/test_strlen.go b/tests/go/func/strlen/main.go similarity index 68% rename from tests/go/func/test_strlen.go rename to tests/go/func/strlen/main.go index ef11d6d9..9a5a5ec8 100644 --- a/tests/go/func/test_strlen.go +++ b/tests/go/func/strlen/main.go @@ -1,10 +1,16 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +func strLen(str string) int { + len := 0 + + strConverted := []rune(str) + for i, _ := range strConverted { + len = i + 1 + } + return len +} func main() { randomStringCharset := "a b c d e f g h ijklmnopqrstuvwxyz A B C D E FGHIJKLMNOPRSTUVWXYZ" @@ -19,6 +25,6 @@ func main() { table = append(table, randomStringCharset) for _, s := range table { - lib.Challenge("StrLen", correct.StrLen, student.StrLen, s) + lib.Challenge("StrLen", strLen, student.StrLen, s) } } diff --git a/tests/go/func/strrev/main.go b/tests/go/func/strrev/main.go new file mode 100644 index 00000000..e52e3bdd --- /dev/null +++ b/tests/go/func/strrev/main.go @@ -0,0 +1,27 @@ +package main + +import "./student" + +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/tests/go/func/test_swap.go b/tests/go/func/swap/main.go similarity index 84% rename from tests/go/func/test_swap.go rename to tests/go/func/swap/main.go index 904d937b..ef10a57f 100644 --- a/tests/go/func/test_swap.go +++ b/tests/go/func/swap/main.go @@ -1,9 +1,10 @@ package main -import ( - "../lib" - "./student" -) +import "./student" + +func Swap(a, b *int) { + *a, *b = *b, *a +} func main() { i := 0 diff --git a/tests/go/func/test_swapbits.go b/tests/go/func/swapbits/main.go similarity index 84% rename from tests/go/func/test_swapbits.go rename to tests/go/func/swapbits/main.go index c3f3d3dd..afcb9cab 100644 --- a/tests/go/func/test_swapbits.go +++ b/tests/go/func/swapbits/main.go @@ -3,11 +3,13 @@ package main import ( "reflect" - "../lib" - "./correct" "./student" ) +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) @@ -30,6 +32,6 @@ func main() { } for _, v := range args { - challengeBytes(student.SwapBits, correct.SwapBits, v) + challengeBytes(student.SwapBits, swapBits, v) } } diff --git a/tests/go/func/sweetproblem/main.go b/tests/go/func/sweetproblem/main.go new file mode 100644 index 00000000..0507d48c --- /dev/null +++ b/tests/go/func/sweetproblem/main.go @@ -0,0 +1,94 @@ +package main + +import "./student" + +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/tests/go/prog/correct/switchcase/main.go b/tests/go/func/switchcase/correct/main.go similarity index 100% rename from tests/go/prog/correct/switchcase/main.go rename to tests/go/func/switchcase/correct/main.go diff --git a/tests/go/prog/test_switchcase.go b/tests/go/func/switchcase/main.go similarity index 100% rename from tests/go/prog/test_switchcase.go rename to tests/go/func/switchcase/main.go diff --git a/tests/go/prog/correct/tabmult/main.go b/tests/go/func/tabmult/correct/main.go similarity index 100% rename from tests/go/prog/correct/tabmult/main.go rename to tests/go/func/tabmult/correct/main.go diff --git a/tests/go/prog/test_tabmult.go b/tests/go/func/tabmult/main.go similarity index 100% rename from tests/go/prog/test_tabmult.go rename to tests/go/func/tabmult/main.go diff --git a/tests/go/func/test_abort.go b/tests/go/func/test_abort.go deleted file mode 100644 index 0cac3199..00000000 --- a/tests/go/func/test_abort.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - arg := lib.MultRandInt() - arg = append(arg, lib.RandInt()) - for i := 0; i < 15; i++ { - lib.Challenge("Abort", student.Abort, correct.Abort, arg[0], arg[1], arg[2], arg[3], arg[4]) - arg = lib.MultRandInt() - arg = append(arg, lib.RandInt()) - } -} diff --git a/tests/go/func/test_activebits.go b/tests/go/func/test_activebits.go deleted file mode 100644 index c057f3b8..00000000 --- a/tests/go/func/test_activebits.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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, correct.ActiveBits, v) - } -} diff --git a/tests/go/func/test_capitalize.go b/tests/go/func/test_capitalize.go deleted file mode 100644 index c2d5b720..00000000 --- a/tests/go/func/test_capitalize.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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, correct.Capitalize, arg) - } -} diff --git a/tests/go/func/test_eightqueens.go b/tests/go/func/test_eightqueens.go deleted file mode 100644 index b23ab595..00000000 --- a/tests/go/func/test_eightqueens.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - lib.Challenge("EightQueens", student.EightQueens, correct.EightQueens) -} diff --git a/tests/go/func/test_fib.go b/tests/go/func/test_fib.go deleted file mode 100644 index ef795d85..00000000 --- a/tests/go/func/test_fib.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - table := []int{ - 20, - 0, - 9, - 2, - } - table = append(table, lib.MultRandIntBetween(-100, 150)...) - for _, arg := range table { - lib.Challenge("Fib", student.Fib, correct.Fib, arg) - } -} diff --git a/tests/go/func/test_fibonacci.go b/tests/go/func/test_fibonacci.go deleted file mode 100644 index de614853..00000000 --- a/tests/go/func/test_fibonacci.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - table := append( - lib.MultRandIntBetween(0, 25), - 4, - 5, - -5, - ) - for _, arg := range table { - lib.Challenge("Fibonacci", student.Fibonacci, correct.Fibonacci, arg) - } -} diff --git a/tests/go/func/test_findprevprime.go b/tests/go/func/test_findprevprime.go deleted file mode 100644 index b5ea44a1..00000000 --- a/tests/go/func/test_findprevprime.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - a := append(lib.MultRandIntBetween(0, 99999), 5, 4, 1) - for _, elem := range a { - lib.Challenge("FindPrevPrime", student.FindPrevPrime, correct.FindPrevPrime, elem) - } -} diff --git a/tests/go/func/test_firstrune.go b/tests/go/func/test_firstrune.go deleted file mode 100644 index 92ebe463..00000000 --- a/tests/go/func/test_firstrune.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - table := append( - lib.MultRandASCII(), - "Hello!", - "Salut!", - "Ola!", - "♥01", - ) - for _, arg := range table { - lib.Challenge("FirstRune", student.FirstRune, correct.FirstRune, arg) - } -} diff --git a/tests/go/func/test_interestingnumber.go b/tests/go/func/test_interestingnumber.go deleted file mode 100644 index 8a003956..00000000 --- a/tests/go/func/test_interestingnumber.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - table := []int{ - 20, - 1, - 9, - 2, - } - table = append(table, lib.MultRandIntBetween(1, 1500)...) - - for _, arg := range table { - lib.Challenge("InterestingNumber", student.InterestingNumber, correct.InterestingNumber, arg) - } -} diff --git a/tests/go/func/test_isnegative.go b/tests/go/func/test_isnegative.go deleted file mode 100644 index 39a55afa..00000000 --- a/tests/go/func/test_isnegative.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - table := append( - lib.MultRandInt(), - lib.MinInt, - lib.MaxInt, - 0, - ) - for _, arg := range table { - lib.Challenge("IsNegative", student.IsNegative, correct.IsNegative, arg) - } -} diff --git a/tests/go/func/test_iterativefactorial.go b/tests/go/func/test_iterativefactorial.go deleted file mode 100644 index 2f512fae..00000000 --- a/tests/go/func/test_iterativefactorial.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "math/bits" - - "../lib" - "./correct" - "./student" -) - -func main() { - table := append( - lib.MultRandInt(), - lib.IntRange(0, 12)..., - ) - if bits.UintSize == 64 { - table = append(table, lib.IntRange(13, 20)...) - } - for _, arg := range table { - lib.Challenge("IterativeFactorial", student.IterativeFactorial, correct.IterativeFactorial, arg) - } -} diff --git a/tests/go/func/test_nauuo.go b/tests/go/func/test_nauuo.go deleted file mode 100644 index de339b9e..00000000 --- a/tests/go/func/test_nauuo.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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, correct.Nauuo, arg.plus, arg.minus, arg.rand) - } -} diff --git a/tests/go/func/test_printcomb.go b/tests/go/func/test_printcomb.go deleted file mode 100644 index 9f9a440a..00000000 --- a/tests/go/func/test_printcomb.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - lib.Challenge("PrintComb", student.PrintComb, correct.PrintComb) -} diff --git a/tests/go/func/test_printcomb2.go b/tests/go/func/test_printcomb2.go deleted file mode 100644 index 0013a15c..00000000 --- a/tests/go/func/test_printcomb2.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - lib.Challenge("PrintComb2", student.PrintComb2, correct.PrintComb2) -} diff --git a/tests/go/func/test_printcombn.go b/tests/go/func/test_printcombn.go deleted file mode 100644 index 1bc8bff9..00000000 --- a/tests/go/func/test_printcombn.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - table := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} - for _, arg := range table { - lib.Challenge("PrintCombN", student.PrintCombN, correct.PrintCombN, arg) - } -} diff --git a/tests/go/func/test_printmemory.go b/tests/go/func/test_printmemory.go deleted file mode 100644 index cae98caa..00000000 --- a/tests/go/func/test_printmemory.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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, correct.PrintMemory, table) - } - table2 := [10]int{104, 101, 108, 108, 111, 16, 21, 42} - lib.Challenge("PrintMemory", student.PrintMemory, correct.PrintMemory, table2) -} - -// TODO: this can be simplified a lot diff --git a/tests/go/func/test_printnbrinorder.go b/tests/go/func/test_printnbrinorder.go deleted file mode 100644 index 4d78c858..00000000 --- a/tests/go/func/test_printnbrinorder.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - table := append( - lib.MultRandIntBetween(0, lib.MaxInt), - lib.MaxInt, - 321, - 321321, - 0, - ) - for _, arg := range table { - lib.Challenge("PrintNbrInOrder", student.PrintNbrInOrder, correct.PrintNbrInOrder, arg) - } -} diff --git a/tests/go/func/test_priorprime.go b/tests/go/func/test_priorprime.go deleted file mode 100644 index df139e2e..00000000 --- a/tests/go/func/test_priorprime.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - table := []int{ - 50, - 13, - 10, - 0, - 1, - 2, - } - table = append(table, lib.MultRandIntBetween(0, 1000)) - for _, arg := range table { - lib.Challenge("PriorPrime", student.PriorPrime, correct.PriorPrime, arg) - } -} diff --git a/tests/go/func/test_raid1a.go b/tests/go/func/test_raid1a.go deleted file mode 100644 index 25d38817..00000000 --- a/tests/go/func/test_raid1a.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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("Raid1a", correct.Raid1a, student.Raid1a, table[i], table[i+1]) - } - } -} diff --git a/tests/go/func/test_raid1b.go b/tests/go/func/test_raid1b.go deleted file mode 100644 index 47350347..00000000 --- a/tests/go/func/test_raid1b.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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("Raid1b", correct.Raid1b, student.Raid1b, table[i], table[i+1]) - } - } -} diff --git a/tests/go/func/test_raid1c.go b/tests/go/func/test_raid1c.go deleted file mode 100644 index 03ff4acd..00000000 --- a/tests/go/func/test_raid1c.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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("Raid1c", correct.Raid1c, student.Raid1c, table[i], table[i+1]) - } - } -} diff --git a/tests/go/func/test_raid1d.go b/tests/go/func/test_raid1d.go deleted file mode 100644 index 78485cfd..00000000 --- a/tests/go/func/test_raid1d.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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("Raid1d", correct.Raid1d, student.Raid1d, table[i], table[i+1]) - } - } -} diff --git a/tests/go/func/test_raid1e.go b/tests/go/func/test_raid1e.go deleted file mode 100644 index 845538ba..00000000 --- a/tests/go/func/test_raid1e.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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("Raid1e", correct.Raid1e, student.Raid1e, table[i], table[i+1]) - } - } -} diff --git a/tests/go/func/test_reachablenumber.go b/tests/go/func/test_reachablenumber.go deleted file mode 100644 index f568b96c..00000000 --- a/tests/go/func/test_reachablenumber.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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, correct.ReachableNumber, arg) - } -} diff --git a/tests/go/func/test_recursivefactorial.go b/tests/go/func/test_recursivefactorial.go deleted file mode 100644 index c37d7aae..00000000 --- a/tests/go/func/test_recursivefactorial.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "math/bits" - - "../lib" - "./correct" - "./student" -) - -func main() { - table := append( - lib.MultRandInt(), - lib.IntRange(0, 12)..., - ) - if bits.UintSize == 64 { - table = append(table, lib.IntRange(13, 20)...) - } - for _, arg := range table { - lib.Challenge("RecursiveFactorial", student.RecursiveFactorial, correct.RecursiveFactorial, arg) - } -} diff --git a/tests/go/func/test_revivethreenums.go b/tests/go/func/test_revivethreenums.go deleted file mode 100644 index b634b401..00000000 --- a/tests/go/func/test_revivethreenums.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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, correct.ReviveThreeNums, arg[0], arg[1], arg[2], arg[3]) - } -} diff --git a/tests/go/func/test_rot14.go b/tests/go/func/test_rot14.go deleted file mode 100644 index 8dcf4681..00000000 --- a/tests/go/func/test_rot14.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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", correct.Rot14, student.Rot14, s) - } - } -} diff --git a/tests/go/func/test_strrev.go b/tests/go/func/test_strrev.go deleted file mode 100644 index b2208e9b..00000000 --- a/tests/go/func/test_strrev.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -func main() { - table := append( - lib.MultRandASCII(), - "Hello!", - "Bonjour!", - "Hola!", - ) - for _, arg := range table { - lib.Challenge("StrRev", student.StrRev, correct.StrRev, arg) - } -} diff --git a/tests/go/func/test_sweetproblem.go b/tests/go/func/test_sweetproblem.go deleted file mode 100644 index cae72922..00000000 --- a/tests/go/func/test_sweetproblem.go +++ /dev/null @@ -1,42 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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, correct.Sweetproblem, arg.red, arg.green, arg.blue) - } -} diff --git a/tests/go/func/test_trimatoi.go b/tests/go/func/test_trimatoi.go deleted file mode 100644 index f62c877d..00000000 --- a/tests/go/func/test_trimatoi.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "../lib" - "./correct" - "./student" -) - -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, correct.TrimAtoi, elem) - } -} diff --git a/tests/go/func/test_twosum.go b/tests/go/func/test_twosum.go deleted file mode 100644 index 6d9d4a0a..00000000 --- a/tests/go/func/test_twosum.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "math/rand" - - "../lib" - "./correct" - "./student" -) - -func main() { - for i := 0; i < 20; i++ { - token := rand.Perm(20) - target := rand.Intn(30) - lib.Challenge("TwoSum", student.TwoSum, correct.TwoSum, token, target) - } -} diff --git a/tests/go/prog/correct/tetrisoptimizer/board.go b/tests/go/func/tetrisoptimizer/correct/board.go similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/board.go rename to tests/go/func/tetrisoptimizer/correct/board.go diff --git a/tests/go/prog/correct/tetrisoptimizer/main.go b/tests/go/func/tetrisoptimizer/correct/main.go similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/main.go rename to tests/go/func/tetrisoptimizer/correct/main.go diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/bad00.txt b/tests/go/func/tetrisoptimizer/correct/samples/bad00.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/bad00.txt rename to tests/go/func/tetrisoptimizer/correct/samples/bad00.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/bad01.txt b/tests/go/func/tetrisoptimizer/correct/samples/bad01.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/bad01.txt rename to tests/go/func/tetrisoptimizer/correct/samples/bad01.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/bad02.txt b/tests/go/func/tetrisoptimizer/correct/samples/bad02.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/bad02.txt rename to tests/go/func/tetrisoptimizer/correct/samples/bad02.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/bad03.txt b/tests/go/func/tetrisoptimizer/correct/samples/bad03.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/bad03.txt rename to tests/go/func/tetrisoptimizer/correct/samples/bad03.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/bad04.txt b/tests/go/func/tetrisoptimizer/correct/samples/bad04.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/bad04.txt rename to tests/go/func/tetrisoptimizer/correct/samples/bad04.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/badFormat.txt b/tests/go/func/tetrisoptimizer/correct/samples/badFormat.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/badFormat.txt rename to tests/go/func/tetrisoptimizer/correct/samples/badFormat.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_01-1-2-0.00.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_01-1-2-0.00.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_01-1-2-0.00.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_01-1-2-0.00.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_02-1-4-0.00.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_02-1-4-0.00.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_02-1-4-0.00.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_02-1-4-0.00.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_03-2-4-0.00.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_03-2-4-0.00.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_03-2-4-0.00.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_03-2-4-0.00.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_04-6-6-0.00.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_04-6-6-0.00.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_04-6-6-0.00.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_04-6-6-0.00.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_05-21-10-0.00.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_05-21-10-0.00.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_05-21-10-0.00.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_05-21-10-0.00.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_06-22-10-0.00.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_06-22-10-0.00.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_06-22-10-0.00.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_06-22-10-0.00.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_07-26-11-0.00.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_07-26-11-0.00.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_07-26-11-0.00.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_07-26-11-0.00.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_08-24-10-0.03.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_08-24-10-0.03.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_08-24-10-0.03.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_08-24-10-0.03.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_09-11-7-0.07.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_09-11-7-0.07.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_09-11-7-0.07.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_09-11-7-0.07.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_10-12-7-0.52.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_10-12-7-0.52.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_10-12-7-0.52.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_10-12-7-0.52.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_11-12-8-0.83.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_11-12-8-0.83.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_11-12-8-0.83.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_11-12-8-0.83.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_12-19-9-3.40.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_12-19-9-3.40.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_12-19-9-3.40.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_12-19-9-3.40.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_13-23-10-4.72.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_13-23-10-4.72.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_13-23-10-4.72.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_13-23-10-4.72.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_14-15-8-7.34.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_14-15-8-7.34.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_14-15-8-7.34.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_14-15-8-7.34.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/samples/good_15-26-11-72.22.txt b/tests/go/func/tetrisoptimizer/correct/samples/good_15-26-11-72.22.txt similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/samples/good_15-26-11-72.22.txt rename to tests/go/func/tetrisoptimizer/correct/samples/good_15-26-11-72.22.txt diff --git a/tests/go/prog/correct/tetrisoptimizer/solver.go b/tests/go/func/tetrisoptimizer/correct/solver.go similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/solver.go rename to tests/go/func/tetrisoptimizer/correct/solver.go diff --git a/tests/go/prog/correct/tetrisoptimizer/tetrimino.go b/tests/go/func/tetrisoptimizer/correct/tetrimino.go similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/tetrimino.go rename to tests/go/func/tetrisoptimizer/correct/tetrimino.go diff --git a/tests/go/prog/correct/tetrisoptimizer/validation.go b/tests/go/func/tetrisoptimizer/correct/validation.go similarity index 100% rename from tests/go/prog/correct/tetrisoptimizer/validation.go rename to tests/go/func/tetrisoptimizer/correct/validation.go diff --git a/tests/go/prog/test_tetrisoptimizer.go b/tests/go/func/tetrisoptimizer/main.go similarity index 100% rename from tests/go/prog/test_tetrisoptimizer.go rename to tests/go/func/tetrisoptimizer/main.go diff --git a/tests/go/func/test_tolower.go b/tests/go/func/tolower/main.go similarity index 54% rename from tests/go/func/test_tolower.go rename to tests/go/func/tolower/main.go index cc179c93..6444acaa 100644 --- a/tests/go/func/test_tolower.go +++ b/tests/go/func/tolower/main.go @@ -1,17 +1,21 @@ package main import ( - "../lib" - "./correct" + "strings" + "./student" ) +func toLower(s string) string { + return strings.ToLower(s) +} + func main() { table := append( lib.MultRandASCII(), "Hello! How are you?", ) for _, arg := range table { - lib.Challenge("ToLower", student.ToLower, correct.ToLower, arg) + lib.Challenge("ToLower", student.ToLower, toLower, arg) } } diff --git a/tests/go/func/test_toupper.go b/tests/go/func/toupper/main.go similarity index 56% rename from tests/go/func/test_toupper.go rename to tests/go/func/toupper/main.go index 270a26d8..b7bd7b0e 100644 --- a/tests/go/func/test_toupper.go +++ b/tests/go/func/toupper/main.go @@ -1,11 +1,15 @@ package main import ( - "../lib" - "./correct" + "strings" + "./student" ) +func toUpper(s string) string { + return strings.ToUpper(s) +} + func main() { table := lib.MultRandASCII() @@ -14,6 +18,6 @@ func main() { ) for _, arg := range table { - lib.Challenge("ToUpper", student.ToUpper, correct.ToUpper, arg) + lib.Challenge("ToUpper", student.ToUpper, toUpper, arg) } } diff --git a/tests/go/func/trimatoi/main.go b/tests/go/func/trimatoi/main.go new file mode 100644 index 00000000..9292346e --- /dev/null +++ b/tests/go/func/trimatoi/main.go @@ -0,0 +1,67 @@ +package main + +import "./student" + +func trimAtoi(str string) int { + chars := []rune(str) + for i := range str { + chars[i] = rune(str[i]) + } + var numbers []rune + for i := range chars { + if (chars[i] >= '0' && chars[i] <= '9') || (len(numbers) == 0 && (chars[i]) == '-' || chars[i] == '+') { + numbers = append(numbers, chars[i]) + } + } + 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) + } +} diff --git a/tests/go/func/twosum/main.go b/tests/go/func/twosum/main.go new file mode 100644 index 00000000..3e923214 --- /dev/null +++ b/tests/go/func/twosum/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "math/rand" + + "./student" +) + +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/tests/go/func/test_ultimatedivmod.go b/tests/go/func/ultimatedivmod/main.go similarity index 80% rename from tests/go/func/test_ultimatedivmod.go rename to tests/go/func/ultimatedivmod/main.go index 0e80ef6d..32083749 100644 --- a/tests/go/func/test_ultimatedivmod.go +++ b/tests/go/func/ultimatedivmod/main.go @@ -1,9 +1,12 @@ package main -import ( - "../lib" - "./student" -) +import "./student" + +func UltimateDivMod(a, b *int) { + temp := *a + *a = *a / *b + *b = temp % *b +} func main() { i := 0 diff --git a/tests/go/func/test_ultimatepointone.go b/tests/go/func/ultimatepointone/main.go similarity index 71% rename from tests/go/func/test_ultimatepointone.go rename to tests/go/func/ultimatepointone/main.go index 1eeb98ce..9abac990 100644 --- a/tests/go/func/test_ultimatepointone.go +++ b/tests/go/func/ultimatepointone/main.go @@ -1,9 +1,10 @@ package main -import ( - "../lib" - "./student" -) +import "./student" + +func UltimatePointOne(n ***int) { + ***n = 1 +} func main() { a := 0 diff --git a/tests/go/prog/correct/union/main.go b/tests/go/func/union/correct/main.go similarity index 100% rename from tests/go/prog/correct/union/main.go rename to tests/go/func/union/correct/main.go diff --git a/tests/go/prog/test_union.go b/tests/go/func/union/main.go similarity index 100% rename from tests/go/prog/test_union.go rename to tests/go/func/union/main.go diff --git a/tests/go/prog/correct/uniqueoccurences/main.go b/tests/go/func/uniqueoccurences/correct/main.go similarity index 100% rename from tests/go/prog/correct/uniqueoccurences/main.go rename to tests/go/func/uniqueoccurences/correct/main.go diff --git a/tests/go/prog/test_uniqueoccurences.go b/tests/go/func/uniqueoccurences/main.go similarity index 100% rename from tests/go/prog/test_uniqueoccurences.go rename to tests/go/func/uniqueoccurences/main.go diff --git a/tests/go/func/test_unmatch.go b/tests/go/func/unmatch/main.go similarity index 66% rename from tests/go/func/test_unmatch.go rename to tests/go/func/unmatch/main.go index 4f306426..00ca05e8 100644 --- a/tests/go/func/test_unmatch.go +++ b/tests/go/func/unmatch/main.go @@ -1,10 +1,23 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +// Returns the element of the slice that doesn't have a correspondant pair +func unmatch(arr []int) int { + var quant int + for _, el := range arr { + quant = 0 + for _, v := range arr { + if v == el { + quant++ + } + } + if quant%2 != 0 { + return el + } + } + return -1 +} func main() { arg1 := []int{1, 1, 2, 3, 4, 3, 4} @@ -24,6 +37,6 @@ func main() { args := [][]int{arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8} for _, v := range args { - lib.Challenge("Unmatch", student.Unmatch, correct.Unmatch, v) + lib.Challenge("Unmatch", student.Unmatch, unmatch, v) } } diff --git a/tests/go/func/test_volumechanger.go b/tests/go/func/volumechanger/main.go similarity index 50% rename from tests/go/func/test_volumechanger.go rename to tests/go/func/volumechanger/main.go index 813e2784..c672a1c2 100644 --- a/tests/go/func/test_volumechanger.go +++ b/tests/go/func/volumechanger/main.go @@ -1,10 +1,17 @@ package main -import ( - "../lib" - "./correct" - "./student" -) +import "./student" + +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{ @@ -20,6 +27,6 @@ func main() { }) } for _, arg := range table { - lib.Challenge("Volumechanger", student.Volumechanger, correct.Volumechanger, arg[0], arg[1]) + lib.Challenge("Volumechanger", student.Volumechanger, volumechanger, arg[0], arg[1]) } } diff --git a/tests/go/prog/correct/wdmatch/main.go b/tests/go/func/wdmatch/correct/main.go similarity index 100% rename from tests/go/prog/correct/wdmatch/main.go rename to tests/go/func/wdmatch/correct/main.go diff --git a/tests/go/prog/test_wdmatch.go b/tests/go/func/wdmatch/main.go similarity index 100% rename from tests/go/prog/test_wdmatch.go rename to tests/go/func/wdmatch/main.go diff --git a/tests/go/prog/correct/ztail/main.go b/tests/go/func/ztail/correct/main.go similarity index 100% rename from tests/go/prog/correct/ztail/main.go rename to tests/go/func/ztail/correct/main.go diff --git a/tests/go/prog/test_ztail.go b/tests/go/func/ztail/main.go similarity index 100% rename from tests/go/prog/test_ztail.go rename to tests/go/func/ztail/main.go diff --git a/tests/go/lib/lib.go b/tests/go/lib/lib.go index 461bbdeb..03eb723d 100644 --- a/tests/go/lib/lib.go +++ b/tests/go/lib/lib.go @@ -16,13 +16,15 @@ import ( "unicode/utf8" ) -const ( - IntSize = bits.UintSize - 1 // 31 or 63 +func init() { + if bits.UintSize != 64 { + panic("only works on 64 bits CPU") + } +} - // 32 bits 64 bits - MinInt = -1 << IntSize // -2147483648 -9223372036854775808 - MaxInt = 1<