diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 4ee173d5..766e2911 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -2,9 +2,8 @@ name: Bug report about: Create a report to help us improve title: "[INSCRIPTION FORM] - input type date doesn't appear in safari" -labels: '' -assignees: '' - +labels: "" +assignees: "" --- **Describe the bug** @@ -12,6 +11,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: + 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' @@ -24,15 +24,17 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] + +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] **Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] + +- Device: [e.g. iPhone6] +- OS: [e.g. iOS8.1] +- Browser [e.g. stock browser, safari] +- Version [e.g. 22] **Additional context** Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 30b105ab..8be7f123 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,10 +1,9 @@ --- name: Feature request about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' - +title: "" +labels: "" +assignees: "" --- **Is your feature request related to a problem? Please describe.** diff --git a/README.md b/README.md index 939619e5..369177c5 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# public \ No newline at end of file +# public diff --git a/docs/addition_of_exercise_draft.md b/docs/addition_of_exercise_draft.md index 4a653a92..f2f5050c 100644 --- a/docs/addition_of_exercise_draft.md +++ b/docs/addition_of_exercise_draft.md @@ -1,15 +1,14 @@ # THE ADDITION OF EXERCISE PROCEDURE - ##### This is for a go exercise in the piscine-go ## **1. Writing the subject and / or writing the solution** - + Always address each exceptional cases. -Example: [fprime](https://github.com/01-edu/public/blob/master/subjects/fprime.en.md). +Example: [fprime](https://github.com/01-edu/public/blob/master/subjects/fprime.en.md). -The exceptional cases in the `usage` part. +The exceptional cases in the `usage` part. ```console student@ubuntu:~/piscine-go/test$ go build @@ -39,22 +38,21 @@ Some students found this mistake. An update of the subject during the exam treat 2. Always check the formating md ------- +--- -### fprime (Title of the exercise) +### fprime (Title of the exercise) #### Instructions (Instructions of the exercise) - Write a program that takes a positive `int` and displays its prime factors, followed by a newline (`'\n'`). (general guidelines, notice the imperative style tense and the avoidance of “you”. “You” is authorized in the case of a presence of a back story where the player is immersed) -- Factors must be displayed in ascending order and separated by `*`. (formating requirement) +- Factors must be displayed in ascending order and separated by `*`. (formating requirement) -- If the number of parameters is different from 1, the program displays a newline. (special case requirement, this case will need to be tested) +- If the number of parameters is different from 1, the program displays a newline. (special case requirement, this case will need to be tested) -- The input, when there is one, will always be valid. (Clarification on what the tester will do, hence giving the student guidelines on the cases to be handled, the tests have to reflect this instruction as well) +- The input, when there is one, will always be valid. (Clarification on what the tester will do, hence giving the student guidelines on the cases to be handled, the tests have to reflect this instruction as well) -- In this exercise the primes factor of 1 is considered as 1. (Handling of exceptional case: THIS Happens to be a mistake, we will see uses this example for the “UPDATING A SUBJECT/TEST PROCEDURE”) +- In this exercise the primes factor of 1 is considered as 1. (Handling of exceptional case: THIS Happens to be a mistake, we will see uses this example for the “UPDATING A SUBJECT/TEST PROCEDURE”) ### Usage @@ -79,11 +77,11 @@ student@ubuntu:~/piscine-go/test$ ./test 1 student@ubuntu:~/piscine-go/test$ ``` ------- +--- ## **2. Creating the files for tests (4 main cases)** -### always in -> *all/tests/go/* +### always in -> _all/tests/go/_ ### **Folder organization** @@ -98,7 +96,7 @@ go | | __ solutions | |-strlen.go (package solutions) -| +| | __ student (the same thing as the solutions, just run "cp -aT solutions/ student/") ``` @@ -149,12 +147,12 @@ go | |-atoi.go (package solutions) | |__atoiprog | |-main.go (package main)(func main(){} stays empty) -| |-atoiprog_test.go +| |-atoiprog_test.go | | __ student (the same thing as the solutions, just run "cp -aT solutions/ student/") ``` ------- +--- ## **3. Writing a file_test.go (test file for go)** @@ -164,8 +162,8 @@ go - **If** the source is not in the import section, copy and paste the function, with **lowercase** for the first letter of its name. -- Example: addprimesum_test.go - +- Example: addprimesum_test.go + ![isaprime](isaprime.png) The func isAPrime is fully copied to the file. @@ -176,19 +174,19 @@ Every special case in the subject should be tested. Preferably first. Before the ### **RULE 3** -Whenever possible do at least 1 random test! This is to avoid cheating by predictability of the tests. If the tests are fixed, then the student may create a forest of ifs program to bypass the tester. +Whenever possible do at least 1 random test! This is to avoid cheating by predictability of the tests. If the tests are fixed, then the student may create a forest of ifs program to bypass the tester. ### z01.functions to be used by tester -- Function exercise in a Quest (strlen) ![z01sl](strlenz01.png) - +- Function exercise in a Quest (strlen) ![z01sl](strlenz01.png) + ```go z01.Challenge(t, studentSol, studentStu) // if the program doesn’t have arguments z01.Challenge(t, studentSol, studentStu, args...) //if the program has arguments ``` -- Program exercise in a Quest (doop) ![z01doop](doopz01.png)<- Screenshots to be added. +- Program exercise in a Quest (doop) ![z01doop](doopz01.png)<- Screenshots to be added. ```go z01.ChallengeMain(t) // if the program doesn’t have arguments @@ -212,7 +210,7 @@ z01.Challenge(t, studentSol, studentStu) // if the program doesn’t have argume z01.Challenge(t, studentSol, studentStu, args...) //if the program has arguments ``` ------- +--- ## **4. Testing locally (`go test` or `go test -run=Test\`)** @@ -229,7 +227,7 @@ cp -aT solutions/ student ### Execute a go test in the appropriate folder -- Function exercise in a Quest `(strlen)` ![](image.png) +- Function exercise in a Quest `(strlen)` ![](image.png) `all/test/go` @@ -237,7 +235,7 @@ cp -aT solutions/ student go test -run=TestStrlen ``` -- Program exercise in a Quest `(doop)` ![](image.png)<- Screenshots to be added. +- Program exercise in a Quest `(doop)` ![](image.png)<- Screenshots to be added. `all/test/go/` @@ -247,7 +245,7 @@ go test -run=TestDoop - Program exercise in the exam `(dooprog)` Screenshots to be added. -Here you can do just *go test*, because there's only one test file +Here you can do just _go test_, because there's only one test file `all/test/go/student/dooprog` @@ -263,16 +261,15 @@ go test go test ``` +### **NOTE:** If a go test gives a (cached) result, use this type of command (example with raid3): -### **NOTE:** If a go test gives a (cached) result, use this type of command (example with raid3): - -```go test count=1 raid3_test.go``` +`go test count=1 raid3_test.go` The result should be an OK message: -- This means that the test is running correctly when the correct solution is given. If this does not work, the test file is likely to have errors inside. +- This means that the test is running correctly when the correct solution is given. If this does not work, the test file is likely to have errors inside. -- Time should be under 5-6 seconds. If longer, remove some of the iteration of the random tests (for example, less random tests) +- Time should be under 5-6 seconds. If longer, remove some of the iteration of the random tests (for example, less random tests) - Be watchful of exercises with challenge function: Always test a copy of the variable and not the same variable for both the student and the solution function. diff --git a/docs/bios-configuration.md b/docs/bios-configuration.md index 21fdfab4..c4fed426 100644 --- a/docs/bios-configuration.md +++ b/docs/bios-configuration.md @@ -4,17 +4,17 @@ F10 (Open Setup) -- _Security_ - - _Create BIOS Administrator Password_ → Set password -- _Advanced_ - - _Boot Options_ - - _USB Storage Boot_ → Disabled - - _Fast Boot_ → Disabled (disturbs network boot) - - _Audio Alerts During Boot_ → Disabled (very noisy) - - _HP Sure Recover_ - - _HP Sure Recover_ → Disabled (tries to restore Windows) - - _Secure Boot Configuration_ - - _Configure Legacy Support and Secure Boot_ → «Legacy Support Disable and Secure Boot Disable» (**TODO**: use Secure Boot) +- _Security_ + - _Create BIOS Administrator Password_ → Set password +- _Advanced_ + - _Boot Options_ + - _USB Storage Boot_ → Disabled + - _Fast Boot_ → Disabled (disturbs network boot) + - _Audio Alerts During Boot_ → Disabled (very noisy) + - _HP Sure Recover_ + - _HP Sure Recover_ → Disabled (tries to restore Windows) + - _Secure Boot Configuration_ + - _Configure Legacy Support and Secure Boot_ → «Legacy Support Disable and Secure Boot Disable» (**TODO**: use Secure Boot) F10 → Yes (Save changes & Reboot) @@ -22,8 +22,8 @@ ## Automation -- Can be automated using Intel vPro/AMT (**TODO**) -- Can be partially automated with a USB programmable keyboard such as : - - [USB Rubber Ducky](https://shop.hak5.org/products/usb-rubber-ducky-deluxe) - - [XK-24 USB Programmable Keypad for Windows or Mac](https://www.amazon.com/gp/product/B003MB780E) - - [Cactus WHID: WiFi HID Injector USB Rubberducky](https://www.tindie.com/products/aprbrother/cactus-whid-wifi-hid-injector-usb-rubberducky/) +- Can be automated using Intel vPro/AMT (**TODO**) +- Can be partially automated with a USB programmable keyboard such as : + - [USB Rubber Ducky](https://shop.hak5.org/products/usb-rubber-ducky-deluxe) + - [XK-24 USB Programmable Keypad for Windows or Mac](https://www.amazon.com/gp/product/B003MB780E) + - [Cactus WHID: WiFi HID Injector USB Rubberducky](https://www.tindie.com/products/aprbrother/cactus-whid-wifi-hid-injector-usb-rubberducky/) diff --git a/docs/grand-prix-go-curriculum.md b/docs/grand-prix-go-curriculum.md index 98783e5f..3ef55b0e 100644 --- a/docs/grand-prix-go-curriculum.md +++ b/docs/grand-prix-go-curriculum.md @@ -12,27 +12,27 @@ Notions: basic usage and interaction with a command line terminal. Videos: -- 1-2 `curl` with the GitHub api and Example of shell file | https://www.youtube.com/watch?v=A0Mqc215igw -- 1-3 `touch`, `chmod` and `echo` | https://www.youtube.com/watch?v=21h-vsuXgDU -- 1-4 `find` and `grep` | https://www.youtube.com/watch?v=7a1JSWHhJlM -- 1-5 `cut`, `sed` and `tr` | https://www.youtube.com/watch?v=Nil7rVP3eMI -- 1-6 `jq` and `wc` | https://www.youtube.com/watch?v=cQmcaOseuiA& +- 1-2 `curl` with the GitHub api and Example of shell file | https://www.youtube.com/watch?v=A0Mqc215igw +- 1-3 `touch`, `chmod` and `echo` | https://www.youtube.com/watch?v=21h-vsuXgDU +- 1-4 `find` and `grep` | https://www.youtube.com/watch?v=7a1JSWHhJlM +- 1-5 `cut`, `sed` and `tr` | https://www.youtube.com/watch?v=Nil7rVP3eMI +- 1-6 `jq` and `wc` | https://www.youtube.com/watch?v=cQmcaOseuiA& Exercices: -- introduction | https://public.01-edu.org/subjects/introduction.en -- make-it-better | https://public.01-edu.org/subjects/make-it-better.en -- to-git-or-not-to-git | https://public.01-edu.org/subjects/to-git-or-not-to-git.en -- who-are-you | https://public.01-edu.org/subjects/who-are-you.en -- cl-camp1 | https://public.01-edu.org/subjects/cl-camp1.en -- cl-camp2 | https://public.01-edu.org/subjects/cl-camp2.en -- cl-camp3 | https://public.01-edu.org/subjects/cl-camp3.en -- cl-camp4 | https://public.01-edu.org/subjects/cl-camp4.en -- cl-camp5 | https://public.01-edu.org/subjects/cl-camp5.en -- cl-camp6 | https://public.01-edu.org/subjects/cl-camp6.en -- cl-camp7 | https://public.01-edu.org/subjects/cl-camp7.en -- cl-camp8 | https://public.01-edu.org/subjects/cl-camp8.en -- now-get-to-work | https://public.01-edu.org/subjects/now-get-to-work.en +- introduction | https://public.01-edu.org/subjects/introduction.en +- make-it-better | https://public.01-edu.org/subjects/make-it-better.en +- to-git-or-not-to-git | https://public.01-edu.org/subjects/to-git-or-not-to-git.en +- who-are-you | https://public.01-edu.org/subjects/who-are-you.en +- cl-camp1 | https://public.01-edu.org/subjects/cl-camp1.en +- cl-camp2 | https://public.01-edu.org/subjects/cl-camp2.en +- cl-camp3 | https://public.01-edu.org/subjects/cl-camp3.en +- cl-camp4 | https://public.01-edu.org/subjects/cl-camp4.en +- cl-camp5 | https://public.01-edu.org/subjects/cl-camp5.en +- cl-camp6 | https://public.01-edu.org/subjects/cl-camp6.en +- cl-camp7 | https://public.01-edu.org/subjects/cl-camp7.en +- cl-camp8 | https://public.01-edu.org/subjects/cl-camp8.en +- now-get-to-work | https://public.01-edu.org/subjects/now-get-to-work.en ### Sprint 2 @@ -42,21 +42,21 @@ Notions: Variables declaration, Loops, if and else statement, usage of z01.Print Videos: -- 02-01-If and Else Statements in Go | https://www.youtube.com/watch?v=rnF1_SfeGE4 -- 02-02-ForLoops | https://www.youtube.com/watch?v=Bt47lx6q2-4 -- 02-03-PrintRune function | https://www.youtube.com/watch?v=o8JrvI3jqoM -- 02-04-Variables Declaration and ascii | https://www.youtube.com/watch?v=RCNOV8m0hJQ +- 02-01-If and Else Statements in Go | https://www.youtube.com/watch?v=rnF1_SfeGE4 +- 02-02-ForLoops | https://www.youtube.com/watch?v=Bt47lx6q2-4 +- 02-03-PrintRune function | https://www.youtube.com/watch?v=o8JrvI3jqoM +- 02-04-Variables Declaration and ascii | https://www.youtube.com/watch?v=RCNOV8m0hJQ Exercices: -- printalphabet | https://public.01-edu.org/subjects/printalphabet.en -- printreversealphabet | https://public.01-edu.org/subjects/printreversealphabet.en -- prindigits | https://public.01-edu.org/subjects/printdigits.en -- isnegative | https://public.01-edu.org/subjects/isnegative.en -- printcomb | https://public.01-edu.org/subjects/printcomb.en -- printcomb2 | https://public.01-edu.org/subjects/printcomb2.en -- printnbr | https://public.01-edu.org/subjects/printnbr.en -- printcombn | https://public.01-edu.org/subjects/printcombn.en +- printalphabet | https://public.01-edu.org/subjects/printalphabet.en +- printreversealphabet | https://public.01-edu.org/subjects/printreversealphabet.en +- prindigits | https://public.01-edu.org/subjects/printdigits.en +- isnegative | https://public.01-edu.org/subjects/isnegative.en +- printcomb | https://public.01-edu.org/subjects/printcomb.en +- printcomb2 | https://public.01-edu.org/subjects/printcomb2.en +- printnbr | https://public.01-edu.org/subjects/printnbr.en +- printcombn | https://public.01-edu.org/subjects/printcombn.en ### Sprint 3 @@ -66,25 +66,25 @@ Notions: String Manupulation, Range Loops, Pointers, Modulo and Division relativ Videos: -- 03-01-StringsManipulation | https://www.youtube.com/watch?v=8LplJN_8iOU -- 03-02-RangeLoop | https://www.youtube.com/watch?v=i89N4cjh1-g -- 03-03-Pointers on variables | https://www.youtube.com/watch?v=owVPa5b1BMc -- 03-04-Modulo and Division | https://www.youtube.com/watch?v=NVan-9-Ioec +- 03-01-StringsManipulation | https://www.youtube.com/watch?v=8LplJN_8iOU +- 03-02-RangeLoop | https://www.youtube.com/watch?v=i89N4cjh1-g +- 03-03-Pointers on variables | https://www.youtube.com/watch?v=owVPa5b1BMc +- 03-04-Modulo and Division | https://www.youtube.com/watch?v=NVan-9-Ioec Exercices: -- pointone | https://public.01-edu.org/subjects/pointone.en -- ultimatepointone | https://public.01-edu.org/subjects/ultimatepointone.en -- divmod | https://public.01-edu.org/subjects/divmod.en -- ultimatedivmod | https://public.01-edu.org/subjects/ultimatedivmod.en -- printstr | https://public.01-edu.org/subjects/printstr.en -- strlen | https://public.01-edu.org/subjects/strlen.en -- swap | https://public.01-edu.org/subjects/swap.en -- strrev | https://public.01-edu.org/subjects/strrev.en -- basicatoi | https://public.01-edu.org/subjects/basicatoi.en -- basicatoi2 | https://public.01-edu.org/subjects/basicatoi2.en -- atoi | https://public.01-edu.org/subjects/atoi.en -- sortintegerable | https://public.01-edu.org/subjects/sortintegertable.en +- pointone | https://public.01-edu.org/subjects/pointone.en +- ultimatepointone | https://public.01-edu.org/subjects/ultimatepointone.en +- divmod | https://public.01-edu.org/subjects/divmod.en +- ultimatedivmod | https://public.01-edu.org/subjects/ultimatedivmod.en +- printstr | https://public.01-edu.org/subjects/printstr.en +- strlen | https://public.01-edu.org/subjects/strlen.en +- swap | https://public.01-edu.org/subjects/swap.en +- strrev | https://public.01-edu.org/subjects/strrev.en +- basicatoi | https://public.01-edu.org/subjects/basicatoi.en +- basicatoi2 | https://public.01-edu.org/subjects/basicatoi2.en +- atoi | https://public.01-edu.org/subjects/atoi.en +- sortintegerable | https://public.01-edu.org/subjects/sortintegertable.en ### Checkpoint 1 (4hours) @@ -106,19 +106,19 @@ Notions: Iterative and recursive programmation Videos: -- 04-01-Iterativity and Recursivity | https://www.youtube.com/watch?v=oCZDdAID5Ik +- 04-01-Iterativity and Recursivity | https://www.youtube.com/watch?v=oCZDdAID5Ik Exercices: -- iterativefactorial | https://public.01-edu.org/subjects/iterativefactorial.en -- recursivefactorial | https://public.01-edu.org/subjects/recursivefactorial.en -- iterativepower | https://public.01-edu.org/subjects/iterativepower.en -- recursivepower | https://public.01-edu.org/subjects/recursivepower.en -- fibonacci | https://public.01-edu.org/subjects/fibonacci.en -- sqrt | https://public.01-edu.org/subjects/sqrt.en -- isprime | https://public.01-edu.org/subjects/isprime.en -- findnextprime | https://public.01-edu.org/subjects/findnextprime.en -- eightqueens | https://public.01-edu.org/subjects/eightqueens.en +- iterativefactorial | https://public.01-edu.org/subjects/iterativefactorial.en +- recursivefactorial | https://public.01-edu.org/subjects/recursivefactorial.en +- iterativepower | https://public.01-edu.org/subjects/iterativepower.en +- recursivepower | https://public.01-edu.org/subjects/recursivepower.en +- fibonacci | https://public.01-edu.org/subjects/fibonacci.en +- sqrt | https://public.01-edu.org/subjects/sqrt.en +- isprime | https://public.01-edu.org/subjects/isprime.en +- findnextprime | https://public.01-edu.org/subjects/findnextprime.en +- eightqueens | https://public.01-edu.org/subjects/eightqueens.en ### Sprint 5 @@ -128,28 +128,28 @@ Notions: String Manipulation and medium-advanced algorithmia Videos: -- 05-01-Runes, Bytes and Strings | https://www.youtube.com/watch?v=-eIU5ISID64 +- 05-01-Runes, Bytes and Strings | https://www.youtube.com/watch?v=-eIU5ISID64 Exercices: -- firstrune | https://public.01-edu.org/subjects/firstrune.en -- nrune | https://public.01-edu.org/subjects/nrune.en -- lastrune | https://public.01-edu.org/subjects/lastrune.en -- index | https://public.01-edu.org/subjects/index.en -- compare | https://public.01-edu.org/subjects/compare.en -- toupper | https://public.01-edu.org/subjects/toupper.en -- tolower | https://public.01-edu.org/subjects/tolower.en -- capitalize | https://public.01-edu.org/subjects/capitalize.en -- isalpha | https://public.01-edu.org/subjects/isalpha.en -- isnumeric | https://public.01-edu.org/subjects/isnumeric.en -- islower | https://public.01-edu.org/subjects/islower.en -- isupper | https://public.01-edu.org/subjects/isupper.en -- isprintable | https://public.01-edu.org/subjects/isprintable.en -- concat | https://public.01-edu.org/subjects/concat.en -- basicjoin | https://public.01-edu.org/subjects/basicjoin.en -- join | https://public.01-edu.org/subjects/join.en -- printnbrbase | https://public.01-edu.org/subjects/printnbrbase.en -- atoibase | https://public.01-edu.org/subjects/atoibase.en +- firstrune | https://public.01-edu.org/subjects/firstrune.en +- nrune | https://public.01-edu.org/subjects/nrune.en +- lastrune | https://public.01-edu.org/subjects/lastrune.en +- index | https://public.01-edu.org/subjects/index.en +- compare | https://public.01-edu.org/subjects/compare.en +- toupper | https://public.01-edu.org/subjects/toupper.en +- tolower | https://public.01-edu.org/subjects/tolower.en +- capitalize | https://public.01-edu.org/subjects/capitalize.en +- isalpha | https://public.01-edu.org/subjects/isalpha.en +- isnumeric | https://public.01-edu.org/subjects/isnumeric.en +- islower | https://public.01-edu.org/subjects/islower.en +- isupper | https://public.01-edu.org/subjects/isupper.en +- isprintable | https://public.01-edu.org/subjects/isprintable.en +- concat | https://public.01-edu.org/subjects/concat.en +- basicjoin | https://public.01-edu.org/subjects/basicjoin.en +- join | https://public.01-edu.org/subjects/join.en +- printnbrbase | https://public.01-edu.org/subjects/printnbrbase.en +- atoibase | https://public.01-edu.org/subjects/atoibase.en ### Sprint 6 @@ -159,14 +159,14 @@ Notions: Arguments manipulation in programs Videos: -- 06-01-Os.Args | https://www.youtube.com/watch?v=I1xt_TLRhF0 +- 06-01-Os.Args | https://www.youtube.com/watch?v=I1xt_TLRhF0 Exercices: -- printprogramname | https://public.01-edu.org/subjects/printprogramname.en -- printparams | https://public.01-edu.org/subjects/printparams.en -- revparams | https://public.01-edu.org/subjects/revparams.en -- sortparams | https://public.01-edu.org/subjects/sortparams.en +- printprogramname | https://public.01-edu.org/subjects/printprogramname.en +- printparams | https://public.01-edu.org/subjects/printparams.en +- revparams | https://public.01-edu.org/subjects/revparams.en +- sortparams | https://public.01-edu.org/subjects/sortparams.en ### Sprint 7 @@ -176,17 +176,17 @@ Notions: Usage of Make and Append Videos: -- 07-01-Make and Append methods | https://www.youtube.com/watch?v=2HHVUM0YQuI +- 07-01-Make and Append methods | https://www.youtube.com/watch?v=2HHVUM0YQuI Exercices: -- appendrange | https://public.01-edu.org/subjects/apprendrange.en -- makerange | https://public.01-edu.org/subjects/makerange.en -- concatparams | https://public.01-edu.org/subjects/concatparams.en -- splitwhitespaces | https://public.01-edu.org/subjects/splitwhitespaces.en -- printwordstables | https://public.01-edu.org/subjects/printwordstables.en -- convertbase | https://public.01-edu.org/subjects/converbase.en -- split | https://public.01-edu.org/subjects/split.en +- appendrange | https://public.01-edu.org/subjects/apprendrange.en +- makerange | https://public.01-edu.org/subjects/makerange.en +- concatparams | https://public.01-edu.org/subjects/concatparams.en +- splitwhitespaces | https://public.01-edu.org/subjects/splitwhitespaces.en +- printwordstables | https://public.01-edu.org/subjects/printwordstables.en +- convertbase | https://public.01-edu.org/subjects/converbase.en +- split | https://public.01-edu.org/subjects/split.en ### Checkpoint 2 (4hours) @@ -208,16 +208,16 @@ Notions: Creation of struct types and file manipulation (Open, Read, Close metho Videos: -- 08-01-Structures in Go | https://www.youtube.com/watch?v=-24M7r7VuLY -- 08-02-File Manipulation in go | https://www.youtube.com/watch?v=8vUgchQGhcQ +- 08-01-Structures in Go | https://www.youtube.com/watch?v=-24M7r7VuLY +- 08-02-File Manipulation in go | https://www.youtube.com/watch?v=8vUgchQGhcQ Exercices: -- bool | https://public.01-edu.org/subjects/bool.en -- point | https://public.01-edu.org/subjects/point.en -- displayfile | https://public.01-edu.org/subjects/displayfile.en -- cat | https://public.01-edu.org/subjects/cat.en -- ztail | https://public.01-edu.org/subjects/ztail.en +- bool | https://public.01-edu.org/subjects/bool.en +- point | https://public.01-edu.org/subjects/point.en +- displayfile | https://public.01-edu.org/subjects/displayfile.en +- cat | https://public.01-edu.org/subjects/cat.en +- ztail | https://public.01-edu.org/subjects/ztail.en ### Sprint 9 @@ -227,18 +227,18 @@ Notions: Advance function prototyping Videos: -- 09-01-Functions as Arguments | https://www.youtube.com/watch?v=lw8jUwsluAE +- 09-01-Functions as Arguments | https://www.youtube.com/watch?v=lw8jUwsluAE Exercices: -- foreach | https://public.01-edu.org/subjects/foreach.en -- map | https://public.01-edu.org/subjects/map.en -- any | https://public.01-edu.org/subjects/any.en -- countif | https://public.01-edu.org/subjects/countif.en -- issorted | https://public.01-edu.org/subjects/issorted.en -- doop | https://public.01-edu.org/subjects/doop.en -- sortwordarr | https://public.01-edu.org/subjects/sortwordarr.en -- advancedsortwordarr | https://public.01-edu.org/subjects/advancedsortwordarr.en +- foreach | https://public.01-edu.org/subjects/foreach.en +- map | https://public.01-edu.org/subjects/map.en +- any | https://public.01-edu.org/subjects/any.en +- countif | https://public.01-edu.org/subjects/countif.en +- issorted | https://public.01-edu.org/subjects/issorted.en +- doop | https://public.01-edu.org/subjects/doop.en +- sortwordarr | https://public.01-edu.org/subjects/sortwordarr.en +- advancedsortwordarr | https://public.01-edu.org/subjects/advancedsortwordarr.en ### Sprint 10 @@ -248,18 +248,18 @@ Notions: All previously viewed concepts in team work Exercices: -- rot14 | https://public.01-edu.org/subjects/rot14.en -- abort | https://public.01-edu.org/subjects/abort.en -- collatzcountdown | https://public.01-edu.org/subjects/collatzcountdown.en -- comcheck | https://public.01-edu.org/subjects/comcheck.en -- enigma | https://public.01-edu.org/subjects/enigma.en -- pilot | https://public.01-edu.org/subjects/pilot.en -- fixthemain | https://public.01-edu.org/subjects/fixthemain.en -- compact | https://public.01-edu.org/subjects/compact.en -- activebits | https://public.01-edu.org/subjects/activebits.en -- max | https://public.01-edu.org/subjects/max.en -- join | https://public.01-edu.org/subjects/join.en -- unmatch | https://public.01-edu.org/subjects/unmatch.en +- rot14 | https://public.01-edu.org/subjects/rot14.en +- abort | https://public.01-edu.org/subjects/abort.en +- collatzcountdown | https://public.01-edu.org/subjects/collatzcountdown.en +- comcheck | https://public.01-edu.org/subjects/comcheck.en +- enigma | https://public.01-edu.org/subjects/enigma.en +- pilot | https://public.01-edu.org/subjects/pilot.en +- fixthemain | https://public.01-edu.org/subjects/fixthemain.en +- compact | https://public.01-edu.org/subjects/compact.en +- activebits | https://public.01-edu.org/subjects/activebits.en +- max | https://public.01-edu.org/subjects/max.en +- join | https://public.01-edu.org/subjects/join.en +- unmatch | https://public.01-edu.org/subjects/unmatch.en ### Checkpoint 3 (4hours) @@ -281,25 +281,25 @@ Notions: Pointers manipulation and data structure Videos: -- 11-01-Linked Lists Introduction | https://www.youtube.com/watch?v=EPICVEbylU0 +- 11-01-Linked Lists Introduction | https://www.youtube.com/watch?v=EPICVEbylU0 Exercices: -- listpushback | https://public.01-edu.org/subjects/listpushback.en -- listpushfront | https://public.01-edu.org/subjects/listpushfront.en -- listsize | https://public.01-edu.org/subjects/listsize.en -- listlast | https://public.01-edu.org/subjects/listlast.en -- listclear | https://public.01-edu.org/subjects/listclear.en -- listat | https://public.01-edu.org/subjects/listat.en -- listreverse | https://public.01-edu.org/subjects/listreverse.en -- listforeach | https://public.01-edu.org/subjects/listforeach.en -- listforeachif | https://public.01-edu.org/subjects/listforeachif.en -- listfind | https://public.01-edu.org/subjects/listfind.en -- listremoveif | https://public.01-edu.org/subjects/listremoveif.en -- listmerge | https://public.01-edu.org/subjects/listmerge.en -- listsort | https://public.01-edu.org/subjects/listsort.en -- sortlistinsert | https://public.01-edu.org/subjects/sortlistinsert.en -- sortedlistmerge | https://public.01-edu.org/subjects/sortedlistmerge.en +- listpushback | https://public.01-edu.org/subjects/listpushback.en +- listpushfront | https://public.01-edu.org/subjects/listpushfront.en +- listsize | https://public.01-edu.org/subjects/listsize.en +- listlast | https://public.01-edu.org/subjects/listlast.en +- listclear | https://public.01-edu.org/subjects/listclear.en +- listat | https://public.01-edu.org/subjects/listat.en +- listreverse | https://public.01-edu.org/subjects/listreverse.en +- listforeach | https://public.01-edu.org/subjects/listforeach.en +- listforeachif | https://public.01-edu.org/subjects/listforeachif.en +- listfind | https://public.01-edu.org/subjects/listfind.en +- listremoveif | https://public.01-edu.org/subjects/listremoveif.en +- listmerge | https://public.01-edu.org/subjects/listmerge.en +- listsort | https://public.01-edu.org/subjects/listsort.en +- sortlistinsert | https://public.01-edu.org/subjects/sortlistinsert.en +- sortedlistmerge | https://public.01-edu.org/subjects/sortedlistmerge.en ### Sprint 12 @@ -309,21 +309,21 @@ Notions: Advanced Data Structure using binary trees Videos: -- 12-01-Introduction to Binary Trees | https://www.youtube.com/watch?v=3g2WCqWNIVs +- 12-01-Introduction to Binary Trees | https://www.youtube.com/watch?v=3g2WCqWNIVs Exercices: -- btreeinsertdata | https://public.01-edu.org/subjects/btreeinsertdata.en -- btreeapplyinorder | https://public.01-edu.org/subjects/btreeapplyinorder.en -- btreeapplypreorder | https://public.01-edu.org/subjects/btreeapplypreorder.en -- btreesearchitem | https://public.01-edu.org/subjects/btreesearchitem.en -- btreelevelcount | https://public.01-edu.org/subjects/btreelevelcount.en -- btreeisbinary | https://public.01-edu.org/subjects/btreeisbinary.en -- btreeapplylevel | https://public.01-edu.org/subjects/btreeapplylevel.en -- btreemax | https://public.01-edu.org/subjects/btreemax.en -- btreemin | https://public.01-edu.org/subjects/btreemin.en -- btreetransplant | https://public.01-edu.org/subjects/btreetransplant.en -- btreedeletenode | https://public.01-edu.org/subjects/btreedeletenode.en +- btreeinsertdata | https://public.01-edu.org/subjects/btreeinsertdata.en +- btreeapplyinorder | https://public.01-edu.org/subjects/btreeapplyinorder.en +- btreeapplypreorder | https://public.01-edu.org/subjects/btreeapplypreorder.en +- btreesearchitem | https://public.01-edu.org/subjects/btreesearchitem.en +- btreelevelcount | https://public.01-edu.org/subjects/btreelevelcount.en +- btreeisbinary | https://public.01-edu.org/subjects/btreeisbinary.en +- btreeapplylevel | https://public.01-edu.org/subjects/btreeapplylevel.en +- btreemax | https://public.01-edu.org/subjects/btreemax.en +- btreemin | https://public.01-edu.org/subjects/btreemin.en +- btreetransplant | https://public.01-edu.org/subjects/btreetransplant.en +- btreedeletenode | https://public.01-edu.org/subjects/btreedeletenode.en ### Checkpoint 4 - Final Checkpoint (8hours) diff --git a/docs/object-child-creation.md b/docs/object-child-creation.md index fd02a216..9cf4843b 100644 --- a/docs/object-child-creation.md +++ b/docs/object-child-creation.md @@ -4,8 +4,8 @@ Objects of the Admin can be configured : -- By setting particular **attributes** to the object -- By associating **children** to the object +- By setting particular **attributes** to the object +- By associating **children** to the object Children can be added, deleted, reordered in the list. Also, it's possible to configure it in a special way for the parent object, by setting children attributes for all the children. @@ -28,13 +28,13 @@ This documentation explains how to associate a child to a parent object. #### 3. Set up the new child: -- Enter its name in the input "Add a child name" -- Select your step object in the select input -- Click on "ADD" +- Enter its name in the input "Add a child name" +- Select your step object in the select input +- Click on "ADD" Your step is then related to its parent. You can see it in the _Children_ section of the parent's object. There, you can now: -- Delete the child from its parent (the actual object of your child will not be deleted). -- Reorder it in the children's list, by dragging it to the place you want. -- Update its original settings by clicking on the eye icon of its reference (redirection to object edit page of the child). - Capture d’écran 2019-04-22 à 19 51 12 +- Delete the child from its parent (the actual object of your child will not be deleted). +- Reorder it in the children's list, by dragging it to the place you want. +- Update its original settings by clicking on the eye icon of its reference (redirection to object edit page of the child). + Capture d’écran 2019-04-22 à 19 51 12 diff --git a/docs/object-edit.md b/docs/object-edit.md index 5434d1c5..132c00a3 100644 --- a/docs/object-edit.md +++ b/docs/object-edit.md @@ -8,27 +8,27 @@ ### Pin 1 -- Link back to the "Objects" page ; -- Editable name field, hit 'enter' or 'cmd + s' or click on the floppy-disk icon to save ; -- Major dependencies visualisation, (where my object is used as a child), click the label to navigate to the dependence ; -- External URL, this is an optional parameter, it's use to point at an other source of content or information needed by the object. We generaly use to point at a Git repository ; +- Link back to the "Objects" page ; +- Editable name field, hit 'enter' or 'cmd + s' or click on the floppy-disk icon to save ; +- Major dependencies visualisation, (where my object is used as a child), click the label to navigate to the dependence ; +- External URL, this is an optional parameter, it's use to point at an other source of content or information needed by the object. We generaly use to point at a Git repository ; ### Pin 2 -- Delete Button, Warning there, it will destroy your object! ; -- Type of your Object (`organisation`, `campus`, `onboarding`, `cursus`, `quest`, `exercise`), save on select ; -- Status of your Object (`draft`, `online`, `offline`), save on select ; -- The first and last name of the original author ; +- Delete Button, Warning there, it will destroy your object! ; +- Type of your Object (`organisation`, `campus`, `onboarding`, `cursus`, `quest`, `exercise`), save on select ; +- Status of your Object (`draft`, `online`, `offline`), save on select ; +- The first and last name of the original author ; ### Pin 3 -- Object Attribute edition area, manage all the attributes relative to this Object. These attributes will be exposed to its relationship ; +- Object Attribute edition area, manage all the attributes relative to this Object. These attributes will be exposed to its relationship ; ### Pin 4 -- Object Children edition area ; -- Children Attributes edition area, these attributes impact and overload all the following children. Works the same way as standard attributes ; -- Add a child, allows to add a child to the children list, more information here -> [Object Child creation](object-child-creation.md) ; -- Children List, allows you to reorganise, delete and edit child. Each child can be overload with its own attributes, the edition works the same way as the original attributes ; +- Object Children edition area ; +- Children Attributes edition area, these attributes impact and overload all the following children. Works the same way as standard attributes ; +- Add a child, allows to add a child to the children list, more information here -> [Object Child creation](object-child-creation.md) ; +- Children List, allows you to reorganise, delete and edit child. Each child can be overload with its own attributes, the edition works the same way as the original attributes ; More informations about attribute overload system [here](object-attribute-system.md) diff --git a/docs/objects.md b/docs/objects.md index 81414db7..98c90405 100644 --- a/docs/objects.md +++ b/docs/objects.md @@ -11,12 +11,12 @@ It structure can be visualized in two parts. The first one is the definition of This is the minimal structure of an object: -- name -- type (`organisation`, `campus`, `onboarding`, `cursus`, `quest`, `exercise`) -- status (`draft`, `online`, `offline`) -- attrs {} -- childrenAttrs {} -- children {} +- name +- type (`organisation`, `campus`, `onboarding`, `cursus`, `quest`, `exercise`) +- status (`draft`, `online`, `offline`) +- attrs {} +- childrenAttrs {} +- children {} ## Browse Objects: diff --git a/docs/os-deployment.md b/docs/os-deployment.md index a572ab6d..5113199f 100644 --- a/docs/os-deployment.md +++ b/docs/os-deployment.md @@ -2,29 +2,29 @@ ## Image creation steps -- [Installation of Ubuntu](ubuntu-installation.md) - - minimal OS installation (downloads ~200 MB) - - Software installation (downloads ~900 MB) - - Optimization - - improve speed - - reduce image size - - reduce power (CPU) & memory usage - - reduce surface of attack - - reduce bandwidth usage - - Customization - - machine-dependent (drivers, bug workarounds...) - - time zone of the school - - school scripts - - Cleaning - - logs - - temporary files - - histories - - caches - - auto-generated IDs -- Preparation of the disk image - - zero unallocated space of filesystem (~7 GB of data remains) - - (optional) create compressed image with [lz4](https://lz4.github.io/lz4) (the resulting image is ~3.2 GB) +- [Installation of Ubuntu](ubuntu-installation.md) + - minimal OS installation (downloads ~200 MB) + - Software installation (downloads ~900 MB) + - Optimization + - improve speed + - reduce image size + - reduce power (CPU) & memory usage + - reduce surface of attack + - reduce bandwidth usage + - Customization + - machine-dependent (drivers, bug workarounds...) + - time zone of the school + - school scripts + - Cleaning + - logs + - temporary files + - histories + - caches + - auto-generated IDs +- Preparation of the disk image + - zero unallocated space of filesystem (~7 GB of data remains) + - (optional) create compressed image with [lz4](https://lz4.github.io/lz4) (the resulting image is ~3.2 GB) ## Network installation -- Boot through PXE [UDPcast](http://udpcast.linux.lu) which allows an efficient transfer of the disk image (using multicast or broadcast) +- Boot through PXE [UDPcast](http://udpcast.linux.lu) which allows an efficient transfer of the disk image (using multicast or broadcast) diff --git a/docs/pc-requirements.md b/docs/pc-requirements.md index cd6bc4a1..ba36bf19 100644 --- a/docs/pc-requirements.md +++ b/docs/pc-requirements.md @@ -12,7 +12,7 @@ ## Other considerations -- The monitor must be flicker-free (no PWM) to preserve the student's attention & eye health. -- To avoid damaging the PC ports, all cables (USB, Audio) must be connected to cheaper and easier to replace extension cables. -- Energy consumption is an important criterion to be taken into account. -- It is better to buy the computers without a Windows licence, as it is an unnecessary extra cost. +- The monitor must be flicker-free (no PWM) to preserve the student's attention & eye health. +- To avoid damaging the PC ports, all cables (USB, Audio) must be connected to cheaper and easier to replace extension cables. +- Energy consumption is an important criterion to be taken into account. +- It is better to buy the computers without a Windows licence, as it is an unnecessary extra cost. diff --git a/docs/piscine-go-curriculum.md b/docs/piscine-go-curriculum.md index 23c91246..be5fa989 100644 --- a/docs/piscine-go-curriculum.md +++ b/docs/piscine-go-curriculum.md @@ -12,27 +12,27 @@ Notions: basic usage and interaction with a command line terminal. Videos: -- 1-2 `curl` with the GitHub api and Example of shell file | https://www.youtube.com/watch?v=A0Mqc215igw -- 1-3 `touch`, `chmod` and `echo` | https://www.youtube.com/watch?v=21h-vsuXgDU -- 1-4 `find` and `grep` | https://www.youtube.com/watch?v=7a1JSWHhJlM -- 1-5 `cut`, `sed` and `tr` | https://www.youtube.com/watch?v=Nil7rVP3eMI -- 1-6 `jq` and `wc` | https://www.youtube.com/watch?v=cQmcaOseuiA& +- 1-2 `curl` with the GitHub api and Example of shell file | https://www.youtube.com/watch?v=A0Mqc215igw +- 1-3 `touch`, `chmod` and `echo` | https://www.youtube.com/watch?v=21h-vsuXgDU +- 1-4 `find` and `grep` | https://www.youtube.com/watch?v=7a1JSWHhJlM +- 1-5 `cut`, `sed` and `tr` | https://www.youtube.com/watch?v=Nil7rVP3eMI +- 1-6 `jq` and `wc` | https://www.youtube.com/watch?v=cQmcaOseuiA& Exercices: -- introduction | https://public.01-edu.org/subjects/introduction.en -- make-it-better | https://public.01-edu.org/subjects/make-it-better.en -- to-git-or-not-to-git | https://public.01-edu.org/subjects/to-git-or-not-to-git.en -- who-are-you | https://public.01-edu.org/subjects/who-are-you.en -- cl-camp1 | https://public.01-edu.org/subjects/cl-camp1.en -- cl-camp2 | https://public.01-edu.org/subjects/cl-camp2.en -- cl-camp3 | https://public.01-edu.org/subjects/cl-camp3.en -- cl-camp4 | https://public.01-edu.org/subjects/cl-camp4.en -- cl-camp5 | https://public.01-edu.org/subjects/cl-camp5.en -- cl-camp6 | https://public.01-edu.org/subjects/cl-camp6.en -- cl-camp7 | https://public.01-edu.org/subjects/cl-camp7.en -- cl-camp8 | https://public.01-edu.org/subjects/cl-camp8.en -- now-get-to-work | https://public.01-edu.org/subjects/now-get-to-work.en +- introduction | https://public.01-edu.org/subjects/introduction.en +- make-it-better | https://public.01-edu.org/subjects/make-it-better.en +- to-git-or-not-to-git | https://public.01-edu.org/subjects/to-git-or-not-to-git.en +- who-are-you | https://public.01-edu.org/subjects/who-are-you.en +- cl-camp1 | https://public.01-edu.org/subjects/cl-camp1.en +- cl-camp2 | https://public.01-edu.org/subjects/cl-camp2.en +- cl-camp3 | https://public.01-edu.org/subjects/cl-camp3.en +- cl-camp4 | https://public.01-edu.org/subjects/cl-camp4.en +- cl-camp5 | https://public.01-edu.org/subjects/cl-camp5.en +- cl-camp6 | https://public.01-edu.org/subjects/cl-camp6.en +- cl-camp7 | https://public.01-edu.org/subjects/cl-camp7.en +- cl-camp8 | https://public.01-edu.org/subjects/cl-camp8.en +- now-get-to-work | https://public.01-edu.org/subjects/now-get-to-work.en ### Quest 2 @@ -42,21 +42,21 @@ Notions: Variables declaration, Loops, if and else statement, usage of z01.Print Videos: -- 02-01-If and Else Statements in Go | https://www.youtube.com/watch?v=rnF1_SfeGE4 -- 02-02-ForLoops | https://www.youtube.com/watch?v=Bt47lx6q2-4 -- 02-03-PrintRune function | https://www.youtube.com/watch?v=o8JrvI3jqoM -- 02-04-Variables Declaration and ascii | https://www.youtube.com/watch?v=RCNOV8m0hJQ +- 02-01-If and Else Statements in Go | https://www.youtube.com/watch?v=rnF1_SfeGE4 +- 02-02-ForLoops | https://www.youtube.com/watch?v=Bt47lx6q2-4 +- 02-03-PrintRune function | https://www.youtube.com/watch?v=o8JrvI3jqoM +- 02-04-Variables Declaration and ascii | https://www.youtube.com/watch?v=RCNOV8m0hJQ Exercices: -- printalphabet | https://public.01-edu.org/subjects/printalphabet.en -- printreversealphabet | https://public.01-edu.org/subjects/printreversealphabet.en -- prindigits | https://public.01-edu.org/subjects/printdigits.en -- isnegative | https://public.01-edu.org/subjects/isnegative.en -- printcomb | https://public.01-edu.org/subjects/printcomb.en -- printcomb2 | https://public.01-edu.org/subjects/printcomb2.en -- printnbr | https://public.01-edu.org/subjects/printnbr.en -- printcombn | https://public.01-edu.org/subjects/printcombn.en +- printalphabet | https://public.01-edu.org/subjects/printalphabet.en +- printreversealphabet | https://public.01-edu.org/subjects/printreversealphabet.en +- prindigits | https://public.01-edu.org/subjects/printdigits.en +- isnegative | https://public.01-edu.org/subjects/isnegative.en +- printcomb | https://public.01-edu.org/subjects/printcomb.en +- printcomb2 | https://public.01-edu.org/subjects/printcomb2.en +- printnbr | https://public.01-edu.org/subjects/printnbr.en +- printcombn | https://public.01-edu.org/subjects/printcombn.en ### Quest 3 @@ -66,25 +66,25 @@ Notions: String Manupulation, Range Loops, Pointers, Modulo and Division relativ Videos: -- 03-01-StringsManipulation | https://www.youtube.com/watch?v=8LplJN_8iOU -- 03-02-RangeLoop | https://www.youtube.com/watch?v=i89N4cjh1-g -- 03-03-Pointers on variables | https://www.youtube.com/watch?v=owVPa5b1BMc -- 03-04-Modulo and Division | https://www.youtube.com/watch?v=NVan-9-Ioec +- 03-01-StringsManipulation | https://www.youtube.com/watch?v=8LplJN_8iOU +- 03-02-RangeLoop | https://www.youtube.com/watch?v=i89N4cjh1-g +- 03-03-Pointers on variables | https://www.youtube.com/watch?v=owVPa5b1BMc +- 03-04-Modulo and Division | https://www.youtube.com/watch?v=NVan-9-Ioec Exercices: -- pointone | https://public.01-edu.org/subjects/pointone.en -- ultimatepointone | https://public.01-edu.org/subjects/ultimatepointone.en -- divmod | https://public.01-edu.org/subjects/divmod.en -- ultimatedivmod | https://public.01-edu.org/subjects/ultimatedivmod.en -- printstr | https://public.01-edu.org/subjects/printstr.en -- strlen | https://public.01-edu.org/subjects/strlen.en -- swap | https://public.01-edu.org/subjects/swap.en -- strrev | https://public.01-edu.org/subjects/strrev.en -- basicatoi | https://public.01-edu.org/subjects/basicatoi.en -- basicatoi2 | https://public.01-edu.org/subjects/basicatoi2.en -- atoi | https://public.01-edu.org/subjects/atoi.en -- sortintegerable | https://public.01-edu.org/subjects/sortintegertable.en +- pointone | https://public.01-edu.org/subjects/pointone.en +- ultimatepointone | https://public.01-edu.org/subjects/ultimatepointone.en +- divmod | https://public.01-edu.org/subjects/divmod.en +- ultimatedivmod | https://public.01-edu.org/subjects/ultimatedivmod.en +- printstr | https://public.01-edu.org/subjects/printstr.en +- strlen | https://public.01-edu.org/subjects/strlen.en +- swap | https://public.01-edu.org/subjects/swap.en +- strrev | https://public.01-edu.org/subjects/strrev.en +- basicatoi | https://public.01-edu.org/subjects/basicatoi.en +- basicatoi2 | https://public.01-edu.org/subjects/basicatoi2.en +- atoi | https://public.01-edu.org/subjects/atoi.en +- sortintegerable | https://public.01-edu.org/subjects/sortintegertable.en ### Exam 1 (4hours) @@ -106,19 +106,19 @@ Notions: Iterative and recursive programmation Videos: -- 04-01-Iterativity and Recursivity | https://www.youtube.com/watch?v=oCZDdAID5Ik +- 04-01-Iterativity and Recursivity | https://www.youtube.com/watch?v=oCZDdAID5Ik Exercices: -- iterativefactorial | https://public.01-edu.org/subjects/iterativefactorial.en -- recursivefactorial | https://public.01-edu.org/subjects/recursivefactorial.en -- iterativepower | https://public.01-edu.org/subjects/iterativepower.en -- recursivepower | https://public.01-edu.org/subjects/recursivepower.en -- fibonacci | https://public.01-edu.org/subjects/fibonacci.en -- sqrt | https://public.01-edu.org/subjects/sqrt.en -- isprime | https://public.01-edu.org/subjects/isprime.en -- findnextprime | https://public.01-edu.org/subjects/findnextprime.en -- eightqueens | https://public.01-edu.org/subjects/eightqueens.en +- iterativefactorial | https://public.01-edu.org/subjects/iterativefactorial.en +- recursivefactorial | https://public.01-edu.org/subjects/recursivefactorial.en +- iterativepower | https://public.01-edu.org/subjects/iterativepower.en +- recursivepower | https://public.01-edu.org/subjects/recursivepower.en +- fibonacci | https://public.01-edu.org/subjects/fibonacci.en +- sqrt | https://public.01-edu.org/subjects/sqrt.en +- isprime | https://public.01-edu.org/subjects/isprime.en +- findnextprime | https://public.01-edu.org/subjects/findnextprime.en +- eightqueens | https://public.01-edu.org/subjects/eightqueens.en ### Quest 5 @@ -128,28 +128,28 @@ Notions: String Manipulation and medium-advanced algorithmia Videos: -- 05-01-Runes, Bytes and Strings | https://www.youtube.com/watch?v=-eIU5ISID64 +- 05-01-Runes, Bytes and Strings | https://www.youtube.com/watch?v=-eIU5ISID64 Exercices: -- firstrune | https://public.01-edu.org/subjects/firstrune.en -- nrune | https://public.01-edu.org/subjects/nrune.en -- lastrune | https://public.01-edu.org/subjects/lastrune.en -- index | https://public.01-edu.org/subjects/index.en -- compare | https://public.01-edu.org/subjects/compare.en -- toupper | https://public.01-edu.org/subjects/toupper.en -- tolower | https://public.01-edu.org/subjects/tolower.en -- capitalize | https://public.01-edu.org/subjects/capitalize.en -- isalpha | https://public.01-edu.org/subjects/isalpha.en -- isnumeric | https://public.01-edu.org/subjects/isnumeric.en -- islower | https://public.01-edu.org/subjects/islower.en -- isupper | https://public.01-edu.org/subjects/isupper.en -- isprintable | https://public.01-edu.org/subjects/isprintable.en -- concat | https://public.01-edu.org/subjects/concat.en -- basicjoin | https://public.01-edu.org/subjects/basicjoin.en -- join | https://public.01-edu.org/subjects/join.en -- printnbrbase | https://public.01-edu.org/subjects/printnbrbase.en -- atoibase | https://public.01-edu.org/subjects/atoibase.en +- firstrune | https://public.01-edu.org/subjects/firstrune.en +- nrune | https://public.01-edu.org/subjects/nrune.en +- lastrune | https://public.01-edu.org/subjects/lastrune.en +- index | https://public.01-edu.org/subjects/index.en +- compare | https://public.01-edu.org/subjects/compare.en +- toupper | https://public.01-edu.org/subjects/toupper.en +- tolower | https://public.01-edu.org/subjects/tolower.en +- capitalize | https://public.01-edu.org/subjects/capitalize.en +- isalpha | https://public.01-edu.org/subjects/isalpha.en +- isnumeric | https://public.01-edu.org/subjects/isnumeric.en +- islower | https://public.01-edu.org/subjects/islower.en +- isupper | https://public.01-edu.org/subjects/isupper.en +- isprintable | https://public.01-edu.org/subjects/isprintable.en +- concat | https://public.01-edu.org/subjects/concat.en +- basicjoin | https://public.01-edu.org/subjects/basicjoin.en +- join | https://public.01-edu.org/subjects/join.en +- printnbrbase | https://public.01-edu.org/subjects/printnbrbase.en +- atoibase | https://public.01-edu.org/subjects/atoibase.en ### Quest 6 @@ -159,14 +159,14 @@ Notions: Arguments manipulation in programs Videos: -- 06-01-Os.Args | https://www.youtube.com/watch?v=I1xt_TLRhF0 +- 06-01-Os.Args | https://www.youtube.com/watch?v=I1xt_TLRhF0 Exercices: -- printprogramname | https://public.01-edu.org/subjects/printprogramname.en -- printparams | https://public.01-edu.org/subjects/printparams.en -- revparams | https://public.01-edu.org/subjects/revparams.en -- sortparams | https://public.01-edu.org/subjects/sortparams.en +- printprogramname | https://public.01-edu.org/subjects/printprogramname.en +- printparams | https://public.01-edu.org/subjects/printparams.en +- revparams | https://public.01-edu.org/subjects/revparams.en +- sortparams | https://public.01-edu.org/subjects/sortparams.en ### Quest 7 @@ -176,17 +176,17 @@ Notions: Usage of Make and Append Videos: -- 07-01-Make and Append methods | https://www.youtube.com/watch?v=2HHVUM0YQuI +- 07-01-Make and Append methods | https://www.youtube.com/watch?v=2HHVUM0YQuI Exercices: -- appendrange | https://public.01-edu.org/subjects/apprendrange.en -- makerange | https://public.01-edu.org/subjects/makerange.en -- concatparams | https://public.01-edu.org/subjects/concatparams.en -- splitwhitespaces | https://public.01-edu.org/subjects/splitwhitespaces.en -- printwordstables | https://public.01-edu.org/subjects/printwordstables.en -- convertbase | https://public.01-edu.org/subjects/converbase.en -- split | https://public.01-edu.org/subjects/split.en +- appendrange | https://public.01-edu.org/subjects/apprendrange.en +- makerange | https://public.01-edu.org/subjects/makerange.en +- concatparams | https://public.01-edu.org/subjects/concatparams.en +- splitwhitespaces | https://public.01-edu.org/subjects/splitwhitespaces.en +- printwordstables | https://public.01-edu.org/subjects/printwordstables.en +- convertbase | https://public.01-edu.org/subjects/converbase.en +- split | https://public.01-edu.org/subjects/split.en ### Exam 2 (4hours) @@ -208,16 +208,16 @@ Notions: Creation of struct types and file manipulation (Open, Read, Close metho Videos: -- 08-01-Structures in Go | https://www.youtube.com/watch?v=-24M7r7VuLY -- 08-02-File Manipulation in go | https://www.youtube.com/watch?v=8vUgchQGhcQ +- 08-01-Structures in Go | https://www.youtube.com/watch?v=-24M7r7VuLY +- 08-02-File Manipulation in go | https://www.youtube.com/watch?v=8vUgchQGhcQ Exercices: -- bool | https://public.01-edu.org/subjects/bool.en -- point | https://public.01-edu.org/subjects/point.en -- displayfile | https://public.01-edu.org/subjects/displayfile.en -- cat | https://public.01-edu.org/subjects/cat.en -- ztail | https://public.01-edu.org/subjects/ztail.en +- bool | https://public.01-edu.org/subjects/bool.en +- point | https://public.01-edu.org/subjects/point.en +- displayfile | https://public.01-edu.org/subjects/displayfile.en +- cat | https://public.01-edu.org/subjects/cat.en +- ztail | https://public.01-edu.org/subjects/ztail.en ### Quest 9 @@ -227,18 +227,18 @@ Notions: Advance function prototyping Videos: -- 09-01-Functions as Arguments | https://www.youtube.com/watch?v=lw8jUwsluAE +- 09-01-Functions as Arguments | https://www.youtube.com/watch?v=lw8jUwsluAE Exercices: -- foreach | https://public.01-edu.org/subjects/foreach.en -- map | https://public.01-edu.org/subjects/map.en -- any | https://public.01-edu.org/subjects/any.en -- countif | https://public.01-edu.org/subjects/countif.en -- issorted | https://public.01-edu.org/subjects/issorted.en -- doop | https://public.01-edu.org/subjects/doop.en -- sortwordarr | https://public.01-edu.org/subjects/sortwordarr.en -- advancedsortwordarr | https://public.01-edu.org/subjects/advancedsortwordarr.en +- foreach | https://public.01-edu.org/subjects/foreach.en +- map | https://public.01-edu.org/subjects/map.en +- any | https://public.01-edu.org/subjects/any.en +- countif | https://public.01-edu.org/subjects/countif.en +- issorted | https://public.01-edu.org/subjects/issorted.en +- doop | https://public.01-edu.org/subjects/doop.en +- sortwordarr | https://public.01-edu.org/subjects/sortwordarr.en +- advancedsortwordarr | https://public.01-edu.org/subjects/advancedsortwordarr.en ### Quest 10 @@ -248,18 +248,18 @@ Notions: All previously viewed concepts in team work Exercices: -- rot14 | https://public.01-edu.org/subjects/rot14.en -- abort | https://public.01-edu.org/subjects/abort.en -- collatzcountdown | https://public.01-edu.org/subjects/collatzcountdown.en -- comcheck | https://public.01-edu.org/subjects/comcheck.en -- enigma | https://public.01-edu.org/subjects/enigma.en -- pilot | https://public.01-edu.org/subjects/pilot.en -- fixthemain | https://public.01-edu.org/subjects/fixthemain.en -- compact | https://public.01-edu.org/subjects/compact.en -- activebits | https://public.01-edu.org/subjects/activebits.en -- max | https://public.01-edu.org/subjects/max.en -- join | https://public.01-edu.org/subjects/join.en -- unmatch | https://public.01-edu.org/subjects/unmatch.en +- rot14 | https://public.01-edu.org/subjects/rot14.en +- abort | https://public.01-edu.org/subjects/abort.en +- collatzcountdown | https://public.01-edu.org/subjects/collatzcountdown.en +- comcheck | https://public.01-edu.org/subjects/comcheck.en +- enigma | https://public.01-edu.org/subjects/enigma.en +- pilot | https://public.01-edu.org/subjects/pilot.en +- fixthemain | https://public.01-edu.org/subjects/fixthemain.en +- compact | https://public.01-edu.org/subjects/compact.en +- activebits | https://public.01-edu.org/subjects/activebits.en +- max | https://public.01-edu.org/subjects/max.en +- join | https://public.01-edu.org/subjects/join.en +- unmatch | https://public.01-edu.org/subjects/unmatch.en ### Exam 3 (4hours) @@ -281,25 +281,25 @@ Notions: Pointers manipulation and data structure Videos: -- 11-01-Linked Lists Introduction | https://www.youtube.com/watch?v=EPICVEbylU0 +- 11-01-Linked Lists Introduction | https://www.youtube.com/watch?v=EPICVEbylU0 Exercices: -- listpushback | https://public.01-edu.org/subjects/listpushback.en -- listpushfront | https://public.01-edu.org/subjects/listpushfront.en -- listsize | https://public.01-edu.org/subjects/listsize.en -- listlast | https://public.01-edu.org/subjects/listlast.en -- listclear | https://public.01-edu.org/subjects/listclear.en -- listat | https://public.01-edu.org/subjects/listat.en -- listreverse | https://public.01-edu.org/subjects/listreverse.en -- listforeach | https://public.01-edu.org/subjects/listforeach.en -- listforeachif | https://public.01-edu.org/subjects/listforeachif.en -- listfind | https://public.01-edu.org/subjects/listfind.en -- listremoveif | https://public.01-edu.org/subjects/listremoveif.en -- listmerge | https://public.01-edu.org/subjects/listmerge.en -- listsort | https://public.01-edu.org/subjects/listsort.en -- sortlistinsert | https://public.01-edu.org/subjects/sortlistinsert.en -- sortedlistmerge | https://public.01-edu.org/subjects/sortedlistmerge.en +- listpushback | https://public.01-edu.org/subjects/listpushback.en +- listpushfront | https://public.01-edu.org/subjects/listpushfront.en +- listsize | https://public.01-edu.org/subjects/listsize.en +- listlast | https://public.01-edu.org/subjects/listlast.en +- listclear | https://public.01-edu.org/subjects/listclear.en +- listat | https://public.01-edu.org/subjects/listat.en +- listreverse | https://public.01-edu.org/subjects/listreverse.en +- listforeach | https://public.01-edu.org/subjects/listforeach.en +- listforeachif | https://public.01-edu.org/subjects/listforeachif.en +- listfind | https://public.01-edu.org/subjects/listfind.en +- listremoveif | https://public.01-edu.org/subjects/listremoveif.en +- listmerge | https://public.01-edu.org/subjects/listmerge.en +- listsort | https://public.01-edu.org/subjects/listsort.en +- sortlistinsert | https://public.01-edu.org/subjects/sortlistinsert.en +- sortedlistmerge | https://public.01-edu.org/subjects/sortedlistmerge.en ### Quest 12 @@ -309,21 +309,21 @@ Notions: Advanced Data Structure using binary trees Videos: -- 12-01-Introduction to Binary Trees | https://www.youtube.com/watch?v=3g2WCqWNIVs +- 12-01-Introduction to Binary Trees | https://www.youtube.com/watch?v=3g2WCqWNIVs Exercices: -- btreeinsertdata | https://public.01-edu.org/subjects/btreeinsertdata.en -- btreeapplyinorder | https://public.01-edu.org/subjects/btreeapplyinorder.en -- btreeapplypreorder | https://public.01-edu.org/subjects/btreeapplypreorder.en -- btreesearchitem | https://public.01-edu.org/subjects/btreesearchitem.en -- btreelevelcount | https://public.01-edu.org/subjects/btreelevelcount.en -- btreeisbinary | https://public.01-edu.org/subjects/btreeisbinary.en -- btreeapplylevel | https://public.01-edu.org/subjects/btreeapplylevel.en -- btreemax | https://public.01-edu.org/subjects/btreemax.en -- btreemin | https://public.01-edu.org/subjects/btreemin.en -- btreetransplant | https://public.01-edu.org/subjects/btreetransplant.en -- btreedeletenode | https://public.01-edu.org/subjects/btreedeletenode.en +- btreeinsertdata | https://public.01-edu.org/subjects/btreeinsertdata.en +- btreeapplyinorder | https://public.01-edu.org/subjects/btreeapplyinorder.en +- btreeapplypreorder | https://public.01-edu.org/subjects/btreeapplypreorder.en +- btreesearchitem | https://public.01-edu.org/subjects/btreesearchitem.en +- btreelevelcount | https://public.01-edu.org/subjects/btreelevelcount.en +- btreeisbinary | https://public.01-edu.org/subjects/btreeisbinary.en +- btreeapplylevel | https://public.01-edu.org/subjects/btreeapplylevel.en +- btreemax | https://public.01-edu.org/subjects/btreemax.en +- btreemin | https://public.01-edu.org/subjects/btreemin.en +- btreetransplant | https://public.01-edu.org/subjects/btreetransplant.en +- btreedeletenode | https://public.01-edu.org/subjects/btreedeletenode.en ### Exam 4 - Final Exam (8hours) diff --git a/docs/principles.md b/docs/principles.md index 901cbb52..eb247158 100644 --- a/docs/principles.md +++ b/docs/principles.md @@ -4,34 +4,34 @@ Rationale : -- Reduce the number of potential bugs and problems -- The remaining bugs will be easier to identify/isolate & fix -- Easier maintenance -- Lower human capital required +- Reduce the number of potential bugs and problems +- The remaining bugs will be easier to identify/isolate & fix +- Easier maintenance +- Lower human capital required ## Limit security & filtering mechanisms Especially during the launch, rationale : -- Reduce complexity (see above) -- Alem is a school, not a bank, so the security requirements are lower -- Some students will be able to bypass security systems in all cases - - And they will spread the word quickly -- The only reliable way to identify students will be security cameras and staff attention - - Students will share accounts and USB drives - - They will open connections to the outside and there is no definitive way to prevent this -- We will "hire" the students who have found vulnerabilities using technical skills and creativity - - We cannot anticipate every breach hundreds of students will find & exploit -- Focus on endpoint security rather than network security (firewall on each node) - - Reduce complexity of the network and make it more flexible +- Reduce complexity (see above) +- Alem is a school, not a bank, so the security requirements are lower +- Some students will be able to bypass security systems in all cases + - And they will spread the word quickly +- The only reliable way to identify students will be security cameras and staff attention + - Students will share accounts and USB drives + - They will open connections to the outside and there is no definitive way to prevent this +- We will "hire" the students who have found vulnerabilities using technical skills and creativity + - We cannot anticipate every breach hundreds of students will find & exploit +- Focus on endpoint security rather than network security (firewall on each node) + - Reduce complexity of the network and make it more flexible ## Promote open, neutral network & technologies Rationale : -- Students will spend more time learning things and exchanging ideas than bypassing censorship -- Students will have more extensive knowledge and skills -- It is better to make them aware of their situation than to try to stop them -- A student's motivation is very much influenced by his or her environment - - An environment with limitations will limit the spectrum of things that stimulate the student's curiosity -- A focus will made on increasing student's empowerement in order to make them feel accountable for their own actions. If the student cheats, he has to understand that he is only hindering his own progress. +- Students will spend more time learning things and exchanging ideas than bypassing censorship +- Students will have more extensive knowledge and skills +- It is better to make them aware of their situation than to try to stop them +- A student's motivation is very much influenced by his or her environment + - An environment with limitations will limit the spectrum of things that stimulate the student's curiosity +- A focus will made on increasing student's empowerement in order to make them feel accountable for their own actions. If the student cheats, he has to understand that he is only hindering his own progress. diff --git a/docs/responsibilities.md b/docs/responsibilities.md index 7f546b88..cecf4936 100644 --- a/docs/responsibilities.md +++ b/docs/responsibilities.md @@ -2,30 +2,30 @@ ## Alem -- Hardware - - Maintenance & replacement of parts - - HP machines - - Inventory (associates MAC address or other ID to the physical location of the machine) - - [BIOS configuration](bios-configuration.md) - - Connected on Ethernet network - - Audio & USB extension cables (to protect the PC ports) - - Computers & cables are physically attached to the table (to prevent stealing or damage) - - Monitor brightness (the default might be too high and it cannot be controlled by software) - - Server (virtualized with at least these dedicated resources) - - CPU : 8 threads - - RAM : 64 GB - - SSD : 512 GB - - NIC : pass-through or bridged ? (see with Vitalii) -- Software - - DHCP - - DNS - - PXE - - Image creation & deployment (with the help of team 01) +- Hardware + - Maintenance & replacement of parts + - HP machines + - Inventory (associates MAC address or other ID to the physical location of the machine) + - [BIOS configuration](bios-configuration.md) + - Connected on Ethernet network + - Audio & USB extension cables (to protect the PC ports) + - Computers & cables are physically attached to the table (to prevent stealing or damage) + - Monitor brightness (the default might be too high and it cannot be controlled by software) + - Server (virtualized with at least these dedicated resources) + - CPU : 8 threads + - RAM : 64 GB + - SSD : 512 GB + - NIC : pass-through or bridged ? (see with Vitalii) +- Software + - DHCP + - DNS + - PXE + - Image creation & deployment (with the help of team 01) ## 01 -- Software maintenance - - Implement the features requested or identified at the Alem School - - Bug fix -- Technical advice -- Pedagogical support +- Software maintenance + - Implement the features requested or identified at the Alem School + - Bug fix +- Technical advice +- Pedagogical support diff --git a/docs/reviews.md b/docs/reviews.md index 08fee7f7..10404630 100644 --- a/docs/reviews.md +++ b/docs/reviews.md @@ -9,9 +9,9 @@ Bonus exercises are available in quests 02 / 03 / 04 / 05 / 07 / 08 / 09. Making a review involves 2 students who are goning to review each other's exercise. Each user has to : -- **check** the code of the other one on Github -- **bet** if it is going to fail or succeed in the Review interface -- **run** his own exercise in the Review interface to give a result to compare with the bet, and state if it was right or wrong +- **check** the code of the other one on Github +- **bet** if it is going to fail or succeed in the Review interface +- **run** his own exercise in the Review interface to give a result to compare with the bet, and state if it was right or wrong ## Usage @@ -29,13 +29,13 @@ Once you and the other student have confirmed the match, you can go and check th When you have checked his code, those 4 steps will have to be completed to achieve the review : -- You have to bet if the exercise of the other student will fail or succeed after running the tester -- The other student has to do the same with your exercise and make his own bet, that you will see on the component `Review of your exercise` - Screenshot 2019-10-17 at 02.20.18 +- You have to bet if the exercise of the other student will fail or succeed after running the tester +- The other student has to do the same with your exercise and make his own bet, that you will see on the component `Review of your exercise` + Screenshot 2019-10-17 at 02.20.18 -- Once the other student's bet is set, the tester button unblocks and you have to run it on your exercise to output the result determining if your exercise has failed or succeeded ; this result is compared to the other student's bet to determine if it was wrong or right -- The other student also has to run the tester on his exercise to determine his result and so if your bet was wrong or right - Screenshot 2019-10-17 at 02.22.30 +- Once the other student's bet is set, the tester button unblocks and you have to run it on your exercise to output the result determining if your exercise has failed or succeeded ; this result is compared to the other student's bet to determine if it was wrong or right +- The other student also has to run the tester on his exercise to determine his result and so if your bet was wrong or right + Screenshot 2019-10-17 at 02.22.30 In fact, a bet is succeeded if it is equal to the tester output : Screenshot 2019-10-17 at 02.24.04 diff --git a/docs/server-installation.md b/docs/server-installation.md index 6686c990..8c75b3e7 100644 --- a/docs/server-installation.md +++ b/docs/server-installation.md @@ -32,8 +32,8 @@ Download and boot the ISO image `amd64` of [Debian](https://www.debian.org/distr Select : -- "Advanced options ..." -- "... Automated install" +- "Advanced options ..." +- "... Automated install" The network is automatically configured with DHCP, you can also configure it manually. @@ -44,4 +44,3 @@ raw.githubusercontent.com/01-edu/public/master/scripts/preseed.cfg ``` and select "Continue", let us know when the server's remote access is ready, we will configure it. - diff --git a/docs/server-requirements.md b/docs/server-requirements.md index 20a2477a..e9da8231 100644 --- a/docs/server-requirements.md +++ b/docs/server-requirements.md @@ -2,8 +2,8 @@ **Linux compatible only** -| Component | Recommended specifications | -| --------- | --------------------------------- | -| Processor | 16 threads x86-64 (64 bits) | -| Memory | 64 GB ECC DDR4 2133 Mhz frequency | -| Disk | 500 GB SSD NVMe | +| Component | Recommended specifications | +| --------- | --------------------------- | +| Processor | 16 threads x86-64 (64 bits) | +| Memory | 16 GB DDR4 | +| Disk | 500 GB SSD NVMe | diff --git a/docs/tasks.md b/docs/tasks.md deleted file mode 100644 index 1d72d794..00000000 --- a/docs/tasks.md +++ /dev/null @@ -1,11 +0,0 @@ -# Tasks - -- [x] Install, connect, check the server and the HP clients (_Alem_, _Vitalii_) -- [x] Check the settings of the virtual machine (_01_, _Vitalii_) -- [x] Install the server (_01_, _Vitalii_) -- [x] Tests & benchmark of the server (_01_) -- [x] Test the [OS deployment](https://github.com/01-edu/public/blob/master/docs/os-deployment.md) (_01_, _Vitalii_) -- [ ] Write process documentation (_01_, _Alem_, _Vitalii_) -- [ ] Ensure the tester only works inside the school (_01_, _Alem_) -- [ ] Ensure the exam app works as expected (_01_, _Alem_) -- [ ] Test the entire piscine (_01_, _Alem_) diff --git a/docs/ubuntu-persistent-installation.md b/docs/ubuntu-persistent-installation.md index 9dd46769..5bc9e59f 100644 --- a/docs/ubuntu-persistent-installation.md +++ b/docs/ubuntu-persistent-installation.md @@ -10,19 +10,19 @@ Screenshots of the installation of Ubuntu in Virtual Box are [here](https://gith Download and boot the [last Ubuntu release](http://releases.ubuntu.com/19.10/ubuntu-19.10-desktop-amd64.iso). -- Create a new virtual machine named "Ubuntu" with at least 4096 MB of RAM -- Use the fixed size storage allocation (to have more performance) -- In the settings of the VM - - System -> Motherboard : check "Enable EFI" - - System -> Processor : Select at least 2 processors - - Display -> Screen : Put "Video Memory" to the maximum - - Enable 3D acceleration - - Storage - - Remove IDE controller - - Add Optical Drive to the SATA controller - - Choose your Ubuntu ISO image - - Close the settings (click OK) -- Run the VM +- Create a new virtual machine named "Ubuntu" with at least 4096 MB of RAM +- Use the fixed size storage allocation (to have more performance) +- In the settings of the VM + - System -> Motherboard : check "Enable EFI" + - System -> Processor : Select at least 2 processors + - Display -> Screen : Put "Video Memory" to the maximum + - Enable 3D acceleration + - Storage + - Remove IDE controller + - Add Optical Drive to the SATA controller + - Choose your Ubuntu ISO image + - Close the settings (click OK) +- Run the VM Follow the screenshots (some settings can be personalized, such as keyboard layout, location, password, login automatically, but **do not change the username**) diff --git a/rc/README.md b/rc/README.md index 065a8170..0203bf58 100644 --- a/rc/README.md +++ b/rc/README.md @@ -37,83 +37,95 @@ The program must be executed passing the go source file to be analyze as the fir - The remaining argument (from 2 to ...): - Can be (without any particular order): - - - Allowed imports and functions from a package - - `.*` for full imports (all functions from that package are allowed) - - ``.`` for partial imports (only the function is allowed) - - ``.`#amout` for certain amounts (only certain amount os a function is allowed) - - Ex: `fmt.*` (all functions from `fmt` are allowed), `github.com/01-edu/z01.PrintRune` (only `z01.PrintRune` is allowed), `append#2` (the only amount of `append`'s allowed is 2) - - Allowed built-in functions - - Use the name of the built-in function - - Ex: `make`, `append`, `len`. - - Allowed casting - - by using the type of casting, ex: for allowing `string` casting, use `string` - - Or use the flag `--cast`, to allow every type of casting - - - Import relative packages - - Use the relative path - - Ex: `../piscine`, `..`, `.` - - - Unallow for loops - - Use the flags `--no-for`. - - Note: remember to use it before the `--no-array` flag. - - ex: - ```console - _$ ./rc main.go fmt.* github.com/01-edu/z01.PrintRune len --no-array <...> --no-for - ``` - the last line produces undesired behaviors. - - Unallow literals - - Use the flag `--no-lit="{PATTERN}"` - - Note: `"{PATTERN}"` must be a valid RegExp. - - ex: - ```console - _$ ./rc main.go fmt.* github.com/01-edu/z01.PrintRune len --no-array --no-lit=[b-yB-Y] - ``` + Can be (without any particular order): + + - Allowed imports and functions from a package + - `.*` for full imports (all functions from that package are allowed) + - ``.`` for partial imports (only the function is allowed) + - ``.`#amout` for certain amounts (only certain amount os a function is allowed) + - Ex: `fmt.*` (all functions from `fmt` are allowed), `github.com/01-edu/z01.PrintRune` (only `z01.PrintRune` is allowed), `append#2` (the only amount of `append`'s allowed is 2) + - Allowed built-in functions + + - Use the name of the built-in function + - Ex: `make`, `append`, `len`. + - Allowed casting + - by using the type of casting, ex: for allowing `string` casting, use `string` + - Or use the flag `--cast`, to allow every type of casting + + - Import relative packages + + - Use the relative path + - Ex: `../piscine`, `..`, `.` + + - Unallow for loops + - Use the flags `--no-for`. + - Note: remember to use it before the `--no-array` flag. + - ex: + ```console + _$ ./rc main.go fmt.* github.com/01-edu/z01.PrintRune len --no-array <...> --no-for + ``` + the last line produces undesired behaviors. + - Unallow literals + - Use the flag `--no-lit="{PATTERN}"` + - Note: `"{PATTERN}"` must be a valid RegExp. + - ex: + ```console + _$ ./rc main.go fmt.* github.com/01-edu/z01.PrintRune len --no-array --no-lit=[b-yB-Y] + ``` + - Optional lasts arguments - - The flag `--no-array` must be given as the last argument or to signal that all the arguments after are unallowed array types + - The flag `--no-array` must be given as the last argument or to signal that all the arguments after are unallowed array types + ### Usage: - To allow the import of the whole `fmt` package, `z01.PrintRune` and the built-in functions len in the file `main.go` - The imports must be writen exactly the way are writen inside the source code, example: + The imports must be writen exactly the way are writen inside the source code, example: ```console _$ ./rc main.go fmt.* github.com/01-edu/z01.PrintRune len ``` + - More examples: - import "fmt" is allowed by executing - ```console - _$ ./rc sourcefile.go fmt.* - ``` - - - import "go/parser" is allowed by executing - ```console - _$ ./rc sourcefile.go go/parser.* - ``` - - - import "github.com/01-edu/z01" is allowed by executing - ```console - ./rc sourcefile.go github.com/01-edu/z01.* - ``` - - - import "../../../all/tests/go/solutions" is allowed by executing - ```console - _$ ./rc sourcefile.go ../../../all/tests/go/solutions - ``` - (no `.*` is needed, all the functions from this relative package are allowed) + + ```console + _$ ./rc sourcefile.go fmt.* + ``` + + - import "go/parser" is allowed by executing + + ```console + _$ ./rc sourcefile.go go/parser.* + ``` + + - import "github.com/01-edu/z01" is allowed by executing + + ```console + ./rc sourcefile.go github.com/01-edu/z01.* + ``` + + - import "../../../all/tests/go/solutions" is allowed by executing + + ```console + _$ ./rc sourcefile.go ../../../all/tests/go/solutions + ``` + + (no `.*` is needed, all the functions from this relative package are allowed) - allow all type of casting - ```console - _$ ./rc sourcefile.go ../../../all/tests/go/solutions/ztail/ztail.go fmt.* github.com/01-edu/z01 os.* strconv.* make len append --cast - ``` - - this will allow all type of casting in the file ztail.go + ```console + _$ ./rc sourcefile.go ../../../all/tests/go/solutions/ztail/ztail.go fmt.* github.com/01-edu/z01 os.* strconv.* make len append --cast + ``` + + - this will allow all type of casting in the file ztail.go - to allow just one type of casting - ```console - _$ ./rc sourcefile.go ../../../all/tests/go/solutions/ztail/ztail.go fmt.* github.com/01-edu/z01 os.* strconv.* make len append rune - ``` - - this will allow `rune`, but not `int8`, ..., `string`, `float32`, ... \ No newline at end of file + ```console + _$ ./rc sourcefile.go ../../../all/tests/go/solutions/ztail/ztail.go fmt.* github.com/01-edu/z01 os.* strconv.* make len append rune + ``` + + - this will allow `rune`, but not `int8`, ..., `string`, `float32`, ... diff --git a/rc/rc.go b/rc/rc.go index ab6cf9aa..9b04b45e 100644 --- a/rc/rc.go +++ b/rc/rc.go @@ -43,7 +43,7 @@ var ( funcOccurrences map[string]int ) -//pkgFunc for all the functions of a given package +// pkgFunc for all the functions of a given package type pkgFunc struct { functions []string path string @@ -93,6 +93,7 @@ func (fv *fileVisitor) getPos(n ast.Node) string { func (p *pkgVisitor) getPos(n ast.Node) string { return p.Fset.Position(n.Pos()).String() } + func (c *callVisitor) getPos(n ast.Node) string { return c.Fset.Position(n.Pos()).String() } @@ -135,7 +136,7 @@ func getPkgFunc(path string, fsetPkg *token.FileSet) { } -//reformat from the data base +// reformat from the data base func splitArgs(args string) []string { result := strings.Split(args, " ") return result @@ -198,12 +199,12 @@ func removeAmount(s string) string { return strRm } -//compares if the function is used a certain amount of times allowed +// compares if the function is used a certain amount of times allowed func allowedAmount(occurrences map[string]int, allowedImports []string) { function := "" funcSelector := "" for _, v := range allowedImports { - //pkg in case it's a build in function and slice in case it's a selector function + // pkg in case it's a build in function and slice in case it's a selector function pkg, slice := trimRelativeImport(v) if slice != nil { function = strings.Join(slice, ".") @@ -531,7 +532,7 @@ func (fv *fileVisitor) Visit(n ast.Node) ast.Visitor { if x, ok := expr.X.(*ast.Ident); ok { fv.selectExpr = append(fv.selectExpr, x.Name+"."+expr.Sel.Name) - //saves the function in to the map, from the package + // saves the function in to the map, from the package if importPkg[x.Name] != nil { importPkg[x.Name].functions = append(importPkg[x.Name].functions, x.Name+"."+expr.Sel.Name) } @@ -549,7 +550,6 @@ func (fv *fileVisitor) Visit(n ast.Node) ast.Visitor { position: fv.getPos(n), }) } - } if exp, ok := n.(*ast.FuncDecl); ok { diff --git a/subjects/activebits.en.md b/subjects/activebits.en.md index f5e7ad22..1d84fc2e 100644 --- a/subjects/activebits.en.md +++ b/subjects/activebits.en.md @@ -7,7 +7,7 @@ Write a function, `ActiveBits`, that returns the number of active `bits` (bits w ### Expected function ```go -func ActiveBits(n int) uint { +func ActiveBits(n int) int { } ``` diff --git a/subjects/addlinkednumbers.en.md b/subjects/addlinkednumbers.en.md index f9b773bf..bb884037 100644 --- a/subjects/addlinkednumbers.en.md +++ b/subjects/addlinkednumbers.en.md @@ -1,16 +1,5 @@ ## addlinkednumbers -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testing are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions You have two numbers represented by a linked list, where each NodeAddL contains a single digit. @@ -39,9 +28,7 @@ Here is a possible program to test your function: ```go package main -import ( - "fmt" -) +import "fmt" func pushFront(node *NodeAddL, num int) *NodeAddL { diff --git a/subjects/advancedsortwordarr.en.md b/subjects/advancedsortwordarr.en.md index 10168e53..48b4c6c9 100644 --- a/subjects/advancedsortwordarr.en.md +++ b/subjects/advancedsortwordarr.en.md @@ -2,12 +2,12 @@ ### Instructions -Write a function `AdvancedSortWordArr` that sorts a `string` array, based on the function `f` passed in parameter. +Write a function `AdvancedSortWordArr` that sorts a slice of `string`, based on the function `f` passed in parameter. ### Expected function ```go -func AdvancedSortWordArr(array []string, f func(a, b string) int) { +func AdvancedSortWordArr(a []string, f func(a, b string) int) { } ``` diff --git a/subjects/alphacount.en.md b/subjects/alphacount.en.md index da478b4f..f7826f8b 100644 --- a/subjects/alphacount.en.md +++ b/subjects/alphacount.en.md @@ -10,7 +10,7 @@ The letters are only the ones from the latin alphabet. ### Expected function ```go -func AlphaCount(str string) int { +func AlphaCount(s string) int { } ``` @@ -28,8 +28,8 @@ import ( ) func main() { - str := "Hello 78 World! 4455 /" - nb := piscine.AlphaCount(str) + s := "Hello 78 World! 4455 /" + nb := piscine.AlphaCount(s) fmt.Println(nb) } ``` diff --git a/subjects/alphamirror.en.md b/subjects/alphamirror.en.md index bb84af50..d1471bba 100644 --- a/subjects/alphamirror.en.md +++ b/subjects/alphamirror.en.md @@ -11,7 +11,7 @@ The case of the letter stays the same, for example : The final result will be followed by a newline (`'\n'`). -If the number of arguments is different from 1, the program displays only a newline (`'\n'`). +If the number of arguments is different from 1, the program displays nothing. ### Usage @@ -21,7 +21,6 @@ student@ubuntu:~/[[ROOT]]/alphamirror$ ./alphamirror "abc" zyx student@ubuntu:~/[[ROOT]]/alphamirror$ ./alphamirror "My horse is Amazing." | cat -e Nb slihv rh Znzarmt.$ -student@ubuntu:~/[[ROOT]]/alphamirror$ ./alphamirror | cat -e -$ +student@ubuntu:~/[[ROOT]]/alphamirror$ ./alphamirror student@ubuntu:~/[[ROOT]]/alphamirror$ ``` diff --git a/subjects/any.en.md b/subjects/any.en.md index 8b2f5d36..e736286b 100644 --- a/subjects/any.en.md +++ b/subjects/any.en.md @@ -2,14 +2,14 @@ ### Instructions -Write a function `Any` that returns `true`, for a `string` array : +Write a function `Any` that returns `true`, for a `string` slice : -- if, when that `string` array is passed through an `f` function, at least one element returns `true`. +- if, when that `string` slice is passed through an `f` function, at least one element returns `true`. ### Expected function ```go -func Any(f func(string) bool, arr []string) bool { +func Any(f func(string) bool, a []string) bool { } ``` @@ -27,11 +27,11 @@ import ( ) func main() { - tab1 := []string{"Hello", "how", "are", "you"} - tab2 := []string{"This", "is", "4", "you"} + a1 := []string{"Hello", "how", "are", "you"} + a2 := []string{"This", "is", "4", "you"} - result1 := piscine.Any(piscine.IsNumeric, tab1) - result2 := piscine.Any(piscine.IsNumeric, tab2) + result1 := piscine.Any(piscine.IsNumeric, a1) + result2 := piscine.Any(piscine.IsNumeric, a2) fmt.Println(result1) fmt.Println(result2) diff --git a/subjects/ascii-art-web/ascii-art-web.audit.en.md b/subjects/ascii-art-web/ascii-art-web.audit.en.md index 51776405..04e6b25b 100644 --- a/subjects/ascii-art-web/ascii-art-web.audit.en.md +++ b/subjects/ascii-art-web/ascii-art-web.audit.en.md @@ -11,22 +11,22 @@ In the first line `{123}` In the second line ` (World)!` ``` - __ __ - / / _ ____ _____ \ \ - | | / | |___ \ |___ / | | -/ / | | __) | |_ \ \ \ -\ \ | | / __/ ___) | / / - | | |_| |_____| |____/ | | - \_\ /_/ - - __ _ _ _ _ __ __ __ __ _ _ __ _ - / / | | | | | | | | \ \ / / \ \ / / | | | | \ \ | | - / / | |__| | ___ | | | | ___ \ \ | | \ \ /\ / / ___ _ __ | | __| | | | | | -< < | __ | / _ \ | | | | / _ \ > > | | \ \/ \/ / / _ \ | '__| | | / _` | | | | | - \ \ | | | | | __/ | | | | | (_) | / / | | \ /\ / | (_) | | | | | | (_| | | | |_| - \_\ |_| |_| \___| |_| |_| \___/ /_/ | | \/ \/ \___/ |_| |_| \__,_| | | (_) - \_\ /_/ - + __ __ + / / _ ____ _____ \ \ + | | / | |___ \ |___ / | | +/ / | | __) | |_ \ \ \ +\ \ | | / __/ ___) | / / + | | |_| |_____| |____/ | | + \_\ /_/ + + __ _ _ _ _ __ __ __ __ _ _ __ _ + / / | | | | | | | | \ \ / / \ \ / / | | | | \ \ | | + / / | |__| | ___ | | | | ___ \ \ | | \ \ /\ / / ___ _ __ | | __| | | | | | +< < | __ | / _ \ | | | | / _ \ > > | | \ \/ \/ / / _ \ | '__| | | / _` | | | | | + \ \ | | | | | __/ | | | | | (_) | / / | | \ /\ / | (_) | | | | | | (_| | | | |_| + \_\ |_| |_| \___| |_| |_| \___/ /_/ | | \/ \/ \___/ |_| |_| \__,_| | | (_) + \_\ /_/ + ``` ###### Does it display the right result as above? @@ -34,14 +34,14 @@ In the second line ` (World)!` ##### Try to input `"123??"` using the template/banner standard. ``` - ___ ___ - _ ____ _____ |__ \ |__ \ -/ | |___ \ |___ / ) | ) | -| | __) | |_ \ / / / / -| | / __/ ___) | |_| |_| -|_| |_____| |____/ (_) (_) - - + ___ ___ + _ ____ _____ |__ \ |__ \ +/ | |___ \ |___ / ) | ) | +| | __) | |_ \ / / / / +| | / __/ ___) | |_| |_| +|_| |_____| |____/ (_) (_) + + ``` ###### Does it display the right result as above? @@ -49,14 +49,14 @@ In the second line ` (World)!` ##### Try to input `"$% "="` using the template/banner shadow. ``` - _| _| - _| _|_| _| _| _| -_|_|_| _|_| _| _|_|_|_|_| -_|_| _| - _|_| _| _|_| _|_|_|_|_| -_|_|_| _| _|_| - _| - + _| _| + _| _|_| _| _| _| +_|_|_| _|_| _| _|_|_|_|_| +_|_| _| + _|_| _| _|_| _|_|_|_|_| +_|_|_| _| _|_| + _| + ``` ###### Does it display the right result as above? @@ -64,14 +64,14 @@ _|_|_| _| _|_| ##### Try to input `"123 T/fs#R"` using the template/banner thinkertoy. ``` - - 0 -- o-o o-O-o o o-o | | o--o - /| o o | | / | -O-O- | | -o | / oo | o -O- o-o | | O-Oo - | / | | / | \ -O-O- | \ -o-o-o o--o o-o o o o o-o | | o o - - + + 0 -- o-o o-O-o o o-o | | o--o + /| o o | | / | -O-O- | | +o | / oo | o -O- o-o | | O-Oo + | / | | / | \ -O-O- | \ +o-o-o o--o o-o o o o o-o | | o o + + ``` ###### Does it display the right result as above? diff --git a/subjects/ascii-art/ascii-art-fs.audit.en.md b/subjects/ascii-art/ascii-art-fs.audit.en.md index 0f634e90..fe0edc2a 100644 --- a/subjects/ascii-art/ascii-art-fs.audit.en.md +++ b/subjects/ascii-art/ascii-art-fs.audit.en.md @@ -5,14 +5,14 @@ ##### Try passing as arguments `"hello" standard` ``` - _ _ _ -| | | | | | -| |__ ___ | | | | ___ -| _ \ / _ \ | | | | / _ \ -| | | | | __/ | | | | | (_) | -|_| |_| \___| |_| |_| \___/ - - + _ _ _ +| | | | | | +| |__ ___ | | | | ___ +| _ \ / _ \ | | | | / _ \ +| | | | | __/ | | | | | (_) | +|_| |_| \___| |_| |_| \___/ + + ``` ###### Does it display the string in the right template as an ASCII art representation as above? @@ -20,14 +20,14 @@ ##### Try passing as arguments `"hello world" shadow` ``` - -_| _| _| _| _| -_|_|_| _|_| _| _| _|_| _| _| _| _|_| _| _|_| _| _|_|_| -_| _| _|_|_|_| _| _| _| _| _| _| _| _| _| _|_| _| _| _| -_| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| -_| _| _|_|_| _| _| _|_| _| _| _|_| _| _| _|_|_| - - + +_| _| _| _| _| +_|_|_| _|_| _| _| _|_| _| _| _| _|_| _| _|_| _| _|_|_| +_| _| _|_|_|_| _| _| _| _| _| _| _| _| _| _|_| _| _| _| +_| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| +_| _| _|_|_| _| _| _|_| _| _| _|_| _| _| _|_|_| + + ``` ###### Does it display the string in the right template as an ASCII art representation as above? @@ -35,14 +35,14 @@ _| _| _|_|_| _| _| _|_| _| _| _|_| _| _| ##### Try passing as arguments `"nice 2 meet you" thinkertoy` ``` - - -- o - o o o | -o-o o-o o-o / o-O-o o-o o-o -o- o o o-o o o -| | | | |-' / | | | |-' |-' | | | | | | | -o o | o-o o-o o--o o o o o-o o-o o o--O o-o o--o - | - o--o + + -- o + o o o | +o-o o-o o-o / o-O-o o-o o-o -o- o o o-o o o +| | | | |-' / | | | |-' |-' | | | | | | | +o o | o-o o-o o--o o o o o-o o-o o o--O o-o o--o + | + o--o ``` ###### Does it display the string in the right template as an ASCII art representation as above? @@ -50,14 +50,14 @@ o o | o-o o-o o--o o o o o-o o-o o o--O o-o o--o ##### Try passing as arguments `"you & me" standard` ``` - - ___ - _ _ ___ _ _ ( _ ) _ __ ___ ___ -| | | | / _ \ | | | | / _ \/\ | '_ ` _ \ / _ \ -| |_| | | (_) | | |_| | | (_> < | | | | | | | __/ - \__, | \___/ \__,_| \___/\/ |_| |_| |_| \___| - __/ / -|___/ + + ___ + _ _ ___ _ _ ( _ ) _ __ ___ ___ +| | | | / _ \ | | | | / _ \/\ | '_ ` _ \ / _ \ +| |_| | | (_) | | |_| | | (_> < | | | | | | | __/ + \__, | \___/ \__,_| \___/\/ |_| |_| |_| \___| + __/ / +|___/ ``` ###### Does it display the string in the right template as an ASCII art representation as above? @@ -65,14 +65,14 @@ o o | o-o o-o o--o o o o o-o o-o o o--O o-o o--o ##### Try passing as arguments `"123" shadow` ``` - - _| _|_| _|_|_| -_|_| _| _| _| - _| _| _|_| - _| _| _| - _| _|_|_|_| _|_|_| - - + + _| _|_| _|_|_| +_|_| _| _| _| + _| _| _|_| + _| _| _| + _| _|_|_|_| _|_|_| + + ``` ###### Does it display the string in the right template as an ASCII art representation as above? @@ -80,14 +80,14 @@ _|_| _| _| _| ##### Try passing as arguments `/(\") thinkertoy` ``` - o o - o / | | \ - / o o - o | | - / o o -o \ / - - + o o + o / | | \ + / o o + o | | + / o o +o \ / + + ``` ###### Does it display the string in the right template as an ASCII art representation as above? @@ -95,14 +95,14 @@ o \ / ##### Try passing as arguments `ABCDEFGHIJKLMNOPQRSTUVWXYZ shadow` ``` - - _|_| _|_|_| _|_|_| _|_|_| _|_|_|_| _|_|_|_| _|_|_| _| _| _|_|_| _| _| _| _| _| _| _| _| _|_| _|_|_| _|_| _|_|_| _|_|_| _|_|_|_|_| _| _| _| _| _| _| _| _| _| _| _|_|_|_|_| -_| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _|_| _|_| _|_| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| -_|_|_|_| _|_|_| _| _| _| _|_|_| _|_|_| _| _|_| _|_|_|_| _| _| _|_| _| _| _| _| _| _| _| _| _| _|_|_| _| _|_| _|_|_| _|_| _| _| _| _| _| _| _| _| _| _| _| -_| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| -_| _| _|_|_| _|_|_| _|_|_| _|_|_|_| _| _|_|_| _| _| _|_|_| _|_| _| _| _|_|_|_| _| _| _| _| _|_| _| _|_| _| _| _| _|_|_| _| _|_| _| _| _| _| _| _| _|_|_|_|_| - - + + _|_| _|_|_| _|_|_| _|_|_| _|_|_|_| _|_|_|_| _|_|_| _| _| _|_|_| _| _| _| _| _| _| _| _| _|_| _|_|_| _|_| _|_|_| _|_|_| _|_|_|_|_| _| _| _| _| _| _| _| _| _| _| _|_|_|_|_| +_| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _|_| _|_| _|_| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| +_|_|_|_| _|_|_| _| _| _| _|_|_| _|_|_| _| _|_| _|_|_|_| _| _| _|_| _| _| _| _| _| _| _| _| _| _|_|_| _| _|_| _|_|_| _|_| _| _| _| _| _| _| _| _| _| _| _| +_| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| _| +_| _| _|_|_| _|_|_| _|_|_| _|_|_|_| _| _|_|_| _| _| _|_|_| _|_| _| _| _|_|_|_| _| _| _| _| _|_| _| _|_| _| _| _| _|_|_| _| _|_| _| _| _| _| _| _| _|_|_|_|_| + + ``` @@ -111,14 +111,14 @@ _| _| _|_|_| _|_|_| _|_|_| _|_|_|_| _| _|_|_| _| _| _|_|_| ##### Try passing as arguments `\"#$%&/()*+,-./ thinkertoy` ``` -o o | | -| | | | -O-O- O o / \ o | o o - -O-O- o | | o / o / o o \|/ | / - | | -O-O- / /| o | | --O-- -o- o - -O-O- | | o / o o-O- / o o /|\ | o-o / - | | -O-O- O | o \ / o | o o O o - | | | - +o o | | +| | | | -O-O- O o / \ o | o o + -O-O- o | | o / o / o o \|/ | / + | | -O-O- / /| o | | --O-- -o- o + -O-O- | | o / o o-O- / o o /|\ | o-o / + | | -O-O- O | o \ / o | o o O o + | | | + ``` ###### Does it display the string in the right template as an ASCII art representation as above? @@ -126,14 +126,14 @@ o o | | ##### Try passing as arguments `"It's Working" thinkertoy` ``` - o -o-O-o o | o o o - | | | | | / o - | -o- o-o o o o o-o o-o OO o-o o--o - | | \ \ / \ / | | | | \ | | | | | -o-O-o o o-o o o o-o o o o | o o o--O - | - o--o + o +o-O-o o | o o o + | | | | | / o + | -o- o-o o o o o-o o-o OO o-o o--o + | | \ \ / \ / | | | | \ | | | | | +o-O-o o o-o o o o-o o o o | o o o--O + | + o--o ``` ###### Does it display the string in the right template as an ASCII art representation as above? diff --git a/subjects/ascii-art/ascii-art-fs.en.md b/subjects/ascii-art/ascii-art-fs.en.md index 1b97198b..01b673ca 100644 --- a/subjects/ascii-art/ascii-art-fs.en.md +++ b/subjects/ascii-art/ascii-art-fs.en.md @@ -29,34 +29,34 @@ This project will help you learn about : ```console student@ubuntu:~/ascii-art$ go build student@ubuntu:~/ascii-art$ ./ascii-art "hello" standard - _ _ _ - | | | | | | - | |__ ___ | | | | ___ - | _ \ / _ \ | | | | / _ \ - | | | | | __/ | | | | | (_) | - |_| |_| \___| |_| |_| \___/ - - + _ _ _ + | | | | | | + | |__ ___ | | | | ___ + | _ \ / _ \ | | | | / _ \ + | | | | | __/ | | | | | (_) | + |_| |_| \___| |_| |_| \___/ + + student@ubuntu:~/ascii-art$ ./ascii-art "Hello There!" shadow - -_| _| _| _| _|_|_|_|_| _| _| -_| _| _|_| _| _| _|_| _| _|_|_| _|_| _| _|_| _|_| _| -_|_|_|_| _|_|_|_| _| _| _| _| _| _| _| _|_|_|_| _|_| _|_|_|_| _| -_| _| _| _| _| _| _| _| _| _| _| _| _| -_| _| _|_|_| _| _| _|_| _| _| _| _|_|_| _| _|_|_| _| - - + +_| _| _| _| _|_|_|_|_| _| _| +_| _| _|_| _| _| _|_| _| _|_|_| _|_| _| _|_| _|_| _| +_|_|_|_| _|_|_|_| _| _| _| _| _| _| _| _|_|_|_| _|_| _|_|_|_| _| +_| _| _| _| _| _| _| _| _| _| _| _| _| +_| _| _|_|_| _| _| _|_| _| _| _| _|_|_| _| _|_|_| _| + + student@ubuntu:~/ascii-art$ ./ascii-art "Hello There!" thinkertoy - -o o o o o-O-o o -| | | | | | o -O--O o-o | | o-o | O--o o-o o-o o-o | -| | |-' | | | | | | | |-' | |-' o -o o o-o o o o-o o o o o-o o o-o - O - + +o o o o o-O-o o +| | | | | | o +O--O o-o | | o-o | O--o o-o o-o o-o | +| | |-' | | | | | | | |-' | |-' o +o o o-o o o o-o o o o o-o o o-o + O + student@ubuntu:~/ascii-art$ ``` diff --git a/subjects/ascii-art/ascii-art-output.audit.en.md b/subjects/ascii-art/ascii-art-output.audit.en.md index ab5edcab..345acb67 100644 --- a/subjects/ascii-art/ascii-art-output.audit.en.md +++ b/subjects/ascii-art/ascii-art-output.audit.en.md @@ -6,22 +6,22 @@ ``` student$ cat test00.txt - -_|_|_|_| _| _| -_| _| _|_| _|_|_| _|_|_|_| -_|_|_| _| _|_| _|_| _| -_| _| _| _|_| _| -_| _| _| _|_|_| _|_| - - - -_|_|_|_|_| _| - _| _|_| _|_|_| _|_|_|_| - _| _|_|_|_| _|_| _| - _| _| _|_| _| - _| _|_|_| _|_|_| _|_| - - + +_|_|_|_| _| _| +_| _| _|_| _|_|_| _|_|_|_| +_|_|_| _| _|_| _|_| _| +_| _| _| _|_| _| +_| _| _| _|_|_| _|_| + + + +_|_|_|_|_| _| + _| _|_| _|_|_| _|_|_|_| + _| _|_|_|_| _|_| _| + _| _| _|_| _| + _| _|_|_| _|_|_| _|_| + + ``` ###### Does it save the right output in the right file? @@ -30,14 +30,14 @@ _|_|_|_|_| _| ``` student$ cat test01.txt - _ _ _ -| | | | | | -| |__ ___ | | | | ___ -| _ \ / _ \ | | | | / _ \ -| | | | | __/ | | | | | (_) | -|_| |_| \___| |_| |_| \___/ - - + _ _ _ +| | | | | | +| |__ ___ | | | | ___ +| _ \ / _ \ | | | | / _ \ +| | | | | __/ | | | | | (_) | +|_| |_| \___| |_| |_| \___/ + + ``` ###### Does it save the right output in the right file? @@ -46,14 +46,14 @@ student$ cat test01.txt ``` student$ cat test02.txt - __ _ _ _ _ __ - _ ____ _____ \ \ _| || |_ | | (_) / / -/ | |___ \ |___ / ______ \ \ |_ __ _| / __) / / -| | __) | |_ \ |______| > > _| || |_ \__ \ / / -| | / __/ ___) | / / |_ __ _| ( / / / _ -|_| |_____| |____/ /_/ |_||_| |_| /_/ (_) - - + __ _ _ _ _ __ + _ ____ _____ \ \ _| || |_ | | (_) / / +/ | |___ \ |___ / ______ \ \ |_ __ _| / __) / / +| | __) | |_ \ |______| > > _| || |_ \__ \ / / +| | / __/ ___) | / / |_ __ _| ( / / / _ +|_| |_____| |____/ /_/ |_||_| |_| /_/ (_) + + ``` ###### Does it save the right output in the right file? @@ -62,14 +62,14 @@ student$ cat test02.txt ``` student$ cat test03.txt - -_| _| _|_|_| _|_| _| _| _| _| _|_| _| _| _|_|_|_|_| -_| _| _| _| _| _| _|_|_|_|_| _|_|_| _|_| _| _| _| _| _| -_|_|_|_| _|_| _| _|_|_|_|_| _| _| _| _|_| _| _|_| _| _| _|_|_| _| - _| _| _| _| _|_|_|_|_| _|_| _| _|_| _| _| _| _| _| _| - _| _|_|_| _|_|_|_| _| _| _| _|_|_| _| _|_| _|_| _| _| _|_|_|_| - _| _| - _|_|_|_|_|_| + +_| _| _|_|_| _|_| _| _| _| _| _|_| _| _| _|_|_|_|_| +_| _| _| _| _| _| _|_|_|_|_| _|_|_| _|_| _| _| _| _| _| +_|_|_|_| _|_| _| _|_|_|_|_| _| _| _| _|_| _| _|_| _| _| _|_|_| _| + _| _| _| _| _|_|_|_|_| _|_| _| _|_| _| _| _| _| _| _| + _| _|_|_| _|_|_|_| _| _| _| _|_|_| _| _|_| _|_| _| _| _|_|_|_| + _| _| + _|_|_|_|_|_| ``` ###### Does it save the right output in the right file? @@ -78,14 +78,14 @@ _|_|_|_| _|_| _| _|_|_|_|_| _| _| _| _|_| _ ``` student$ cat test04.txt - -_|_|_|_|_| _| - _| _|_|_| _|_| _| _|_| _|_| - _| _| _| _|_|_|_| _|_| _|_|_|_| - _| _| _| _| _| _| - _| _| _| _|_|_| _| _|_|_| - - + +_|_|_|_|_| _| + _| _|_|_| _|_| _| _|_| _|_| + _| _| _| _|_|_|_| _|_| _|_|_|_| + _| _| _| _| _| _| + _| _| _| _|_|_| _| _|_|_| + + ``` ###### Does it save the right output in the right file? @@ -94,14 +94,14 @@ _|_|_|_|_| _| ``` student$ cat test05.txt - o o | | - 0 -- o-o o | | | | -O-O- O o - /| o o | \ -O-O- o | | o / / \ -o | / oo O | | -O-O- / o O-o - | / | o-o / -O-O- | | o / o \ -o-o-o o--o o-o o | | -O-O- O o- - | | - + o o | | + 0 -- o-o o | | | | -O-O- O o + /| o o | \ -O-O- o | | o / / \ +o | / oo O | | -O-O- / o O-o + | / | o-o / -O-O- | | o / o \ +o-o-o o--o o-o o | | -O-O- O o- + | | + ``` ###### Does it save the right output in the right file? @@ -111,30 +111,30 @@ o-o-o o--o o-o o | | -O-O- O o- ``` student$ cat test06.txt - - -- -o o - / o o o-o o o - / | | | | | | -o--o o--O o-o o--o - | - o--o + + -- +o o + / o o o-o o o + / | | | | | | +o--o o--O o-o o--o + | + o--o ``` ###### Does it save the right output in the right file? -##### Try passing as arguments `"Testing long output!" standard --output=test07.txt` +##### Try passing as arguments `"Testing long output!" standard --output=test07.txt` ``` student$ cat test07.txt - _______ _ _ _ _ _ _ -|__ __| | | (_) __ _ | | __ _ | | | | | | - | | ___ ___ | |_ _ _ __ / _` | | | ___ _ __ / _` | ___ _ _ | |_ _ __ _ _ | |_ | | - | | / _ \ / __| | __| | | | '_ \ | (_| | | | / _ \ | '_ \ | (_| | / _ \ | | | | | __| | '_ \ | | | | | __| | | - | | | __/ \__ \ \ |_ | | | | | | \__, | | | | (_) | | | | | \__, | | (_) | | |_| | \ |_ | |_) | | |_| | \ |_ |_| - |_| \___| |___/ \__| |_| |_| |_| __/ | |_| \___/ |_| |_| __/ | \___/ \__,_| \__| | .__/ \__,_| \__| (_) - |___/ |___/ | | - |_| + _______ _ _ _ _ _ _ +|__ __| | | (_) __ _ | | __ _ | | | | | | + | | ___ ___ | |_ _ _ __ / _` | | | ___ _ __ / _` | ___ _ _ | |_ _ __ _ _ | |_ | | + | | / _ \ / __| | __| | | | '_ \ | (_| | | | / _ \ | '_ \ | (_| | / _ \ | | | | | __| | '_ \ | | | | | __| | | + | | | __/ \__ \ \ |_ | | | | | | \__, | | | | (_) | | | | | \__, | | (_) | | |_| | \ |_ | |_) | | |_| | \ |_ |_| + |_| \___| |___/ \__| |_| |_| |_| __/ | |_| \___/ |_| |_| __/ | \___/ \__,_| \__| | .__/ \__,_| \__| (_) + |___/ |___/ | | + |_| ``` ###### Does it save the right output in the right file? diff --git a/subjects/ascii-art/ascii-art-output.en.md b/subjects/ascii-art/ascii-art-output.en.md index dddbb531..5f2a6eb5 100644 --- a/subjects/ascii-art/ascii-art-output.en.md +++ b/subjects/ascii-art/ascii-art-output.en.md @@ -31,25 +31,25 @@ This project will help you learn about : student@ubuntu:~/ascii-art$ go build student@ubuntu:~/ascii-art$ ./ascii-art "hello" standard --output=banner.txt student@ubuntu:~/ascii-art$ cat banner.txt - _ _ _ -| | | | | | -| |__ ___ | | | | ___ -| _ \ / _ \ | | | | / _ \ -| | | | | __/ | | | | | (_) | -|_| |_| \___| |_| |_| \___/ - - + _ _ _ +| | | | | | +| |__ ___ | | | | ___ +| _ \ / _ \ | | | | / _ \ +| | | | | __/ | | | | | (_) | +|_| |_| \___| |_| |_| \___/ + + student@ubuntu:~/ascii-art$ ./ascii-art "Hello There!" shadow --output=banner.txt student@ubuntu:~/ascii-art$ cat banner.txt - -_| _| _| _| _|_|_|_|_| _| _| -_| _| _|_| _| _| _|_| _| _|_|_| _|_| _| _|_| _|_| _| -_|_|_|_| _|_|_|_| _| _| _| _| _| _| _| _|_|_|_| _|_| _|_|_|_| _| -_| _| _| _| _| _| _| _| _| _| _| _| _| -_| _| _|_|_| _| _| _|_| _| _| _| _|_|_| _| _|_|_| _| - - + +_| _| _| _| _|_|_|_|_| _| _| +_| _| _|_| _| _| _|_| _| _|_|_| _|_| _| _|_| _|_| _| +_|_|_|_| _|_|_|_| _| _| _| _| _| _| _| _|_|_|_| _|_| _|_|_|_| _| +_| _| _| _| _| _| _| _| _| _| _| _| _| +_| _| _|_|_| _| _| _|_| _| _| _| _|_|_| _| _|_|_| _| + + student@ubuntu:~/ascii-art$ ``` diff --git a/subjects/ascii-art/ascii-art-reverse-example.md b/subjects/ascii-art/ascii-art-reverse-example.md index 55bae938..ee4796ae 100644 --- a/subjects/ascii-art/ascii-art-reverse-example.md +++ b/subjects/ascii-art/ascii-art-reverse-example.md @@ -5,14 +5,14 @@ ### example00 ```console - _ _ _ _ __ __ _ _ -| | | | | | | | \ \ / / | | | | -| |__| | ___ | | | | ___ \ \ /\ / / ___ _ __ | | __| | -| __ | / _ \ | | | | / _ \ \ \/ \/ / / _ \ | '__| | | / _` | -| | | | | __/ | | | | | (_) | \ /\ / | (_) | | | | | | (_| | -|_| |_| \___| |_| |_| \___/ \/ \/ \___/ |_| |_| \__,_| - - + _ _ _ _ __ __ _ _ +| | | | | | | | \ \ / / | | | | +| |__| | ___ | | | | ___ \ \ /\ / / ___ _ __ | | __| | +| __ | / _ \ | | | | / _ \ \ \/ \/ / / _ \ | '__| | | / _` | +| | | | | __/ | | | | | (_) | \ /\ / | (_) | | | | | | (_| | +|_| |_| \___| |_| |_| \___/ \/ \/ \___/ |_| |_| \__,_| + + ``` @@ -20,14 +20,14 @@ ### example01 ```console - - _ ____ _____ -/ | |___ \ |___ / -| | __) | |_ \ -| | / __/ ___) | -|_| |_____| |____/ - - + + _ ____ _____ +/ | |___ \ |___ / +| | __) | |_ \ +| | / __/ ___) | +|_| |_____| |____/ + + ``` @@ -35,14 +35,14 @@ ### example02 ```console - _ _ __ ___ - _| || |_ ______ \ \ | _| -|_ __ _| |______| \ \ | | - _| || |_ ______ \ \ | | -|_ __ _| |______| \ \ | | - |_||_| \_\ | |_ - |___| - + _ _ __ ___ + _| || |_ ______ \ \ | _| +|_ __ _| |______| \ \ | | + _| || |_ ______ \ \ | | +|_ __ _| |______| \ \ | | + |_||_| \_\ | |_ + |___| + ``` @@ -50,69 +50,69 @@ ### example03 ```console - __ _ _ _ __ - / / | | | | (_) __ _ ___ ____ _____ _ _ \ \ -| | ___ ___ _ __ ___ | |_ | |__ _ _ __ / _` | ( _ ) |___ \ |___ / | || | | | -| | / __| / _ \ | '_ ` _ \ | __| | _ \ | | | '_ \ | (_| | / _ \/\ __) | |_ \ | || |_ | | -| | \__ \ | (_) | | | | | | | \ |_ | | | | | | | | | | \__, | | (_> < / __/ ___) | |__ _| | | -| | |___/ \___/ |_| |_| |_| \__| |_| |_| |_| |_| |_| __/ | \___/\/ |_____| |____/ |_| | | - \_\ |___/ /_/ - + __ _ _ _ __ + / / | | | | (_) __ _ ___ ____ _____ _ _ \ \ +| | ___ ___ _ __ ___ | |_ | |__ _ _ __ / _` | ( _ ) |___ \ |___ / | || | | | +| | / __| / _ \ | '_ ` _ \ | __| | _ \ | | | '_ \ | (_| | / _ \/\ __) | |_ \ | || |_ | | +| | \__ \ | (_) | | | | | | | \ |_ | | | | | | | | | | \__, | | (_> < / __/ ___) | |__ _| | | +| | |___/ \___/ |_| |_| |_| \__| |_| |_| |_| |_| |_| __/ | \___/\/ |_____| |____/ |_| | | + \_\ |___/ /_/ + ``` ### example04 ```console - _ _ __ _ _ _ _ _ - | | | | / _| __ _ | | (_) (_) _ | | | | - __ _ | |__ ___ __| | ___ | |_ / _` | | |__ _ _ | | _ | | _ __ ___ _ __ ___ _ __ __ _ _ __ ___ | |_ _ _ __ __ __ __ __ __ _ _ ____ - / _` | | '_ \ / __| / _` | / _ \ | _| | (_| | | _ \ | | | | | |/ / | | | '_ ` _ \ | '_ \ / _ \ | '_ \ / _` | | '__| / __| | __| | | | | \ \ / / \ \ /\ / / \ \/ / | | | | |_ / -| (_| | | |_) | | (__ | (_| | | __/ | | \__, | | | | | | | | | | < | | | | | | | | | | | | | (_) | | |_) | | (_| | | | \__ \ \ |_ | |_| | \ V / \ V V / > < | |_| | / / - \__,_| |_.__/ \___| \__,_| \___| |_| __/ | |_| |_| |_| | | |_|\_\ |_| |_| |_| |_| |_| |_| \___/ | .__/ \__, | |_| |___/ \__| \__,_| \_/ \_/\_/ /_/\_\ \__, | /___| - |___/ _/ | | | | | __/ / - |__/ |_| |_| |___/ + _ _ __ _ _ _ _ _ + | | | | / _| __ _ | | (_) (_) _ | | | | + __ _ | |__ ___ __| | ___ | |_ / _` | | |__ _ _ | | _ | | _ __ ___ _ __ ___ _ __ __ _ _ __ ___ | |_ _ _ __ __ __ __ __ __ _ _ ____ + / _` | | '_ \ / __| / _` | / _ \ | _| | (_| | | _ \ | | | | | |/ / | | | '_ ` _ \ | '_ \ / _ \ | '_ \ / _` | | '__| / __| | __| | | | | \ \ / / \ \ /\ / / \ \/ / | | | | |_ / +| (_| | | |_) | | (__ | (_| | | __/ | | \__, | | | | | | | | | | < | | | | | | | | | | | | | (_) | | |_) | | (_| | | | \__ \ \ |_ | |_| | \ V / \ V V / > < | |_| | / / + \__,_| |_.__/ \___| \__,_| \___| |_| __/ | |_| |_| |_| | | |_|\_\ |_| |_| |_| |_| |_| |_| \___/ | .__/ \__, | |_| |___/ \__| \__,_| \_/ \_/\_/ /_/\_\ \__, | /___| + |___/ _/ | | | | | __/ / + |__/ |_| |_| |___/ ``` ### example05 ```console -__ _ _ _ _ _ _ _ __ _ __ __ _ __ -\ \ | | ( | ) _| || |_ | | (_) / / ___ ( ) / / \ \ /\| |/\ _ / / - \ \ | | V V |_ __ _| / __) / / ( _ ) |/ | | | | \ ` ' / _| |_ ______ / / - \ \ | | _| || |_ \__ \ / / / _ \/\ | | | | |_ _| |_ _| |______| / / - \ \ |_| |_ __ _| ( / / / _ | (_> < | | | | / , . \ |_| _ _ / / - \_\ (_) |_||_| |_| /_/ (_) \___/\/ | | | | \/|_|\/ ( ) (_) /_/ - \_\ /_/ |/ - +__ _ _ _ _ _ _ _ __ _ __ __ _ __ +\ \ | | ( | ) _| || |_ | | (_) / / ___ ( ) / / \ \ /\| |/\ _ / / + \ \ | | V V |_ __ _| / __) / / ( _ ) |/ | | | | \ ` ' / _| |_ ______ / / + \ \ | | _| || |_ \__ \ / / / _ \/\ | | | | |_ _| |_ _| |______| / / + \ \ |_| |_ __ _| ( / / / _ | (_> < | | | | / , . \ |_| _ _ / / + \_\ (_) |_||_| |_| /_/ (_) \___/\/ | | | | \/|_|\/ ( ) (_) /_/ + \_\ /_/ |/ + ``` ### example06 ```console - __ __ ___ - _ _ / / ______ \ \ |__ \ ____ -(_) (_) / / |______| \ \ ) | / __ \ - < < ______ > > / / / / _` | - _ _ \ \ |______| / / |_| | | (_| | -(_) ( ) \_\ /_/ (_) \ \__,_| - |/ \____/ - + __ __ ___ + _ _ / / ______ \ \ |__ \ ____ +(_) (_) / / |______| \ \ ) | / __ \ + < < ______ > > / / / / _` | + _ _ \ \ |______| / / |_| | | (_| | +(_) ( ) \_\ /_/ (_) \ \__,_| + |/ \____/ + ``` ### example07 ```console - ____ _____ _____ ______ ______ _____ _ _ _____ _ _ __ _ __ __ _ _ ____ _____ ____ _____ _____ _______ _ _ __ __ __ __ __ __ __ __ ______ - /\ | _ \ / ____| | __ \ | ____| | ____| / ____| | | | | |_ _| | | | |/ / | | | \/ | | \ | | / __ \ | __ \ / __ \ | __ \ / ____| |__ __| | | | | \ \ / / \ \ / / \ \ / / \ \ / / |___ / - / \ | |_) | | | | | | | | |__ | |__ | | __ | |__| | | | | | | ' / | | | \ / | | \| | | | | | | |__) | | | | | | |__) | | (___ | | | | | | \ \ / / \ \ /\ / / \ V / \ \_/ / / / - / /\ \ | _ < | | | | | | | __| | __| | | |_ | | __ | | | _ | | | < | | | |\/| | | . ` | | | | | | ___/ | | | | | _ / \___ \ | | | | | | \ \/ / \ \/ \/ / > < \ / / / - / ____ \ | |_) | | |____ | |__| | | |____ | | | |__| | | | | | _| |_ | |__| | | . \ | |____ | | | | | |\ | | |__| | | | | |__| | | | \ \ ____) | | | | |__| | \ / \ /\ / / . \ | | / /__ -/_/ \_\ |____/ \_____| |_____/ |______| |_| \_____| |_| |_| |_____| \____/ |_|\_\ |______| |_| |_| |_| \_| \____/ |_| \___\_\ |_| \_\ |_____/ |_| \____/ \/ \/ \/ /_/ \_\ |_| /_____| - - + ____ _____ _____ ______ ______ _____ _ _ _____ _ _ __ _ __ __ _ _ ____ _____ ____ _____ _____ _______ _ _ __ __ __ __ __ __ __ __ ______ + /\ | _ \ / ____| | __ \ | ____| | ____| / ____| | | | | |_ _| | | | |/ / | | | \/ | | \ | | / __ \ | __ \ / __ \ | __ \ / ____| |__ __| | | | | \ \ / / \ \ / / \ \ / / \ \ / / |___ / + / \ | |_) | | | | | | | | |__ | |__ | | __ | |__| | | | | | | ' / | | | \ / | | \| | | | | | | |__) | | | | | | |__) | | (___ | | | | | | \ \ / / \ \ /\ / / \ V / \ \_/ / / / + / /\ \ | _ < | | | | | | | __| | __| | | |_ | | __ | | | _ | | | < | | | |\/| | | . ` | | | | | | ___/ | | | | | _ / \___ \ | | | | | | \ \/ / \ \/ \/ / > < \ / / / + / ____ \ | |_) | | |____ | |__| | | |____ | | | |__| | | | | | _| |_ | |__| | | . \ | |____ | | | | | |\ | | |__| | | | | |__| | | | \ \ ____) | | | | |__| | \ / \ /\ / / . \ | | / /__ +/_/ \_\ |____/ \_____| |_____/ |______| |_| \_____| |_| |_| |_____| \____/ |_|\_\ |______| |_| |_| |_| \_| \____/ |_| \___\_\ |_| \_\ |_____/ |_| \____/ \/ \/ \/ /_/ \_\ |_| /_____| + + ``` diff --git a/subjects/ascii-art/ascii-art-reverse.en.md b/subjects/ascii-art/ascii-art-reverse.en.md index b4abebc0..b97f9739 100644 --- a/subjects/ascii-art/ascii-art-reverse.en.md +++ b/subjects/ascii-art/ascii-art-reverse.en.md @@ -33,14 +33,14 @@ This project will help you learn about : ```console student@ubuntu:~/ascii-art$ go build student@ubuntu:~/ascii-art$ cat file.txt - _ _ _ -| | | | | | -| |__ ___ | | | | ___ -| _ \ / _ \ | | | | / _ \ -| | | | | __/ | | | | | (_) | -|_| |_| \___| |_| |_| \___/ - - + _ _ _ +| | | | | | +| |__ ___ | | | | ___ +| _ \ / _ \ | | | | / _ \ +| | | | | __/ | | | | | (_) | +|_| |_| \___| |_| |_| \___/ + + student@ubuntu:~/ascii-art$ ./ascii-art --reverse=file.txt hello diff --git a/subjects/ascii-art/ascii-art.audit.en.md b/subjects/ascii-art/ascii-art.audit.en.md index 5fd42e71..2e2c8c91 100644 --- a/subjects/ascii-art/ascii-art.audit.en.md +++ b/subjects/ascii-art/ascii-art.audit.en.md @@ -3,231 +3,267 @@ ###### Has the requirement for the allowed packages been respected? (Reminder for this project: (only [standard packages](https://golang.org/pkg/) ##### Try passing as argument `"hello"`. + ``` - _ _ _ -| | | | | | -| |__ ___ | | | | ___ -| _ \ / _ \ | | | | / _ \ -| | | | | __/ | | | | | (_) | -|_| |_| \___| |_| |_| \___/ - - + _ _ _ +| | | | | | +| |__ ___ | | | | ___ +| _ \ / _ \ | | | | / _ \ +| | | | | __/ | | | | | (_) | +|_| |_| \___| |_| |_| \___/ + + ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing as argument `"HELLO"`. + ``` - _ _ ______ _ _ ____ -| | | | | ____| | | | | / __ \ -| |__| | | |__ | | | | | | | | -| __ | | __| | | | | | | | | -| | | | | |____ | |____ | |____ | |__| | -|_| |_| |______| |______| |______| \____/ - - + _ _ ______ _ _ ____ +| | | | | ____| | | | | / __ \ +| |__| | | |__ | | | | | | | | +| __ | | __| | | | | | | | | +| | | | | |____ | |____ | |____ | |__| | +|_| |_| |______| |______| |______| \____/ + + ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing as argument `"HeLlo HuMaN"`. + ``` - _ _ _ _ _ _ __ __ _ _ -| | | | | | | | | | | | | \/ | | \ | | -| |__| | ___ | | | | ___ | |__| | _ _ | \ / | __ _ | \| | -| __ | / _ \ | | | | / _ \ | __ | | | | | | |\/| | / _` | | . ` | -| | | | | __/ | |____ | | | (_) | | | | | | |_| | | | | | | (_| | | |\ | -|_| |_| \___| |______| |_| \___/ |_| |_| \__,_| |_| |_| \__,_| |_| \_| - - + _ _ _ _ _ _ __ __ _ _ +| | | | | | | | | | | | | \/ | | \ | | +| |__| | ___ | | | | ___ | |__| | _ _ | \ / | __ _ | \| | +| __ | / _ \ | | | | / _ \ | __ | | | | | | |\/| | / _` | | . ` | +| | | | | __/ | |____ | | | (_) | | | | | | |_| | | | | | | (_| | | |\ | +|_| |_| \___| |______| |_| \___/ |_| |_| \__,_| |_| |_| \__,_| |_| \_| + + ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing as argument `"1Hello 2There"`. + ``` - _ _ _ _ _______ _ - _ | | | | | | | | ____ |__ __| | | -/ | | |__| | ___ | | | | ___ |___ \ | | | |__ ___ _ __ ___ -| | | __ | / _ \ | | | | / _ \ __) | | | | _ \ / _ \ | '__| / _ \ -| | | | | | | __/ | | | | | (_) | / __/ | | | | | | | __/ | | | __/ -|_| |_| |_| \___| |_| |_| \___/ |_____| |_| |_| |_| \___| |_| \___| - - + _ _ _ _ _______ _ + _ | | | | | | | | ____ |__ __| | | +/ | | |__| | ___ | | | | ___ |___ \ | | | |__ ___ _ __ ___ +| | | __ | / _ \ | | | | / _ \ __) | | | | _ \ / _ \ | '__| / _ \ +| | | | | | | __/ | | | | | (_) | / __/ | | | | | | | __/ | | | __/ +|_| |_| |_| \___| |_| |_| \___/ |_____| |_| |_| |_| \___| |_| \___| + + ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing as argument `"Hello\nThere"`. + ``` - _ _ _ _ -| | | | | | | | -| |__| | ___ | | | | ___ -| __ | / _ \ | | | | / _ \ -| | | | | __/ | | | | | (_) | -|_| |_| \___| |_| |_| \___/ - - - _______ _ -|__ __| | | - | | | |__ ___ _ __ ___ - | | | _ \ / _ \ | '__| / _ \ - | | | | | | | __/ | | | __/ - |_| |_| |_| \___| |_| \___| - - + _ _ _ _ +| | | | | | | | +| |__| | ___ | | | | ___ +| __ | / _ \ | | | | / _ \ +| | | | | __/ | | | | | (_) | +|_| |_| \___| |_| |_| \___/ + + + _______ _ +|__ __| | | + | | | |__ ___ _ __ ___ + | | | _ \ / _ \ | '__| / _ \ + | | | | | | | __/ | | | __/ + |_| |_| |_| \___| |_| \___| + + ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing `"{Hello & There #}"` as argument. + ``` - __ _ _ _ _ _______ _ _ _ __ - / / | | | | | | | | ___ |__ __| | | _| || |_ \ \ - | | | |__| | ___ | | | | ___ ( _ ) | | | |__ ___ _ __ ___ |_ __ _| | | -/ / | __ | / _ \ | | | | / _ \ / _ \/\ | | | _ \ / _ \ | '__| / _ \ _| || |_ \ \ -\ \ | | | | | __/ | | | | | (_) | | (_> < | | | | | | | __/ | | | __/ |_ __ _| / / - | | |_| |_| \___| |_| |_| \___/ \___/\/ |_| |_| |_| \___| |_| \___| |_||_| | | - \_\ /_/ - + __ _ _ _ _ _______ _ _ _ __ + / / | | | | | | | | ___ |__ __| | | _| || |_ \ \ + | | | |__| | ___ | | | | ___ ( _ ) | | | |__ ___ _ __ ___ |_ __ _| | | +/ / | __ | / _ \ | | | | / _ \ / _ \/\ | | | _ \ / _ \ | '__| / _ \ _| || |_ \ \ +\ \ | | | | | __/ | | | | | (_) | | (_> < | | | | | | | __/ | | | __/ |_ __ _| / / + | | |_| |_| \___| |_| |_| \___/ \___/\/ |_| |_| |_| \___| |_| \___| |_||_| | | + \_\ /_/ + ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing `"hello There 1 to 2!"` as argument. + ``` - _ _ _ _______ _ _ _ -| | | | | | |__ __| | | _ | | ____ | | -| |__ ___ | | | | ___ | | | |__ ___ _ __ ___ / | | |_ ___ |___ \ | | -| _ \ / _ \ | | | | / _ \ | | | _ \ / _ \ | '__| / _ \ | | | __| / _ \ __) | | | -| | | | | __/ | | | | | (_) | | | | | | | | __/ | | | __/ | | \ |_ | (_) | / __/ |_| -|_| |_| \___| |_| |_| \___/ |_| |_| |_| \___| |_| \___| |_| \__| \___/ |_____| (_) - - + _ _ _ _______ _ _ _ +| | | | | | |__ __| | | _ | | ____ | | +| |__ ___ | | | | ___ | | | |__ ___ _ __ ___ / | | |_ ___ |___ \ | | +| _ \ / _ \ | | | | / _ \ | | | _ \ / _ \ | '__| / _ \ | | | __| / _ \ __) | | | +| | | | | __/ | | | | | (_) | | | | | | | | __/ | | | __/ | | \ |_ | (_) | / __/ |_| +|_| |_| \___| |_| |_| \___/ |_| |_| |_| \___| |_| \___| |_| \__| \___/ |_____| (_) + + ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing `"MaD3IrA&LiSboN"` as argument. + ``` - __ __ _____ _____ _ _ _____ _ _ _ -| \/ | | __ \ _____ |_ _| /\ ___ | | (_) / ____| | | | \ | | -| \ / | __ _ | | | | |___ / | | _ __ / \ ( _ ) | | _ | (___ | |__ ___ | \| | -| |\/| | / _` | | | | | |_ \ | | | '__| / /\ \ / _ \/\ | | | | \___ \ | '_ \ / _ \ | . ` | -| | | | | (_| | | |__| | ___) | _| |_ | | / ____ \ | (_> < | |____ | | ____) | | |_) | | (_) | | |\ | -|_| |_| \__,_| |_____/ |____/ |_____| |_| /_/ \_\ \___/\/ |______| |_| |_____/ |_.__/ \___/ |_| \_| - - + __ __ _____ _____ _ _ _____ _ _ _ +| \/ | | __ \ _____ |_ _| /\ ___ | | (_) / ____| | | | \ | | +| \ / | __ _ | | | | |___ / | | _ __ / \ ( _ ) | | _ | (___ | |__ ___ | \| | +| |\/| | / _` | | | | | |_ \ | | | '__| / /\ \ / _ \/\ | | | | \___ \ | '_ \ / _ \ | . ` | +| | | | | (_| | | |__| | ___) | _| |_ | | / ____ \ | (_> < | |____ | | ____) | | |_) | | (_) | | |\ | +|_| |_| \__,_| |_____/ |____/ |_____| |_| /_/ \_\ \___/\/ |______| |_| |_____/ |_.__/ \___/ |_| \_| + + ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing `"1a\"#FdwHywR&/()="` as argument. + ``` - _ _ _ _ ______ _ _ _ _____ __ __ __ - _ ( | ) _| || |_ | ____| | | | | | | | __ \ ___ / / / / \ \ ______ -/ | __ _ V V |_ __ _| | |__ __| | __ __ | |__| | _ _ __ __ | |__) | ( _ ) / / | | | | |______| -| | / _` | _| || |_ | __| / _` | \ \ /\ / / | __ | | | | | \ \ /\ / / | _ / / _ \/\ / / | | | | ______ -| | | (_| | |_ __ _| | | | (_| | \ V V / | | | | | |_| | \ V V / | | \ \ | (_> < / / | | | | |______| -|_| \__,_| |_||_| |_| \__,_| \_/\_/ |_| |_| \__, | \_/\_/ |_| \_\ \___/\/ /_/ | | | | - __/ / \_\ /_/ - |___/ + _ _ _ _ ______ _ _ _ _____ __ __ __ + _ ( | ) _| || |_ | ____| | | | | | | | __ \ ___ / / / / \ \ ______ +/ | __ _ V V |_ __ _| | |__ __| | __ __ | |__| | _ _ __ __ | |__) | ( _ ) / / | | | | |______| +| | / _` | _| || |_ | __| / _` | \ \ /\ / / | __ | | | | | \ \ /\ / / | _ / / _ \/\ / / | | | | ______ +| | | (_| | |_ __ _| | | | (_| | \ V V / | | | | | |_| | \ V V / | | \ \ | (_> < / / | | | | |______| +|_| \__,_| |_||_| |_| \__,_| \_/\_/ |_| |_| \__, | \_/\_/ |_| \_\ \___/\/ /_/ | | | | + __/ / \_\ /_/ + |___/ ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing `"{|}~"` as argument. + ``` - __ _ __ /\/| - / / | | \ \ |/\/ - | | | | | | -/ / | | \ \ -\ \ | | / / - | | | | | | - \_\ | | /_/ - |_| + __ _ __ /\/| + / / | | \ \ |/\/ + | | | | | | +/ / | | \ \ +\ \ | | / / + | | | | | | + \_\ | | /_/ + |_| ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing `"[\]^_ 'a"` as argument. + ``` - ___ __ ___ /\ _ -| _| \ \ |_ | |/\| ( ) -| | \ \ | | |/ __ _ -| | \ \ | | / _` | -| | \ \ | | | (_| | -| |_ \_\ _| | \__,_| -|___| |___| ______ - |______| + ___ __ ___ /\ _ +| _| \ \ |_ | |/\| ( ) +| | \ \ | | |/ __ _ +| | \ \ | | / _` | +| | \ \ | | | (_| | +| |_ \_\ _| | \__,_| +|___| |___| ______ + |______| ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing `"RGB"` as argument. + ``` - _____ _____ ____ -| __ \ / ____| | _ \ -| |__) | | | __ | |_) | -| _ / | | |_ | | _ < -| | \ \ | |__| | | |_) | -|_| \_\ \_____| |____/ - - + _____ _____ ____ +| __ \ / ____| | _ \ +| |__) | | | __ | |_) | +| _ / | | |_ | | _ < +| | \ \ | |__| | | |_) | +|_| \_\ \_____| |____/ + + ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing `":;<=>?@"` as argument. + ``` - __ __ ___ - _ _ / / ______ \ \ |__ \ ____ -(_) (_) / / |______| \ \ ) | / __ \ - < < ______ > > / / / / _` | - _ _ \ \ |______| / / |_| | | (_| | -(_) ( ) \_\ /_/ (_) \ \__,_| - |/ \____/ - + __ __ ___ + _ _ / / ______ \ \ |__ \ ____ +(_) (_) / / |______| \ \ ) | / __ \ + < < ______ > > / / / / _` | + _ _ \ \ |______| / / |_| | | (_| | +(_) ( ) \_\ /_/ (_) \ \__,_| + |/ \____/ + ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing `"\!\" #$%&'()*+,-./"` as argument. + ``` -__ _ _ _ _ _ _ _ __ _ __ __ _ __ -\ \ | | ( | ) _| || |_ | | (_) / / ___ ( ) / / \ \ /\| |/\ _ / / - \ \ | | V V |_ __ _| / __) / / ( _ ) |/ | | | | \ ` ' / _| |_ ______ / / - \ \ | | _| || |_ \__ \ / / / _ \/\ | | | | |_ _| |_ _| |______| / / - \ \ |_| |_ __ _| ( / / / _ | (_> < | | | | / , . \ |_| _ _ / / - \_\ (_) |_||_| |_| /_/ (_) \___/\/ | | | | \/|_|\/ ( ) (_) /_/ - \_\ /_/ |/ - +__ _ _ _ _ _ _ _ __ _ __ __ _ __ +\ \ | | ( | ) _| || |_ | | (_) / / ___ ( ) / / \ \ /\| |/\ _ / / + \ \ | | V V |_ __ _| / __) / / ( _ ) |/ | | | | \ ` ' / _| |_ ______ / / + \ \ | | _| || |_ \__ \ / / / _ \/\ | | | | |_ _| |_ _| |______| / / + \ \ |_| |_ __ _| ( / / / _ | (_> < | | | | / , . \ |_| _ _ / / + \_\ (_) |_||_| |_| /_/ (_) \___/\/ | | | | \/|_|\/ ( ) (_) /_/ + \_\ /_/ |/ + ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing `"ABCDEFGHIJKLMNOPQRSTUVWXYZ"` as argument. + ``` - ____ _____ _____ ______ ______ _____ _ _ _____ _ _ __ _ __ __ _ _ ____ _____ ____ _____ _____ _______ _ _ __ __ __ __ __ __ __ __ ______ - /\ | _ \ / ____| | __ \ | ____| | ____| / ____| | | | | |_ _| | | | |/ / | | | \/ | | \ | | / __ \ | __ \ / __ \ | __ \ / ____| |__ __| | | | | \ \ / / \ \ / / \ \ / / \ \ / / |___ / - / \ | |_) | | | | | | | | |__ | |__ | | __ | |__| | | | | | | ' / | | | \ / | | \| | | | | | | |__) | | | | | | |__) | | (___ | | | | | | \ \ / / \ \ /\ / / \ V / \ \_/ / / / - / /\ \ | _ < | | | | | | | __| | __| | | |_ | | __ | | | _ | | | < | | | |\/| | | . ` | | | | | | ___/ | | | | | _ / \___ \ | | | | | | \ \/ / \ \/ \/ / > < \ / / / - / ____ \ | |_) | | |____ | |__| | | |____ | | | |__| | | | | | _| |_ | |__| | | . \ | |____ | | | | | |\ | | |__| | | | | |__| | | | \ \ ____) | | | | |__| | \ / \ /\ / / . \ | | / /__ -/_/ \_\ |____/ \_____| |_____/ |______| |_| \_____| |_| |_| |_____| \____/ |_|\_\ |______| |_| |_| |_| \_| \____/ |_| \___\_\ |_| \_\ |_____/ |_| \____/ \/ \/ \/ /_/ \_\ |_| /_____| - - + ____ _____ _____ ______ ______ _____ _ _ _____ _ _ __ _ __ __ _ _ ____ _____ ____ _____ _____ _______ _ _ __ __ __ __ __ __ __ __ ______ + /\ | _ \ / ____| | __ \ | ____| | ____| / ____| | | | | |_ _| | | | |/ / | | | \/ | | \ | | / __ \ | __ \ / __ \ | __ \ / ____| |__ __| | | | | \ \ / / \ \ / / \ \ / / \ \ / / |___ / + / \ | |_) | | | | | | | | |__ | |__ | | __ | |__| | | | | | | ' / | | | \ / | | \| | | | | | | |__) | | | | | | |__) | | (___ | | | | | | \ \ / / \ \ /\ / / \ V / \ \_/ / / / + / /\ \ | _ < | | | | | | | __| | __| | | |_ | | __ | | | _ | | | < | | | |\/| | | . ` | | | | | | ___/ | | | | | _ / \___ \ | | | | | | \ \/ / \ \/ \/ / > < \ / / / + / ____ \ | |_) | | |____ | |__| | | |____ | | | |__| | | | | | _| |_ | |__| | | . \ | |____ | | | | | |\ | | |__| | | | | |__| | | | \ \ ____) | | | | |__| | \ / \ /\ / / . \ | | / /__ +/_/ \_\ |____/ \_____| |_____/ |______| |_| \_____| |_| |_| |_____| \____/ |_|\_\ |______| |_| |_| |_| \_| \____/ |_| \___\_\ |_| \_\ |_____/ |_| \____/ \/ \/ \/ /_/ \_\ |_| /_____| + + ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing `"abcdefghijklmnopqrstuvwxyz"` as argument. + ``` - _ _ __ _ _ _ _ _ - | | | | / _| __ _ | | (_) (_) _ | | | | - __ _ | |__ ___ __| | ___ | |_ / _` | | |__ _ _ | | _ | | _ __ ___ _ __ ___ _ __ __ _ _ __ ___ | |_ _ _ __ __ __ __ __ __ _ _ ____ - / _` | | '_ \ / __| / _` | / _ \ | _| | (_| | | _ \ | | | | | |/ / | | | '_ ` _ \ | '_ \ / _ \ | '_ \ / _` | | '__| / __| | __| | | | | \ \ / / \ \ /\ / / \ \/ / | | | | |_ / -| (_| | | |_) | | (__ | (_| | | __/ | | \__, | | | | | | | | | | < | | | | | | | | | | | | | (_) | | |_) | | (_| | | | \__ \ \ |_ | |_| | \ V / \ V V / > < | |_| | / / - \__,_| |_.__/ \___| \__,_| \___| |_| __/ | |_| |_| |_| | | |_|\_\ |_| |_| |_| |_| |_| |_| \___/ | .__/ \__, | |_| |___/ \__| \__,_| \_/ \_/\_/ /_/\_\ \__, | /___| - |___/ _/ | | | | | __/ / - |__/ |_| |_| |___/ + _ _ __ _ _ _ _ _ + | | | | / _| __ _ | | (_) (_) _ | | | | + __ _ | |__ ___ __| | ___ | |_ / _` | | |__ _ _ | | _ | | _ __ ___ _ __ ___ _ __ __ _ _ __ ___ | |_ _ _ __ __ __ __ __ __ _ _ ____ + / _` | | '_ \ / __| / _` | / _ \ | _| | (_| | | _ \ | | | | | |/ / | | | '_ ` _ \ | '_ \ / _ \ | '_ \ / _` | | '__| / __| | __| | | | | \ \ / / \ \ /\ / / \ \/ / | | | | |_ / +| (_| | | |_) | | (__ | (_| | | __/ | | \__, | | | | | | | | | | < | | | | | | | | | | | | | (_) | | |_) | | (_| | | | \__ \ \ |_ | |_| | \ V / \ V V / > < | |_| | / / + \__,_| |_.__/ \___| \__,_| \___| |_| __/ | |_| |_| |_| | | |_|\_\ |_| |_| |_| |_| |_| |_| \___/ | .__/ \__, | |_| |___/ \__| \__,_| \_/ \_/\_/ /_/\_\ \__, | /___| + |___/ _/ | | | | | __/ / + |__/ |_| |_| |___/ ``` + ###### Does it display the right graphical representation in ASCII as above? ##### Try passing `` with at least four lower case letters and three upper case letters. + ###### Does it display the right graphical representation in ASCII as expected? ##### Try passing `` with at least five lower case letters, a space and two numbers. + ###### Does it display the right graphical representation in ASCII as expected? ##### Try passing `` with at least one upper case letters and 3 special characters. + ###### Does it display the right graphical representation in ASCII as expected? ##### Try passing `` with at least two lower case letters, two spaces, one number, two special characters and three upper case letters. + ###### Does it display the right graphical representation in ASCII as expected? #### Basic diff --git a/subjects/ascii-art/ascii-art.en.md b/subjects/ascii-art/ascii-art.en.md index 506759b2..0bdcd878 100644 --- a/subjects/ascii-art/ascii-art.en.md +++ b/subjects/ascii-art/ascii-art.en.md @@ -71,49 +71,49 @@ etc ```console student@ubuntu:~/ascii-art$ go build student@ubuntu:~/ascii-art$ ./ascii-art "hello" - _ _ _ - | | | | | | - | |__ ___ | | | | ___ - | _ \ / _ \ | | | | / _ \ - | | | | | __/ | | | | | (_) | - |_| |_| \___| |_| |_| \___/ - - + _ _ _ + | | | | | | + | |__ ___ | | | | ___ + | _ \ / _ \ | | | | / _ \ + | | | | | __/ | | | | | (_) | + |_| |_| \___| |_| |_| \___/ + + student@ubuntu:~/ascii-art$ ./ascii-art "HeLlO" - _ _ _ _ ____ - | | | | | | | | / __ \ - | |__| | ___ | | | | | | | | - | __ | / _ \ | | | | | | | | - | | | | | __/ | |____ | | | |__| | - |_| |_| \___| |______| |_| \____/ - - + _ _ _ _ ____ + | | | | | | | | / __ \ + | |__| | ___ | | | | | | | | + | __ | / _ \ | | | | | | | | + | | | | | __/ | |____ | | | |__| | + |_| |_| \___| |______| |_| \____/ + + student@ubuntu:~/ascii-art$ ./ascii-art "Hello There" - _ _ _ _ _______ _ - | | | | | | | | |__ __| | | - | |__| | ___ | | | | ___ | | | |__ ___ _ __ ___ - | __ | / _ \ | | | | / _ \ | | | _ \ / _ \ | '__| / _ \ - | | | | | __/ | | | | | (_) | | | | | | | | __/ | | | __/ - |_| |_| \___| |_| |_| \___/ |_| |_| |_| \___| |_| \___| - - + _ _ _ _ _______ _ + | | | | | | | | |__ __| | | + | |__| | ___ | | | | ___ | | | |__ ___ _ __ ___ + | __ | / _ \ | | | | / _ \ | | | _ \ / _ \ | '__| / _ \ + | | | | | __/ | | | | | (_) | | | | | | | | __/ | | | __/ + |_| |_| \___| |_| |_| \___/ |_| |_| |_| \___| |_| \___| + + student@ubuntu:~/ascii-art$ ./ascii-art "1Hello 2There" - _ _ _ _ _______ _ - _ | | | | | | | | ____ |__ __| | | -/ | | |__| | ___ | | | | ___ |___ \ | | | |__ ___ _ __ ___ -| | | __ | / _ \ | | | | / _ \ __) | | | | _ \ / _ \ | '__| / _ \ -| | | | | | | __/ | | | | | (_) | / __/ | | | | | | | __/ | | | __/ -|_| |_| |_| \___| |_| |_| \___/ |_____| |_| |_| |_| \___| |_| \___| - - + _ _ _ _ _______ _ + _ | | | | | | | | ____ |__ __| | | +/ | | |__| | ___ | | | | ___ |___ \ | | | |__ ___ _ __ ___ +| | | __ | / _ \ | | | | / _ \ __) | | | | _ \ / _ \ | '__| / _ \ +| | | | | | | __/ | | | | | (_) | / __/ | | | | | | | __/ | | | __/ +|_| |_| |_| \___| |_| |_| \___/ |_____| |_| |_| |_| \___| |_| \___| + + student@ubuntu:~/ascii-art$ ./ascii-art "{Hello There}" - __ _ _ _ _ _______ _ __ - / / | | | | | | | | |__ __| | | \ \ - | | | |__| | ___ | | | | ___ | | | |__ ___ _ __ ___ | | -/ / | __ | / _ \ | | | | / _ \ | | | _ \ / _ \ | '__| / _ \ \ \ -\ \ | | | | | __/ | | | | | (_) | | | | | | | | __/ | | | __/ / / - | | |_| |_| \___| |_| |_| \___/ |_| |_| |_| \___| |_| \___| | | - \_\ /_/ - + __ _ _ _ _ _______ _ __ + / / | | | | | | | | |__ __| | | \ \ + | | | |__| | ___ | | | | ___ | | | |__ ___ _ __ ___ | | +/ / | __ | / _ \ | | | | / _ \ | | | _ \ / _ \ | '__| / _ \ \ \ +\ \ | | | | | __/ | | | | | (_) | | | | | | | | __/ | | | __/ / / + | | |_| |_| \___| |_| |_| \___/ |_| |_| |_| \___| |_| \___| | | + \_\ /_/ + student@ubuntu:~/ascii-art$ ``` diff --git a/subjects/atoibaseprog.en.md b/subjects/atoibaseprog.en.md index 4154ffc9..0719f94b 100644 --- a/subjects/atoibaseprog.en.md +++ b/subjects/atoibaseprog.en.md @@ -1,16 +1,5 @@ ## atoibaseprog -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function that takes a `string` number and its `string` base in parameters and returns its conversion as an `int`. @@ -42,9 +31,7 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { fmt.Println(AtoiBase("125", "0123456789")) diff --git a/subjects/atoiprog.en.md b/subjects/atoiprog.en.md index d94818c0..08277d95 100644 --- a/subjects/atoiprog.en.md +++ b/subjects/atoiprog.en.md @@ -1,16 +1,5 @@ ## atoiprog -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions - Write a function that simulates the behaviour of the `Atoi` function in Go. `Atoi` transforms a number represented as a `string` in a number represented as an `int`. @@ -36,9 +25,7 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { s := "12345" diff --git a/subjects/basicatoi.en.md b/subjects/basicatoi.en.md index 6fcca0fc..6103921d 100644 --- a/subjects/basicatoi.en.md +++ b/subjects/basicatoi.en.md @@ -2,13 +2,13 @@ ### Instructions -- Write a function that simulates the behaviour of the atoi function in Go. Atoi transforms a number defined as a `string` in a number defined as an `int`. +- Write a function that simulates the behaviour of the `Atoi` function in Go. `Atoi` transforms a number defined as a `string` in a number defined as an `int`. -- Atoi returns `0` if the `string` is not considered as a valid number. For this exercise **only valid** `string` chains will be tested. They will only contain one or several digits as characters. +- Atoi returns `0` if the `string` is not considered as a valid number. For this exercise **only valid** `string` will be tested. They will only contain one or several digits as characters. - For this exercise the handling of the signs `+` or `-` does not have to be taken into account. -- This function will **only** have to return the `int`. For this exercise the `error` return of atoi is not required. +- This function will **only** have to return the `int`. For this exercise the `error` return of `Atoi` is not required. ### Expected function diff --git a/subjects/basicatoi2.en.md b/subjects/basicatoi2.en.md index 78a812f5..52059879 100644 --- a/subjects/basicatoi2.en.md +++ b/subjects/basicatoi2.en.md @@ -2,7 +2,7 @@ ### Instructions -- Write a function that simulates the behaviour of the atoi function in Go. Atoi transforms a number defined as a `string` in a number defined as an `int`. +- Write a function that simulates the behaviour of the `Atoi` function in Go. `Atoi` transforms a number defined as a `string` in a number defined as an `int`. - Atoi returns `0` if the `string` is not considered as a valid number. For this exercise **non-valid `string` chains will be tested**. Some will contain non-digits characters. diff --git a/subjects/basicjoin.en.md b/subjects/basicjoin.en.md index f0410446..db3b26b2 100644 --- a/subjects/basicjoin.en.md +++ b/subjects/basicjoin.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function that returns the concatenation of all the `string` of a table of `string` passed in argument. +Write a function that returns the concatenation of all the `string` of a slice of `string` passed in argument. ### Expected function diff --git a/subjects/boolean.en.md b/subjects/boolean.en.md index cff70f99..95407d9c 100644 --- a/subjects/boolean.en.md +++ b/subjects/boolean.en.md @@ -13,11 +13,9 @@ Create a `.go` file. ### Code to be copied ```go -func printStr(str string) { - arrayStr := []rune(str) - - for i := 0; i < len(arrayStr); i++ { - z01.PrintRune(arrayStr[i]) +func printStr(s string) { + for _, r := range s { + z01.PrintRune(r) } z01.PrintRune('\n') } diff --git a/subjects/brackets.en.md b/subjects/brackets.en.md index 9f41405b..0a87f0a5 100644 --- a/subjects/brackets.en.md +++ b/subjects/brackets.en.md @@ -8,7 +8,7 @@ Symbols considered as brackets are parentheses `(` and `)`, square brackets `[` An opening bracket must always be closed by the good closing bracket in the correct order. A `string` which does not contain any bracket is considered as a correctly bracketed `string`. -If there is no argument, the program must print only a newline. +If there is no argument, the program must print nothing. ### Usage @@ -21,7 +21,6 @@ Error$ student@ubuntu:~/[[ROOT]]/brackets$ ./brackets '' '{[(0 + 0)(1 + 1)](3*(-1)){()}}' | cat -e OK$ OK$ -student@ubuntu:~/[[ROOT]]/brackets$ ./brackets | cat -e -$ +student@ubuntu:~/[[ROOT]]/brackets$ ./brackets student@ubuntu:~/[[ROOT]]/brackets$ ``` diff --git a/subjects/btreeprintroot.en.md b/subjects/btreeprintroot.en.md index 91872c95..374054fe 100644 --- a/subjects/btreeprintroot.en.md +++ b/subjects/btreeprintroot.en.md @@ -26,9 +26,9 @@ Here is a possible program to test your function : package main func main() { - //rootNode initialized with the value "who" - //rootNode1 initialized with the value "are" - //rootNode2 initialized with the value "you" + // rootNode initialized with the value "who" + // rootNode1 initialized with the value "are" + // rootNode2 initialized with the value "you" printRoot(rootNode) printRoot(rootNode1) printRoot(rootNode2) diff --git a/subjects/capitalizeprog.en.md b/subjects/capitalizeprog.en.md index 0151c867..232b53fc 100644 --- a/subjects/capitalizeprog.en.md +++ b/subjects/capitalizeprog.en.md @@ -8,7 +8,7 @@ Write a program that capitalizes the first letter of each word **and** lowercase - If there is more than one argument the program should print `Too many arguments`. -- If there is no arguments given the program should print a newline ("`\n`"). +- If there is no arguments given the program should print nothing. ### Usage : @@ -19,6 +19,5 @@ Hello! How Are You? How+Are+Things+4you?$ student@ubuntu:~/capitalizeprog$ ./capitalizeprog Hello! How are you? | cat -e Too many arguments$ student@ubuntu:~/capitalizeprog$ ./capitalizeprog - student@ubuntu:~/capitalizeprog$ ``` diff --git a/subjects/changeorder.en.md b/subjects/changeorder.en.md index 0d5e82c3..c05a8e73 100644 --- a/subjects/changeorder.en.md +++ b/subjects/changeorder.en.md @@ -1,21 +1,9 @@ ## changeorder -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testing are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions You are given a linked list, where each node contains a single digit. -Change order of linked list so that elements with odd index come first, elements -with even index come afterwards. +Change order of linked list so that elements with odd index come first, elements with even index come afterwards. You have to return pointer/reference to the beginning of new list ### Expected function and structure @@ -40,9 +28,7 @@ Here is a possible program to test your function: ```go package main -import ( - "fmt" -) +import "fmt" // I implemented pushBack for this diff --git a/subjects/chunk.en.md b/subjects/chunk.en.md index 743ff78f..913c9f06 100644 --- a/subjects/chunk.en.md +++ b/subjects/chunk.en.md @@ -1,16 +1,5 @@ ## chunk -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function called `Chunk` that receives as parameters a slice, `slice []int`, and an number `size int`. The goal of this function is to chunk a slice into many sub slices where each sub slice has the length of `size`. diff --git a/subjects/cleanstr.en.md b/subjects/cleanstr.en.md index 1cf0283d..cfce6779 100644 --- a/subjects/cleanstr.en.md +++ b/subjects/cleanstr.en.md @@ -12,7 +12,7 @@ A "word" is defined as a part of a `string` delimited either by spaces/tabs, or by the start/end of the `string`. If the number of arguments is not 1, or if there are no words to display, the -program displays a newline ("`\n`"). +program displays nothing. ### Usage : @@ -24,7 +24,6 @@ student@ubuntu:~/[[ROOT]]/cleanstr$ ./cleanstr " only it's harder " only it's harder$ student@ubuntu:~/[[ROOT]]/cleanstr$ ./cleanstr " how funny" "Did you hear Mathilde ?" $ -student@ubuntu:~/[[ROOT]]/cleanstr$ ./cleanstr "" | cat -e -$ +student@ubuntu:~/[[ROOT]]/cleanstr$ ./cleanstr "" student@ubuntu:~/[[ROOT]]/cleanstr$ ``` diff --git a/subjects/compact.en.md b/subjects/compact.en.md index 51b4527e..67056c7a 100644 --- a/subjects/compact.en.md +++ b/subjects/compact.en.md @@ -2,12 +2,12 @@ ### Instructions -Write a function `Compact` that takes a pointer to a slice of strings as the argument. +Write a function `Compact` that takes a pointer to a slice of `string` as the argument. This function must: -- Return the number of elements with non-`nil`. +- Return the number of elements with non-zero value. -- Compact, i.e., delete the elements with `nil` in the slice. +- Compact, i.e., delete the elements with zero-values in the slice. ### Expected functions @@ -33,18 +33,18 @@ import ( const N = 6 func main() { - arr := make([]string, N) - arr[0] = "a" - arr[2] = "b" - arr[4] = "c" + a := make([]string, N) + a[0] = "a" + a[2] = "b" + a[4] = "c" - for _, v := range arr { + for _, v := range a { fmt.Println(v) } - fmt.Println("Size after compacting:", piscine.Compact(&arr)) + fmt.Println("Size after compacting:", piscine.Compact(&a)) - for _, v := range arr { + for _, v := range a { fmt.Println(v) } } diff --git a/subjects/concatparams.en.md b/subjects/concatparams.en.md index 62f28732..65b9756c 100644 --- a/subjects/concatparams.en.md +++ b/subjects/concatparams.en.md @@ -3,8 +3,7 @@ ### Instructions Write a function that takes the arguments received in parameters and returns them as a `string`. - -The arguments must be **separated** by a `\n`. +The `string` is the result of all the arguments concatenated with a newline (`\n`) between. ### Expected function diff --git a/subjects/costumeprofit.en.md b/subjects/costumeprofit.en.md index e2c6ada5..057d9e94 100644 --- a/subjects/costumeprofit.en.md +++ b/subjects/costumeprofit.en.md @@ -19,6 +19,6 @@ In the output put '\n' at the end. Input: `./main **a** **b** **c** **d** **e** **f**` ```console -$> ./main 12 11 13 20 4 6 +$ ./main 12 11 13 20 4 6 102 ``` diff --git a/subjects/countif.en.md b/subjects/countif.en.md index 05e84754..2d7630c8 100644 --- a/subjects/countif.en.md +++ b/subjects/countif.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function `CountIf` that returns the number of elements of a `string` array for which the `f` function returns `true`. +Write a function `CountIf` that returns the number of elements of a `string` slice for which the `f` function returns `true`. ### Expected function diff --git a/subjects/displaya.en.md b/subjects/displaya.en.md index d046e9c1..41a393d9 100644 --- a/subjects/displaya.en.md +++ b/subjects/displaya.en.md @@ -2,10 +2,9 @@ ### Instructions -Write a program that takes a `string`, and displays the first `a` character it -encounters in it, followed by a newline (`'\n'`). If there are no `a` characters in the -string, the program just writes `a` followed by a newline (`'\n'`). If the number of parameters is not -1, the program displays an `a` followed by a newline (`'\n'`). +Write a program that takes a `string`, and displays the first `a` character it encounters in it, followed by a newline (`'\n'`). +If there are no `a` characters in the string, the program just writes `a` followed by a newline (`'\n'`). +If the number of parameters is not 1, the program displays an `a` followed by a newline (`'\n'`). ### Usage diff --git a/subjects/displayalpham.en.md b/subjects/displayalpham.en.md index 69ea26e9..2f6a30b9 100644 --- a/subjects/displayalpham.en.md +++ b/subjects/displayalpham.en.md @@ -2,8 +2,7 @@ ### Instructions -Write a program that displays the alphabet, with even letters in uppercase, and -odd letters in lowercase, followed by a newline (`'\n'`). +Write a program that displays the alphabet, with even letters in uppercase, and odd letters in lowercase, followed by a newline (`'\n'`). ### Usage diff --git a/subjects/displayalrevm.en.md b/subjects/displayalrevm.en.md index 18b2da02..08238da0 100644 --- a/subjects/displayalrevm.en.md +++ b/subjects/displayalrevm.en.md @@ -2,8 +2,7 @@ ### Instructions -Write a program that displays the alphabet in reverse, with even letters in -uppercase, and odd letters in lowercase, followed by a newline (`'\n'`). +Write a program that displays the alphabet in reverse, with even letters in uppercase, and odd letters in lowercase, followed by a newline (`'\n'`). ### Usage diff --git a/subjects/displayz.en.md b/subjects/displayz.en.md index fb4d9863..46fef229 100644 --- a/subjects/displayz.en.md +++ b/subjects/displayz.en.md @@ -2,7 +2,9 @@ ### Instructions -Write a program that takes a `string`, and displays the first `z` character it encounters in it, followed by a newline (`'\n'`). If there are no `z` characters in the string, the program just writes `z` followed by a newline (`'\n'`). If the number of parameters is not 1, the program displays an `z` followed by a newline (`'\n'`). +Write a program that takes a `string`, and displays the first `z` character it encounters in it, followed by a newline (`'\n'`). +If there are no `z` characters in the string, the program just writes `z` followed by a newline (`'\n'`). +If the number of parameters is not 1, the program displays an `z` followed by a newline (`'\n'`). ### Usage diff --git a/subjects/doppelgangerprog.en.md b/subjects/doppelgangerprog.en.md index 1c7ec1b4..5ba026ac 100644 --- a/subjects/doppelgangerprog.en.md +++ b/subjects/doppelgangerprog.en.md @@ -1,16 +1,5 @@ ## doppelganger -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions You are given 2 strings. Find out if first string contains second string. If it does, return index of the first string where second string occurs last time. If it does not contain, return "-1" @@ -20,7 +9,7 @@ You are given 2 strings. Find out if first string contains second string. If it ```go package main -func DoppelGanger(big, little string) int { +func DoppelGanger(s, substr string) int { } ``` @@ -28,9 +17,7 @@ func DoppelGanger(big, little string) int { ```go package main -import ( - "fmt" -) +import "fmt" func main() { var result int diff --git a/subjects/expandstr.en.md b/subjects/expandstr.en.md index cad98858..847864a4 100644 --- a/subjects/expandstr.en.md +++ b/subjects/expandstr.en.md @@ -2,15 +2,13 @@ ### Instructions -Write a program that takes a `string` and displays it with exactly three spaces -between each word, with no spaces or tabs at either the beginning nor the end. +Write a program that takes a `string` and displays it with exactly three spaces between each word, with no spaces or tabs at either the beginning nor the end. The `string` will be followed by a newline (`'\n'`). A word is a sequence of alphanumerical characters. -If the number of parameters is not 1, or if there are no word, the program displays -a newline. +If the number of parameters is not 1, or if there are no word, the program displays nothing. ### Usage @@ -22,7 +20,6 @@ student@ubuntu:~/[[ROOT]]/expandstr$ ./expandstr " only it's harder " | cat only it's harder$ student@ubuntu:~/[[ROOT]]/expandstr$ ./expandstr " how funny it is" "did you hear, Mathilde ?" | cat -e $ -student@ubuntu:~/[[ROOT]]/expandstr$ ./expandstr | cat -e -$ +student@ubuntu:~/[[ROOT]]/expandstr$ ./expandstr student@ubuntu:~/[[ROOT]]/expandstr$ ``` diff --git a/subjects/fib.en.md b/subjects/fib.en.md index d8452bf1..1130492f 100644 --- a/subjects/fib.en.md +++ b/subjects/fib.en.md @@ -1,16 +1,5 @@ ## fib -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). @@ -37,9 +26,7 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { fmt.Println(Fib(0)) diff --git a/subjects/findprevprimeprog.en.md b/subjects/findprevprimeprog.en.md index 1d134f76..08643fac 100644 --- a/subjects/findprevprimeprog.en.md +++ b/subjects/findprevprimeprog.en.md @@ -1,16 +1,5 @@ ## findprevprime -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(\`\`\`func main()\`\`\`) even if empty. -- The function main declared needs to **also pass** the \`Restrictions Checker\`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a \`program\`. - ### Instructions Write a function that returns the first prime number that is equal or inferior to the `int` passed as parameter. @@ -32,9 +21,7 @@ Here is a possible [program](TODO-LINK) to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { fmt.Println(FindPrevPrime(5)) diff --git a/subjects/firstruneprog.en.md b/subjects/firstruneprog.en.md index 7b2e736e..96fb3ca6 100644 --- a/subjects/firstruneprog.en.md +++ b/subjects/firstruneprog.en.md @@ -1,16 +1,5 @@ ## firstruneprog -> ### **WARNING! VERY IMPORTANT!** -> -> For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function that returns the first `rune` of a `string`. diff --git a/subjects/firstword.en.md b/subjects/firstword.en.md index 06a5df88..59565629 100644 --- a/subjects/firstword.en.md +++ b/subjects/firstword.en.md @@ -8,7 +8,7 @@ Write a program that takes a `string` and displays its first word, followed by a - The output will be followed by a newline (`'\n'`). -- If the number of parameters is not 1, or if there are no words, the program displays a newline (`'\n'`). +- If the number of parameters is not 1, or if there are no words, the program displays nothing. ### Usage @@ -19,8 +19,6 @@ hello student@ubuntu:~/[[ROOT]]/test$ ./test "hello ......... bye" hello student@ubuntu:~/[[ROOT]]/test$ ./test - student@ubuntu:~/[[ROOT]]/test$ ./test "hello" "there" - student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/fixthemain.en.md b/subjects/fixthemain.en.md index fab6b377..6f774d31 100644 --- a/subjects/fixthemain.en.md +++ b/subjects/fixthemain.en.md @@ -10,9 +10,8 @@ Fix the following program. package piscine func PrintStr(str string) { - arrayRune := []rune(str) - for _, s := range arrayRune { - z01.PrintRune(s) + for _, r := range str { + z01.PrintRune(r) } } diff --git a/subjects/foldint.en.md b/subjects/foldint.en.md index 6534de33..4927e3f8 100644 --- a/subjects/foldint.en.md +++ b/subjects/foldint.en.md @@ -1,16 +1,5 @@ ## foldint -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker\`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function called `FoldInt` that simulates the behavior of reduce from JavaScript. @@ -20,7 +9,7 @@ The function should have as parameters a function, `f func(int, int) int` a slic ### Expected function ```go -func FoldInt(f func(int, int) int, arr []int, n int) { +func FoldInt(f func(int, int) int, a []int, n int) { } ``` diff --git a/subjects/foreach.en.md b/subjects/foreach.en.md index afd1a34d..9d868445 100644 --- a/subjects/foreach.en.md +++ b/subjects/foreach.en.md @@ -2,12 +2,12 @@ ### Instructions -Write a function `ForEach` that, for an `int` array, applies a function on each elements of that array. +Write a function `ForEach` that, for an `int` slice, applies a function on each elements of that slice. ### Expected function ```go -func ForEach(f func(int), arr []int) { +func ForEach(f func(int), a []int) { } ``` @@ -22,8 +22,8 @@ package main import piscine ".." func main() { - arr := []int{1, 2, 3, 4, 5, 6} - piscine.ForEach(piscine.PrintNbr, arr) + a := []int{1, 2, 3, 4, 5, 6} + piscine.ForEach(piscine.PrintNbr, a) } ``` diff --git a/subjects/foreachprog.en.md b/subjects/foreachprog.en.md index 2ad28aac..60254263 100644 --- a/subjects/foreachprog.en.md +++ b/subjects/foreachprog.en.md @@ -1,24 +1,13 @@ ## foreachprog -##**WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions -Write a function `ForEach` that, for an `int` array, applies a function on each elements of that array. +Write a function `ForEach` that, for an `int` slice, applies a function on each elements of that slice. ### Expected function ```go -func ForEach(f func(int), arr []int) { +func ForEach(f func(int), a []int) { } ``` @@ -31,8 +20,8 @@ Here is a possible program to test your function : package main func main() { - arr := []int{1, 2, 3, 4, 5, 6} - ForEach(PrintNbr, arr) + a := []int{1, 2, 3, 4, 5, 6} + ForEach(PrintNbr, a) } func PrintNbr(int) { diff --git a/subjects/fprime.en.md b/subjects/fprime.en.md index db2c2a60..406d0325 100644 --- a/subjects/fprime.en.md +++ b/subjects/fprime.en.md @@ -6,9 +6,7 @@ Write a program that takes a positive `int` and displays its prime factors, foll - Factors must be displayed in ascending order and separated by `*`. -- If the number of parameters is different from 1, the program displays a newline. - -- The input, when there is one, will always be valid. +- If the number of arguments is different from 1, if the argument is invalid or if the integer doesn't have a prime factor, the program displays nothing. ### Usage @@ -25,10 +23,7 @@ student@ubuntu:~/[[ROOT]]/test$ ./test 804577 student@ubuntu:~/[[ROOT]]/test$ ./test 42 2*3*7 student@ubuntu:~/[[ROOT]]/test$ ./test a - student@ubuntu:~/[[ROOT]]/test$ ./test 0 - student@ubuntu:~/[[ROOT]]/test$ ./test 1 - student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/game23.en.md b/subjects/game23.en.md index 3482e53c..23c7cba4 100644 --- a/subjects/game23.en.md +++ b/subjects/game23.en.md @@ -1,16 +1,5 @@ ## game23 -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). @@ -35,9 +24,7 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { fmt.Println(Game23(1, 3)) diff --git a/subjects/gcd.en.md b/subjects/gcd.en.md index 98a1b6a7..44ebe08a 100644 --- a/subjects/gcd.en.md +++ b/subjects/gcd.en.md @@ -6,7 +6,7 @@ Write a program that takes two `string` representing two strictly positive integ The program displays their greatest common divisor followed by a newline (`'\n'`). -If the number of parameters is different from 2, the program displays a newline. +If the number of parameters is different from 2, the program displays nothing. All arguments tested will be positive `int` values. @@ -16,15 +16,13 @@ All arguments tested will be positive `int` values. student@ubuntu:~/[[ROOT]]/gcd$ go build student@ubuntu:~/[[ROOT]]/gcd$ ./gcd 42 10 | cat -e 2$ -student@ubuntu:~/[[ROOT]]/gcd$ ./gcd 42 12 | cat -e -6$ -student@ubuntu:~/[[ROOT]]/gcd$ ./gcd 14 77 | cat -e -7$ -student@ubuntu:~/[[ROOT]]/gcd$ ./gcd 17 3 | cat -e -1$ -student@ubuntu:~/[[ROOT]]/gcd$ ./gcd | cat -e -$ -student@ubuntu:~/[[ROOT]]/gcd$ ./gcd 50 12 4 | cat -e -$ +student@ubuntu:~/[[ROOT]]/gcd$ ./gcd 42 12 +6 +student@ubuntu:~/[[ROOT]]/gcd$ ./gcd 14 77 +7 +student@ubuntu:~/[[ROOT]]/gcd$ ./gcd 17 3 +1 +student@ubuntu:~/[[ROOT]]/gcd$ ./gcd +student@ubuntu:~/[[ROOT]]/gcd$ ./gcd 50 12 4 student@ubuntu:~/[[ROOT]]/gcd$ ``` diff --git a/subjects/go-reloaded/go-reloaded.audit.en.md b/subjects/go-reloaded/go-reloaded.audit.en.md index 41474c0d..f10a5e1d 100644 --- a/subjects/go-reloaded/go-reloaded.audit.en.md +++ b/subjects/go-reloaded/go-reloaded.audit.en.md @@ -1,433 +1,767 @@ #### Atoi ##### Try with the argument: `""` + `0` + ###### Does the function returns the value above? + ##### Try with the argument: `"-"` + `0` + ###### Does the function returns the value above? + ##### Try with the argument: `"--123"` + `0` + ###### Does the function returns the value above? + ##### Try with the argument: `"1"` + `1` + ###### Does the function returns the value above? + ##### Try with the argument: `"-3"` + `-3` + ###### Does the function returns the value above? + ##### Try with the argument: `"8292"` + `8292` + ###### Does the function returns the value above? + ##### Try with the argument: `"9223372036854775807"` + `9223372036854775807` + ###### Does the function returns the value above? + ##### Try with the argument: `"-9223372036854775808"` + `-9223372036854775808` + ###### Does the function returns the value above? #### RecursivePower ##### Try with the arguments: `nb = -7 and power = -2` + `0` + ###### Does the function returns the value above? + ##### Try with the arguments: `nb = -8 and power = -7` + `0` + ###### Does the function returns the value above? + ##### Try with the arguments: `nb = 4 and power = 8` + `65536` + ###### Does the function returns the value above? + ##### Try with the arguments: `nb = 1 and power = 3` + `1` + ###### Does the function returns the value above? + ##### Try with the arguments: `nb = -1 and power = 1` + `-1` + ###### Does the function returns the value above? + ##### Try with the arguments: `nb = -6 and power = 5` + `-7776` + ###### Does the function returns the value above? #### PrintCombN ##### Try with the argument: `n = 1` + `0, 1, 2, 3, 4, 5, 6, 7, 8, 9` + ###### Does the function prints the value above? + ##### Try with the argument: `n = 2` + `01, 02, 03, 04, 05, 06, 07, 08, 09, 12, 13, 14, 15, 16, 17, 18, 19, 23, 24, 25, 26, 27, 28, 29, 34, 35, 36, 37, 38, 39, 45, 46, 47, 48, 49, 56, 57, 58, 59, 67, 68, 69, 78, 79, 89` + ###### Does the function prints the value above? + ##### Try with the argument: `n = 3` + `012, 013, 014, 015, 016, 017, 018, 019, 023, 024, 025, 026, 027, 028, 029, 034, 035, 036, 037, 038, 039, 045, 046, 047, 048, 049, 056, 057, 058, 059, 067, 068, 069, 078, 079, 089, 123, 124, 125, 126, 127, 128, 129, 134, 135, 136, 137, 138, 139, 145, 146, 147, 148, 149, 156, 157, 158, 159, 167, 168, 169, 178, 179, 189, 234, 235, 236, 237, 238, 239, 245, 246, 247, 248, 249, 256, 257, 258, 259, 267, 268, 269, 278, 279, 289, 345, 346, 347, 348, 349, 356, 357, 358, 359, 367, 368, 369, 378, 379, 389, 456, 457, 458, 459, 467, 468, 469, 478, 479, 489, 567, 568, 569, 578, 579, 589, 678, 679, 689, 789` + ###### Does the function prints the value above? + ##### Try with the argument: `n = 4` + `0123, 0124, 0125, 0126, 0127, 0128, 0129, 0134, 0135, 0136, 0137, 0138, 0139, 0145, 0146, 0147, 0148, 0149, 0156, 0157, 0158, 0159, 0167, 0168, 0169, 0178, 0179, 0189, 0234, 0235, 0236, 0237, 0238, 0239, 0245, 0246, 0247, 0248, 0249, 0256, 0257, 0258, 0259, 0267, 0268, 0269, 0278, 0279, 0289, 0345, 0346, 0347, 0348, 0349, 0356, 0357, 0358, 0359, 0367, 0368, 0369, 0378, 0379, 0389, 0456, 0457, 0458, 0459, 0467, 0468, 0469, 0478, 0479, 0489, 0567, 0568, 0569, 0578, 0579, 0589, 0678, 0679, 0689, 0789, 1234, 1235, 1236, 1237, 1238, 1239, 1245, 1246, 1247, 1248, 1249, 1256, 1257, 1258, 1259, 1267, 1268, 1269, 1278, 1279, 1289, 1345, 1346, 1347, 1348, 1349, 1356, 1357, 1358, 1359, 1367, 1368, 1369, 1378, 1379, 1389, 1456, 1457, 1458, 1459, 1467, 1468, 1469, 1478, 1479, 1489, 1567, 1568, 1569, 1578, 1579, 1589, 1678, 1679, 1689, 1789, 2345, 2346, 2347, 2348, 2349, 2356, 2357, 2358, 2359, 2367, 2368, 2369, 2378, 2379, 2389, 2456, 2457, 2458, 2459, 2467, 2468, 2469, 2478, 2479, 2489, 2567, 2568, 2569, 2578, 2579, 2589, 2678, 2679, 2689, 2789, 3456, 3457, 3458, 3459, 3467, 3468, 3469, 3478, 3479, 3489, 3567, 3568, 3569, 3578, 3579, 3589, 3678, 3679, 3689, 3789, 4567, 4568, 4569, 4578, 4579, 4589, 4678, 4679, 4689, 4789, 5678, 5679, 5689, 5789, 6789` + ###### Does the function prints the value above? + ##### Try with the argument: `n = 5` + `01234, 01235, 01236, 01237, 01238, 01239, 01245, 01246, 01247, 01248, 01249, 01256, 01257, 01258, 01259, 01267, 01268, 01269, 01278, 01279, 01289, 01345, 01346, 01347, 01348, 01349, 01356, 01357, 01358, 01359, 01367, 01368, 01369, 01378, 01379, 01389, 01456, 01457, 01458, 01459, 01467, 01468, 01469, 01478, 01479, 01489, 01567, 01568, 01569, 01578, 01579, 01589, 01678, 01679, 01689, 01789, 02345, 02346, 02347, 02348, 02349, 02356, 02357, 02358, 02359, 02367, 02368, 02369, 02378, 02379, 02389, 02456, 02457, 02458, 02459, 02467, 02468, 02469, 02478, 02479, 02489, 02567, 02568, 02569, 02578, 02579, 02589, 02678, 02679, 02689, 02789, 03456, 03457, 03458, 03459, 03467, 03468, 03469, 03478, 03479, 03489, 03567, 03568, 03569, 03578, 03579, 03589, 03678, 03679, 03689, 03789, 04567, 04568, 04569, 04578, 04579, 04589, 04678, 04679, 04689, 04789, 05678, 05679, 05689, 05789, 06789, 12345, 12346, 12347, 12348, 12349, 12356, 12357, 12358, 12359, 12367, 12368, 12369, 12378, 12379, 12389, 12456, 12457, 12458, 12459, 12467, 12468, 12469, 12478, 12479, 12489, 12567, 12568, 12569, 12578, 12579, 12589, 12678, 12679, 12689, 12789, 13456, 13457, 13458, 13459, 13467, 13468, 13469, 13478, 13479, 13489, 13567, 13568, 13569, 13578, 13579, 13589, 13678, 13679, 13689, 13789, 14567, 14568, 14569, 14578, 14579, 14589, 14678, 14679, 14689, 14789, 15678, 15679, 15689, 15789, 16789, 23456, 23457, 23458, 23459, 23467, 23468, 23469, 23478, 23479, 23489, 23567, 23568, 23569, 23578, 23579, 23589, 23678, 23679, 23689, 23789, 24567, 24568, 24569, 24578, 24579, 24589, 24678, 24679, 24689, 24789, 25678, 25679, 25689, 25789, 26789, 34567, 34568, 34569, 34578, 34579, 34589, 34678, 34679, 34689, 34789, 35678, 35679, 35689, 35789, 36789, 45678, 45679, 45689, 45789, 46789, 56789` + ###### Does the function prints the value above? + ##### Try with the argument: `n = 6` + `012345, 012346, 012347, 012348, 012349, 012356, 012357, 012358, 012359, 012367, 012368, 012369, 012378, 012379, 012389, 012456, 012457, 012458, 012459, 012467, 012468, 012469, 012478, 012479, 012489, 012567, 012568, 012569, 012578, 012579, 012589, 012678, 012679, 012689, 012789, 013456, 013457, 013458, 013459, 013467, 013468, 013469, 013478, 013479, 013489, 013567, 013568, 013569, 013578, 013579, 013589, 013678, 013679, 013689, 013789, 014567, 014568, 014569, 014578, 014579, 014589, 014678, 014679, 014689, 014789, 015678, 015679, 015689, 015789, 016789, 023456, 023457, 023458, 023459, 023467, 023468, 023469, 023478, 023479, 023489, 023567, 023568, 023569, 023578, 023579, 023589, 023678, 023679, 023689, 023789, 024567, 024568, 024569, 024578, 024579, 024589, 024678, 024679, 024689, 024789, 025678, 025679, 025689, 025789, 026789, 034567, 034568, 034569, 034578, 034579, 034589, 034678, 034679, 034689, 034789, 035678, 035679, 035689, 035789, 036789, 045678, 045679, 045689, 045789, 046789, 056789, 123456, 123457, 123458, 123459, 123467, 123468, 123469, 123478, 123479, 123489, 123567, 123568, 123569, 123578, 123579, 123589, 123678, 123679, 123689, 123789, 124567, 124568, 124569, 124578, 124579, 124589, 124678, 124679, 124689, 124789, 125678, 125679, 125689, 125789, 126789, 134567, 134568, 134569, 134578, 134579, 134589, 134678, 134679, 134689, 134789, 135678, 135679, 135689, 135789, 136789, 145678, 145679, 145689, 145789, 146789, 156789, 234567, 234568, 234569, 234578, 234579, 234589, 234678, 234679, 234689, 234789, 235678, 235679, 235689, 235789, 236789, 245678, 245679, 245689, 245789, 246789, 256789, 345678, 345679, 345689, 345789, 346789, 356789, 456789` + ###### Does the function prints the value above? + ##### Try with the argument: `n = 7` + `0123456, 0123457, 0123458, 0123459, 0123467, 0123468, 0123469, 0123478, 0123479, 0123489, 0123567, 0123568, 0123569, 0123578, 0123579, 0123589, 0123678, 0123679, 0123689, 0123789, 0124567, 0124568, 0124569, 0124578, 0124579, 0124589, 0124678, 0124679, 0124689, 0124789, 0125678, 0125679, 0125689, 0125789, 0126789, 0134567, 0134568, 0134569, 0134578, 0134579, 0134589, 0134678, 0134679, 0134689, 0134789, 0135678, 0135679, 0135689, 0135789, 0136789, 0145678, 0145679, 0145689, 0145789, 0146789, 0156789, 0234567, 0234568, 0234569, 0234578, 0234579, 0234589, 0234678, 0234679, 0234689, 0234789, 0235678, 0235679, 0235689, 0235789, 0236789, 0245678, 0245679, 0245689, 0245789, 0246789, 0256789, 0345678, 0345679, 0345689, 0345789, 0346789, 0356789, 0456789, 1234567, 1234568, 1234569, 1234578, 1234579, 1234589, 1234678, 1234679, 1234689, 1234789, 1235678, 1235679, 1235689, 1235789, 1236789, 1245678, 1245679, 1245689, 1245789, 1246789, 1256789, 1345678, 1345679, 1345689, 1345789, 1346789, 1356789, 1456789, 2345678, 2345679, 2345689, 2345789, 2346789, 2356789, 2456789, 3456789` + ###### Does the function prints the value above? + ##### Try with the argument: `n = 8` + `01234567, 01234568, 01234569, 01234578, 01234579, 01234589, 01234678, 01234679, 01234689, 01234789, 01235678, 01235679, 01235689, 01235789, 01236789, 01245678, 01245679, 01245689, 01245789, 01246789, 01256789, 01345678, 01345679, 01345689, 01345789, 01346789, 01356789, 01456789, 02345678, 02345679, 02345689, 02345789, 02346789, 02356789, 02456789, 03456789, 12345678, 12345679, 12345689, 12345789, 12346789, 12356789, 12456789, 13456789, 23456789` + ###### Does the function prints the value above? + ##### Try with the argument: `n = 9` + `012345678, 012345679, 012345689, 012345789, 012346789, 012356789, 012456789, 013456789, 023456789, 123456789` + ###### Does the function prints the value above? #### PrintNbrBase ##### Try with the argument: `nbr = 919617 and base = 01` + `11100000100001000001` + ###### Does the function prints the value? + ##### Try with the argument: `nbr = 753639 and base = CHOUMIisDAcat!` + `HIDAHI` + ###### Does the function prints the value above? + ##### Try with the argument: `nbr = -174336 and base = CHOUMIisDAcat!` + `-MssiD` + ###### Does the function prints the value above? + ##### Try with the argument: `nbr = -661165 and base = 1` + `NV` + ###### Does the function prints the value above? + ##### Try with the argument: `nbr = -861737 and base = Zone01Zone01` + `NV` + ###### Does the function prints the value above? + ##### Try with the argument: `nbr = 125 and base = 0123456789ABCDEF` + `7D` + ###### Does the function prints the value above? + ##### Try with the argument: `nbr = -125 and base = choumi` + `-uoi` + ###### Does the function prints the value above? + ##### Try with the argument: `nbr = 125 and base = -ab` + `NV` + ###### Does the function prints the value above? + ##### Try with the argument: `nbr = -9223372036854775808 and base = 0123456789` + `-9223372036854775808` + ###### Does the function prints the value above? #### doop ##### Try with the arguments: `861 + 870` + `1731` + ###### Does the program prints the value above? + ##### Try with the arguments: `861 - 870` + `-9` + ###### Does the program prints the value above? + ##### Try with the arguments: `861 * 870` + `749070` + ###### Does the program prints the value above? + ##### Try with the arguments: `861 % 870` + `861` + ###### Does the program prints the value above? + ##### Try with the arguments: `hello + 1` + `0` + ###### Does the program prints the value above? + ##### Try with the arguments: `1 p 1` + `0` + ###### Does the program prints the value above? + ##### Try with the arguments: `1 / 0` + `No division by 0` + ###### Does the program prints the value above? + ##### Try with the arguments: `1 % 0` + `No remainder of division by 0` + ###### Does the program prints the value above? + ##### Try with the arguments: `1 * 1` + `1` + ###### Does the program prints the value above? + ##### Try with the arguments: `9223372036854775807 + 1` + `0` + ###### Does the program prints the value above? + ##### Try with the arguments: `9223372036854775809 - 3` + `0` + ###### Does the program prints the value above? + ##### Try with the arguments: `9223372036854775807 * 3` + `0` + ###### Does the program prints the value above? #### Atoibase ##### Try with the arguments: `s = bcbbbbaab and base = abc` + `12016` + ###### Does the function returns the value above? + ##### Try with the arguments: `s = 0001 and base = 01` + `1` + ###### Does the function returns the value above? + ##### Try with the arguments: `s = 00 and base = 01` + `0` + ###### Does the function returns the value above? + ##### Try with the arguments: `s = saDt!I!sI and base = CHOUMIisDAcat!` + `11557277891` + ###### Does the function returns the value above? + ##### Try with the arguments: `s = AAho?Ao and base = WhoAmI?` + `406772` + ###### Does the function returns the value above? + ##### Try with the arguments: `s = thisinputshouldnotmatter and base = abca` + `0` + ###### Does the function returns the value above? + ##### Try with the arguments: `s = 125 and base = 0123456789` + `125` + ###### Does the function returns the value above? + ##### Try with the arguments: `s = uoi and base = choumi` + `125` + ###### Does the function returns the value above? + ##### Try with the arguments: `s = bbbbbab and base = -ab` + `0` + ###### Does the function returns the value above? #### splitwhitespaces ##### Try with the argument: `str = "The earliest foundations of what would become computer science predate the invention of the modern digital computer"` + `[The earliest foundations of what would become computer science predate the invention of the modern digital computer]` + ###### Does the function returns the value above? + ##### Try with the argument: `str = Machines for calculating fixed numerical tasks such as the abacus have existed since antiquity,` + `[Machines for calculating fixed numerical tasks such as the abacus have existed since antiquity,]` + ###### Does the function returns the value above? -##### Try with the argument: `str = aiding in computations such as multiplication and division .` + +##### Try with the argument: `str = aiding in computations such as multiplication and division .` + `[aiding in computations such as multiplication and division .]` + ###### Does the function returns the value above? -##### Try with the argument: `str = Algorithms for performing computations have existed since antiquity, even before the development of sophisticated computing equipment.` + +##### Try with the argument: `str = Algorithms for performing computations have existed since antiquity, even before the development of sophisticated computing equipment.` + `[Algorithms for performing computations have existed since antiquity, even before the development of sophisticated computing equipment.]` + ###### Does the function returns the value above? + ##### Try with the argument: `str = Wilhelm Schickard designed and constructed the first working mechanical calculator in 1623.[4]` + `[Wilhelm Schickard designed and constructed the first working mechanical calculator in 1623.[4]]` + ###### Does the function returns the value above? -##### Try with the argument: `str = In 1673, Gottfried Leibniz demonstrated a digital mechanical calculator,` + +##### Try with the argument: `str = In 1673, Gottfried Leibniz demonstrated a digital mechanical calculator,` + `[In 1673, Gottfried Leibniz demonstrated a digital mechanical calculator,]` + ###### Does the function returns the value above? #### split ##### Try with the arguments: + ``` str = |=choumi=|which|=choumi=|itself|=choumi=|used|=choumi=|cards|=choumi=|and|=choumi=|a|=choumi=|central|=choumi=|computing|=choumi=|unit.|=choumi=|When|=choumi=|the|=choumi=|machine|=choumi=|was|=choumi=|finished, and charset = |=choumi=| ``` + `[ which itself used cards and a central computing unit. When the machine was finished,]` + ###### Does the function returns the value above? + ##### Try with the arguments: + ``` str = !==!which!==!was!==!making!==!all!==!kinds!==!of!==!punched!==!card!==!equipment!==!and!==!was!==!also!==!in!==!the!==!calculator!==!business[10]!==!to!==!develop!==!his!==!giant!==!programmable!==!calculator, and charset = !==! ``` + `[ which was making all kinds of punched card equipment and was also in the calculator business[10] to develop his giant programmable calculator,]` + ###### Does the function returns the value above? + ##### Try with the arguments: + ``` str = AFJCharlesAFJBabbageAFJstartedAFJtheAFJdesignAFJofAFJtheAFJfirstAFJautomaticAFJmechanicalAFJcalculator, and charset = AFJ ``` + `[ Charles Babbage started the design of the first automatic mechanical calculator,]` + ###### Does the function returns the value above? + ##### Try with the arguments: + ``` str = <<==123==>>In<<==123==>>1820,<<==123==>>Thomas<<==123==>>de<<==123==>>Colmar<<==123==>>launched<<==123==>>the<<==123==>>mechanical<<==123==>>calculator<<==123==>>industry[note<<==123==>>1]<<==123==>>when<<==123==>>he<<==123==>>released<<==123==>>his<<==123==>>simplified<<==123==>>arithmometer, and charset = <<==123==>> ``` + `[ In 1820, Thomas de Colmar launched the mechanical calculator industry[note 1] when he released his simplified arithmometer,]` + ###### Does the function returns the value above? #### convertbase ##### Try with the arguments `nbr = "4506C", baseFrom = "0123456789ABCDEF" and baseTo = "choumi"` + `"hccocimc"` + ###### Does the function returns the value above? + ##### Try with the arguments `nbr = "babcbaaaaabcb", baseFrom = "abc" and baseTo = "0123456789ABCDEF"` + `"9B611"` + ###### Does the function returns the value above? + ##### Try with the arguments `nbr = "256850", baseFrom = "0123456789" and baseTo = "01"` + `"111110101101010010"` + ###### Does the function returns the value above? + ##### Try with the arguments `nbr = "uuhoumo", baseFrom = "choumi" and baseTo = "Zone01"` + `"eeone0n"` + ###### Does the function returns the value above? + ##### Try with the arguments `nbr = "683241", baseFrom = "0123456789" and baseTo = "0123456789"` + `"683241"` + ###### Does the function returns the value above? #### rotatevowels ##### Try the program without any arguments + ###### Does the program displays a new line? + ##### Try executing the program passing as argument: `"Hello World"` + `Hollo Werld` + ###### Does the program returns the value above? + ##### Try executing the program passing as arguments: `"HEllO World" "problem solved"` + `Hello Werld problom sOlvEd` + ###### Does the program returns the value above? + ##### Try executing the program passing as argument: `"str" "shh" "psst"` + `str shh psst` + ###### Does the program returns the value above? + ##### Try executing the program passing as argument: `"happy thoughts" "good luck"` + `huppy thooghts guod lack` + ###### Does the program returns the value above? + ##### Try executing the program passing as argument: `"al's elEphAnt is overly underweight!"` + `il's elephunt es ovirly AndErweaght!` + ###### Does the program returns the value above? #### advancedsortwordarr ##### Try with the arguments - ``` -array = [The earliest computing device undoubtedly consisted of the five fingers of each hand] and f = strings.Compare + ``` +slice = [The earliest computing device undoubtedly consisted of the five fingers of each hand] and f = strings.Compare +``` + `[The computing consisted device each earliest fingers five hand of of the undoubtedly]` + ###### Does the function returns the value above? + ##### Try with the arguments - ``` -array = [The word digital comesfrom "digits" or fingers] and f = strings.Compare + +``` +slice = [The word digital comesfrom "digits" or fingers] and f = strings.Compare ``` + `["digits" The comesfrom digital fingers or word]` + ###### Does the function returns the value above? + ##### Try with the arguments - ``` -array = [a A 1 b B 2 c C 3] and f = strings.Compare + +``` +slice = [a A 1 b B 2 c C 3] and f = strings.Compare ``` + `[1 2 3 A B C a b c]` + ###### Does the function returns the value above? + ##### Try with the arguments - ``` -array = [The computing consisted device each earliest fingers five hand of of the undoubtedly] and f = func(a, b string) int { - return strings.Compare(b, a) - } + ``` +slice = [The computing consisted device each earliest fingers five hand of of the undoubtedly] and f = func(a, b string) int { + return strings.Compare(b, a) +} +``` + `[undoubtedly the of of hand five fingers earliest each device consisted computing The]` + ###### Does the function returns the value above? + ##### Try with the arguments - ``` -array = ["digits" The comesfrom digital fingers or word] and f = func(a, b string) int { - return strings.Compare(b, a) - } + ``` +slice = ["digits" The comesfrom digital fingers or word] and f = func(a, b string) int { + return strings.Compare(b, a) +} +``` + `[word or fingers digital comesfrom The "digits"]` + ###### Does the function returns the value above? + ##### Try with the arguments - ``` -array = [1 2 3 A B C a b c] and f = func(a, b string) int { - return strings.Compare(b, a) - } + +``` +slice = [1 2 3 A B C a b c] and f = func(a, b string) int { + return strings.Compare(b, a) +} ``` + `[c b a C B A 3 2 1]` + ###### Does the function returns the value above? #### cat ##### Run the program without arguments and then write: `Hello` + `Hello` + ###### Does the program returns the value above? + ##### Write: `jaflsdfj` + `jaflsdfj` + ###### Does the program returns the value above? + ##### Write: `Computer science (sometimes called computation science or computing science` + `Computer science (sometimes called computation science or computing science` + ###### Does the program returns the value above? + ##### Run the program passing the file: `quest8.txt` as an argument of execution of the program (as shown in the subject) + ###### Does the the program displays the same output as in the readme? + ##### Run the program with the file: `quest8T.txt` + ###### Does the program displays the content of the file? + ##### Run the program with the arguments: `quest8T.txt quest8.txt` + ###### Does the program displays the content of the file in order? + ##### Run the program with a diferent file and then run the system program `cat` with the same file. + ###### Are the outputs identical? + ##### Run both this program and the system program `cat` passing as an argument a random string that is not the name of a file + ###### Are the outputs identical (ignoring the first word of and the capitalization of the output)? #### ztail -##### Run both ztail and the system command `tail` with the arguments: `-c 20 ` +##### Run both ztail and the system command `tail` with the arguments: `-c 20 ` + ###### Are the outputs exactly the same? + ##### Run both ztail and the system command `tail` with the arguments: ` -c 23` + ###### Are the outputs exactly the same? + ##### Run both ztail and the system command `tail` with the arguments: `-c jelrjq 15` + ###### Are the outputs exactly the same? + ##### Run both ztail and the system command `tail` with the arguments: `-c 11 jfdklsa` + ###### Are the outputs exactly the same? + ##### Run both ztail and the system command `tail` with the arguments: `11 -c ` + ###### Are the outputs exactly the same? #### activebits ##### Try with the argument: `n = 15` + `4` + ###### Does the function returns the value above? + ##### Try with the argument: `n = 17` + `2` + ###### Does the function returns the value above? + ##### Try with the argument: `n = 4` + `1` + ###### Does the function returns the value above? + ##### Try with the argument: `n = 11` + `3` + ###### Does the function returns the value above? + ##### Try with the argument: `n = 9` + `2` + ###### Does the function returns the value above? + ##### Try with the argument: `n = 12` + `2` + ###### Does the function returns the value above? + ##### Try with the argument: `n = 2` + `1` + ###### Does the function returns the value above? #### sortlistinsert ##### Try with the arguments: `l = 0-> and data_ref = 39` + `(0-> 39-> )` + ###### Does the function returns the value above? + ##### Try with the arguments: `l = 0-> 1-> 2-> 3-> 4-> 5-> 24-> 25-> 54-> and data_ref = 33` + `(0-> 1-> 2-> 3-> 4-> 5-> 24-> 25-> 33-> 54-> )` + ###### Does the function returns the value above? + ##### Try with the arguments: `l = 0-> 2-> 18-> 33-> 37-> 37-> 39-> 52-> 53-> 57-> and data_ref = 53` + `(0-> 2-> 18-> 33-> 37-> 37-> 39-> 52-> 53-> 53-> 57-> )` + ###### Does the function returns the value above? + ##### Try with the arguments: `l = 0-> 5-> 18-> 24-> 28-> 35-> 42-> 45-> 52-> and data_ref = 52` + `(0-> 5-> 18-> 24-> 28-> 35-> 42-> 45-> 52-> 52-> )` + ###### Does the function returns the value above? + ##### Try with the arguments: `l = 0-> 12-> 20-> 23-> 23-> 24-> 30-> 41-> 53-> 57-> 59-> and data_ref = 38` + `(0-> 12-> 20-> 23-> 23-> 24-> 30-> 38-> 41-> 53-> 57-> 59-> )` + ###### Does the function returns the value above? #### sortedlistmerge ##### Try with the arguments: `n1 = and n2 = ` + `()` + ###### Does the function returns the value above? + ##### Try with the arguments: `n1 = and n2 = 2-> 2-> 4-> 9-> 12-> 12-> 19-> 20-> ` + `(2-> 2-> 4-> 9-> 12-> 12-> 19-> 20-> )` + ###### Does the function returns the value above? + ##### Try with the arguments: `n1 = 4-> 4-> 6-> 9-> 13-> 18-> 20-> 20-> and n2 = ` + `(4-> 4-> 6-> 9-> 13-> 18-> 20-> 20-> )` + ###### Does the function returns the value above? + ##### Try with the arguments: `n1 = 0-> 7-> 39-> 92-> 97-> 93-> 91-> 28-> 64-> and n2 = 80-> 23-> 27-> 30-> 85-> 81-> 75-> 70-> ` + `(0-> 7-> 23-> 27-> 28-> 30-> 39-> 64-> 70-> 75-> 80-> 81-> 85-> 91-> 92-> 93-> 97-> )` + ###### Does the function returns the value above? + ##### Try with the arguments: `n1 =0-> 2-> 11-> 30-> 54-> 56-> 70-> 79-> 99-> and n2 = 23-> 28-> 38-> 67-> 67-> 79-> 95-> 97-> ` + `(0-> 2-> 11-> 23-> 28-> 30-> 38-> 54-> 56-> 67-> 67-> 70-> 79-> 79-> 95-> 97-> 99-> )` + ###### Does the function returns the value above? + ##### Try with the arguments: `n1 = 0-> 3-> 8-> 8-> 13-> 19-> 34-> 38-> 46-> and n2 = 7-> 39-> 45-> 53-> 59-> 70-> 76-> 79-> ` + `(0-> 3-> 7-> 8-> 8-> 13-> 19-> 34-> 38-> 39-> 45-> 46-> 53-> 59-> 70-> 76-> 79-> )` + ###### Does the function returns the value above? #### listremoveif ##### Try with the arguments: `l = and data_ref = 1` + `()` + ###### Does the function returns the list above? + ##### Try with the arguments: `l = and data_ref = 96` + `()` + ###### Does the function returns the list above? + ##### Try with the arguments: `l = 98-> 98-> 33-> 34-> 33-> 34-> 33-> 89-> 33-> and data_ref = 34` + `(98-> 98-> 33-> 33-> 33-> 89-> 33-> )` + ###### Does the function returns the list above? + ##### Try with the arguments: `l = 79-> 74-> 99-> 79-> 7-> and data_ref = 99` + `(79-> 74-> 79-> 7-> )` + ###### Does the function returns the list above? + ##### Try with the arguments: `l = 56-> 93-> 68-> 56-> 87-> 68-> 56-> 68-> and data_ref = 68` + `(56-> 93-> 56-> 87-> 56-> )` + ###### Does the function returns the list above? -##### Try with the arguments: `l = mvkUxbqhQve4l-> 4Zc4t hnf SQ-> q2If E8BPuX -> and data_ref = 4Zc4t hnf SQ` -`(mvkUxbqhQve4l-> q2If E8BPuX -> )` + +##### Try with the arguments: `l = mvkUxbqhQve4l-> 4Zc4t hnf SQ-> q2If E8BPuX -> and data_ref = 4Zc4t hnf SQ` + +`(mvkUxbqhQve4l-> q2If E8BPuX -> )` + ###### Does the function returns the list above? #### btreetransplant ##### Try with the arguments: + ``` root = 01 @@ -445,6 +779,7 @@ repla = └── 12 └── 15 ``` + ``` 01 └── 07 @@ -457,8 +792,11 @@ repla = └── 02 └── 03 ``` + ###### Does the function returns the value above? + ##### Try with the arguments: + ``` root = 33 @@ -476,6 +814,7 @@ repla = └── 12 └── 15 ``` + ``` 33 ├── 5 @@ -486,8 +825,11 @@ repla = └── 12 └── 15 ``` + ###### Does the function returns the value above? + ##### Try with the arguments: + ``` root = 03 @@ -517,11 +859,13 @@ repla = └── 12 └── 15 ``` + ###### Does the function returns the value above? #### btreeapplybylevel ##### Try with the arguments: + ``` root = 01 @@ -533,6 +877,7 @@ root = └── 03 and f = fmt.Println ``` + ``` 01 07 @@ -542,8 +887,11 @@ and f = fmt.Println 10 03 ``` + ###### Does the function prints the value above? + ##### Try with the arguments: + ``` root = 01 @@ -555,14 +903,17 @@ root = └── 03 and f = fmt.Print ``` + ``` 01070512021003 ``` + ###### Does the function prints the value above? #### btreedeletenode ##### Try with the arguments: + ``` root = 01 @@ -574,6 +925,7 @@ root = └── 03 and node = 02 ``` + ``` 01 └── 07 @@ -582,8 +934,11 @@ and node = 02 └── 05 └── 03 ``` + ###### Does the function returns the value above? + ##### Try with the arguments: + ``` root = 33 @@ -595,6 +950,7 @@ root = └── 11 and node = 20 ``` + ``` 33 ├── 5 @@ -603,8 +959,11 @@ and node = 20 └── 13 └── 11 ``` + ###### Does the function returns the value above? + ##### Try with the arguments: + ``` root = 03 @@ -616,6 +975,7 @@ root = └── 11 and node = 03 ``` + ``` 39 ├── 99 @@ -624,8 +984,11 @@ root = └── 14 └── 11 ``` + ###### Does the function returns the value above? + ##### Try with the arguments: + ``` root = 03 @@ -637,6 +1000,7 @@ root = └── 01 and node = 03 ``` + ``` 03 ├── 94 @@ -645,4 +1009,5 @@ and node = 03 │ └── 111 └── 01 ``` -###### Does the function returns the value above? \ No newline at end of file + +###### Does the function returns the value above? diff --git a/subjects/go-reloaded/go-reloaded.en.md b/subjects/go-reloaded/go-reloaded.en.md index 95e0bffb..35b7560c 100644 --- a/subjects/go-reloaded/go-reloaded.en.md +++ b/subjects/go-reloaded/go-reloaded.en.md @@ -417,7 +417,7 @@ student@ubuntu:~/[[ROOT]]/test$ ### Instructions -Write a function that separates the words of a `string` and puts them in a `string` array. +Write a function that separates the words of a `string` and puts them in a `string` slice. The separators are spaces, tabs and newlines. @@ -467,13 +467,13 @@ student@ubuntu:~/[[ROOT]]/test$ ### Instructions -Write a [function](TODO-LINK) that simulates the behaviour of the `strings.Split` function in Go. `strings.Split` separates the words of a `string` and puts them in a `string` array. -The separators are the characters of the `charset string` given in parameter. +Write a function that simulates the behaviour of the `strings.Split` function in Go. `strings.Split` separates the words of a `string` and puts them in a `string` slice. +The separators are the characters of the separator string given in parameter. ### Expected function ```go -func Split(str, charset string) []string { +func Split(s, sep string) []string { } ``` @@ -606,12 +606,12 @@ student@ubuntu:~/[[ROOT]]/test$ ### Instructions -Write a function `AdvancedSortWordArr` that sorts a `string` array, based on the function `f` passed in parameter. +Write a function `AdvancedSortWordArr` that sorts a `string` slice, based on the function `f` passed in parameter. ### Expected function ```go -func AdvancedSortWordArr(array []string, f func(a, b string) int) { +func AdvancedSortWordArr(a []string, f func(a, b string) int) { } ``` diff --git a/subjects/grouping.en.md b/subjects/grouping.en.md index 8dd2fc0c..c920a237 100644 --- a/subjects/grouping.en.md +++ b/subjects/grouping.en.md @@ -8,9 +8,7 @@ The program should handle the "`|`" operator, that searches for both strings on The output of the program should be the results of the regular expression by order of appearance in the string, being themselves identified by a number. -In case the regular expression is not valid, the last argument is empty or there are no matches the program returns a newline ("`\n`"). - -If the number of arguments is different from 2 the program should print a newline ("`\n`"). +If the number of arguments is different from 2, if the regular expression is not valid, if the last argument is empty or there are no matches the program should print nothing. ### Usage @@ -34,8 +32,6 @@ student@ubuntu:~/[[ROOT]]/test$ ./regbrackets "(hi)" "He swore he just saw his s 1: his 2: sushi student@ubuntu:~/[[ROOT]]/test$ ./regbrackets "(s)" "" - student@ubuntu:~/[[ROOT]]/test$ ./regbrackets "i" "Something in the air" - student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/halfcontestprog.en.md b/subjects/halfcontestprog.en.md index f9feaa07..f42b3435 100644 --- a/subjects/halfcontestprog.en.md +++ b/subjects/halfcontestprog.en.md @@ -1,16 +1,5 @@ ## halfcontest -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). @@ -36,9 +25,7 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { fmt.Println(Halfcontest(1, 15, 3, 33)) diff --git a/subjects/hiddenp.en.md b/subjects/hiddenp.en.md index 68eede87..9b0d7505 100644 --- a/subjects/hiddenp.en.md +++ b/subjects/hiddenp.en.md @@ -8,7 +8,7 @@ Let s1 and s2 be `string`. It is considered that s1 is hidden in s2 if it is pos If s1 is an empty `string` it is considered hidden in any `string`. -If the number of parameters is different from 2, the program displays a newline. +If the number of parameters is different from 2, the program displays nothing. ### Usage @@ -22,7 +22,6 @@ student@ubuntu:~/[[ROOT]]/hiddenp$ ./hiddenp "abc" "btarc" | cat -e 0$ student@ubuntu:~/[[ROOT]]/hiddenp$ ./hiddenp "DD" "DABC" | cat -e 0$ -student@ubuntu:~/[[ROOT]]/hiddenp$ ./hiddenp | cat -e -$ +student@ubuntu:~/[[ROOT]]/hiddenp$ ./hiddenp student@ubuntu:~/[[ROOT]]/hiddenp$ ``` diff --git a/subjects/inter.en.md b/subjects/inter.en.md index eb825758..e5a1ed02 100644 --- a/subjects/inter.en.md +++ b/subjects/inter.en.md @@ -6,7 +6,7 @@ Write a program that takes two `string` and displays, without doubles, the chara - The display will be followed by a newline (`'\n'`). -- If the number of arguments is different from 2, the program displays a newline (`'\n'`). +- If the number of arguments is different from 2, the program displays nothing. ### Usage diff --git a/subjects/interestingnumber.en.md b/subjects/interestingnumber.en.md index 2fc9fed8..d8b23215 100644 --- a/subjects/interestingnumber.en.md +++ b/subjects/interestingnumber.en.md @@ -1,16 +1,5 @@ ## interesting_number -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). diff --git a/subjects/inverttree.en.md b/subjects/inverttree.en.md index c31c8793..09b72204 100644 --- a/subjects/inverttree.en.md +++ b/subjects/inverttree.en.md @@ -1,16 +1,5 @@ ## invert tree -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function that takes tree and inverts(flips) and returns it. diff --git a/subjects/isanagram.en.md b/subjects/isanagram.en.md index da1ac4fc..8533d951 100644 --- a/subjects/isanagram.en.md +++ b/subjects/isanagram.en.md @@ -1,16 +1,5 @@ ## isanagram -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function that returns `true` if two strings are anagrams, otherwise returns `false`. diff --git a/subjects/ispowerof2.en.md b/subjects/ispowerof2.en.md index b88fac2b..ac2a67bf 100644 --- a/subjects/ispowerof2.en.md +++ b/subjects/ispowerof2.en.md @@ -6,9 +6,9 @@ Write a program that determines if a given number is a power of 2. This program must print `true` if the given number is a power of 2, otherwise it prints `false`. -- If there is more than one or no argument the program should print a newline ("`\n`"). +- If there is more than one or no argument the program should print nothing. -- When there is only 1 argument, it will always be a positive valid int. +- When there is only one argument, it will always be a positive valid int. ### Usage : @@ -16,13 +16,11 @@ This program must print `true` if the given number is a power of 2, otherwise it student@ubuntu:~/ispowerof2$ go build student@ubuntu:~/ispowerof2$ ./ispowerof2 2 | cat -e true$ -student@ubuntu:~/ispowerof2$ ./ispowerof2 64 | cat -e -true$ -student@ubuntu:~/ispowerof2$ ./ispowerof2 513 | cat -e -false$ +student@ubuntu:~/ispowerof2$ ./ispowerof2 64 +true +student@ubuntu:~/ispowerof2$ ./ispowerof2 513 +false student@ubuntu:~/ispowerof2$ ./ispowerof2 - student@ubuntu:~/ispowerof2$ ./ispowerof2 64 1024 - student@ubuntu:~/ispowerof2$ ``` diff --git a/subjects/issorted.en.md b/subjects/issorted.en.md index 5c6f8824..e1287233 100644 --- a/subjects/issorted.en.md +++ b/subjects/issorted.en.md @@ -4,15 +4,14 @@ Write a function `IsSorted` that returns `true` if the slice of `int` is sorted, and that returns `false` otherwise. -The function passed in parameter returns a positive `int` if `a`(the first argument) is superior to `b`(the second argument), -it returns `0` if they are equal and it returns a negative `int` otherwise. +The function passed in parameter returns a positive `int` if `a` (the first argument) is superior to `b` (the second argument), it returns `0` if they are equal and it returns a negative `int` otherwise. To do your testing you have to write your own `f` function. ### Expected function ```go -func IsSorted(f func(a, b int) int, tab []int) bool { +func IsSorted(f func(a, b int) int, a []int) bool { } ``` @@ -30,11 +29,11 @@ import ( ) func main() { - tab1 := []int{0, 1, 2, 3, 4, 5} - tab2 := []int{0, 2, 1, 3} + a1 := []int{0, 1, 2, 3, 4, 5} + a2 := []int{0, 2, 1, 3} - result1 := piscine.IsSorted(f, tab1) - result2 := piscine.IsSorted(f, tab2) + result1 := piscine.IsSorted(f, a1) + result2 := piscine.IsSorted(f, a2) fmt.Println(result1) fmt.Println(result2) diff --git a/subjects/itoabaseprog.en.md b/subjects/itoabaseprog.en.md index 0bdea21d..17ee139e 100644 --- a/subjects/itoabaseprog.en.md +++ b/subjects/itoabaseprog.en.md @@ -1,16 +1,5 @@ ## itoabase -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function that: diff --git a/subjects/itoaprog.en.md b/subjects/itoaprog.en.md index 226d2267..96d6ad47 100644 --- a/subjects/itoaprog.en.md +++ b/subjects/itoaprog.en.md @@ -1,16 +1,5 @@ ## itoaprog -##**WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions - Write a function that simulates the behaviour of the `Itoa` function in Go. `Itoa` transforms a number represented as an `int` in a number represented as a `string`. diff --git a/subjects/join.en.md b/subjects/join.en.md index 94851e3c..e87f4d06 100644 --- a/subjects/join.en.md +++ b/subjects/join.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function that returns the concatenation of all the `string` of a table of `string` **separated** by the separator passed in argument. +Write a function that returns the concatenation of all the `string` of a slice of `string` **separated** by the separator passed in argument. ### Expected function diff --git a/subjects/lastruneprog.en.md b/subjects/lastruneprog.en.md index 0c0fab5e..ab0c2f7b 100644 --- a/subjects/lastruneprog.en.md +++ b/subjects/lastruneprog.en.md @@ -1,16 +1,5 @@ ## lastruneprog -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function that returns the last `rune` of a `string`. diff --git a/subjects/lastword.en.md b/subjects/lastword.en.md index d79d23e3..4bc69a8e 100644 --- a/subjects/lastword.en.md +++ b/subjects/lastword.en.md @@ -8,7 +8,7 @@ Write a program that takes a `string` and displays its last word, followed by a - The output will be followed by a newline (`'\n'`). -- If the number of parameters is different from 1, or if there are no word, the program displays a newline (`'\n'`). +- If the number of parameters is different from 1, or if there are no word, the program displays nothing. ### Usage @@ -18,10 +18,8 @@ student@ubuntu:~/[[ROOT]]/lastword$ ./lastword "FOR PONY" | cat -e PONY$ student@ubuntu:~/[[ROOT]]/lastword$ ./lastword "this ... is sparta, then again, maybe not" | cat -e not$ -student@ubuntu:~/[[ROOT]]/lastword$ ./lastword " " | cat -e -$ -student@ubuntu:~/[[ROOT]]/lastword$ ./lastword "a" "b" | cat -e -$ +student@ubuntu:~/[[ROOT]]/lastword$ ./lastword " " +student@ubuntu:~/[[ROOT]]/lastword$ ./lastword "a" "b" student@ubuntu:~/[[ROOT]]/lastword$ ./lastword " lorem,ipsum " | cat -e lorem,ipsum$ student@ubuntu:~/[[ROOT]]/lastword$ diff --git a/subjects/lcm.en.md b/subjects/lcm.en.md index f025adfc..c6b53064 100644 --- a/subjects/lcm.en.md +++ b/subjects/lcm.en.md @@ -1,16 +1,5 @@ ## lcm -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function, `lcm`, that returns least common multiple. diff --git a/subjects/listremoveifprog.en.md b/subjects/listremoveifprog.en.md index 6df9b591..692db5ff 100644 --- a/subjects/listremoveifprog.en.md +++ b/subjects/listremoveifprog.en.md @@ -1,16 +1,5 @@ ## listremoveifprog -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function `ListRemoveIf` that removes all elements that have a `Data` field equal to the `data_ref` in the argument of the function. diff --git a/subjects/listsizeprog.en.md b/subjects/listsizeprog.en.md index 3dbfb1d4..3b18a45a 100644 --- a/subjects/listsizeprog.en.md +++ b/subjects/listsizeprog.en.md @@ -1,16 +1,5 @@ ## listsizeprog -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function `ListSize` that returns the number of elements in a linked list `l`. diff --git a/subjects/map.en.md b/subjects/map.en.md index 3d6b1ddc..8ac288b6 100644 --- a/subjects/map.en.md +++ b/subjects/map.en.md @@ -2,12 +2,12 @@ ### Instructions -Write a function `Map` that, for an `int` array, applies a function of this type `func(int) bool` on each elements of that array and returns an array of all the return values. +Write a function `Map` that, for an `int` slice, applies a function of this type `func(int) bool` on each elements of that slice and returns a slice of all the return values. ### Expected function ```go -func Map(f func(int) bool, arr []int) []bool { +func Map(f func(int) bool, a []int) []bool { } ``` @@ -25,8 +25,8 @@ import ( ) func main() { - arr := []int{1, 2, 3, 4, 5, 6} - result := piscine.Map(piscine.IsPrime, arr) + a := []int{1, 2, 3, 4, 5, 6} + result := piscine.Map(piscine.IsPrime, a) fmt.Println(result) } ``` diff --git a/subjects/max.en.md b/subjects/max.en.md index 52638b8a..2261fa38 100644 --- a/subjects/max.en.md +++ b/subjects/max.en.md @@ -2,12 +2,12 @@ ### Instructions -Write a function, `Max`, that returns the maximum value in a slice of integers. +Write a function, `Max`, that returns the maximum value in a slice of integers. If the slice is empty, returns 0. ### Expected function ```go -func Max(arr []int) int { +func Max(a []int) int { } ``` @@ -25,8 +25,8 @@ import ( ) func main() { - arrInt := []int{23, 123, 1, 11, 55, 93} - max := piscine.Max(arrInt) + a := []int{23, 123, 1, 11, 55, 93} + max := piscine.Max(a) fmt.Println(max) } ``` diff --git a/subjects/maxprog.en.md b/subjects/maxprog.en.md index 0ac672a6..77561af8 100644 --- a/subjects/maxprog.en.md +++ b/subjects/maxprog.en.md @@ -1,16 +1,5 @@ ## maxprog -##**WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function, `Max`, that returns the maximum value in a slice of integers. @@ -18,7 +7,7 @@ Write a function, `Max`, that returns the maximum value in a slice of integers. ### Expected function ```go -func Max(arr []int) int { +func Max(a []int) int { } ``` @@ -30,9 +19,7 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { arrInt := []int{23, 123, 1, 11, 55, 93} diff --git a/subjects/merge.en.md b/subjects/merge.en.md index b36fa9c6..b2d0ba31 100644 --- a/subjects/merge.en.md +++ b/subjects/merge.en.md @@ -1,16 +1,5 @@ ## merge -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testing are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. diff --git a/subjects/nauuo.en.md b/subjects/nauuo.en.md index d568e471..577a2ace 100644 --- a/subjects/nauuo.en.md +++ b/subjects/nauuo.en.md @@ -1,16 +1,5 @@ ## nauuo -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions There was a vote. There are people who voted positively, negatively, and randomly. diff --git a/subjects/nbrconvertalpha.en.md b/subjects/nbrconvertalpha.en.md index 4d2d054a..65e701e5 100644 --- a/subjects/nbrconvertalpha.en.md +++ b/subjects/nbrconvertalpha.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a **program** that prints the corresponding letter in the `n` position of the classic latin alphabet, where `n` is each argument received. +Write a **program** that prints the corresponding letter in the `n` position of the latin alphabet, where `n` is each argument received. For example `1` matches `a`, `2` matches `b`, etc. If `n` does not match a valid position of the alphabet or if the argument is not an integer, the **program** should print a space (" "). diff --git a/subjects/nenokku.en.md b/subjects/nenokku.en.md index a1eaae2c..b4597d6e 100644 --- a/subjects/nenokku.en.md +++ b/subjects/nenokku.en.md @@ -12,7 +12,7 @@ Intersection of words is counted as if it is in your dictionary (see example). Write a program that takes as arguments operations. ```console -$> ./main "? love" "? is" "A loveis" "? love" "? Who" "A Whoareyou" "? is" +$ ./main "? love" "? is" "A loveis" "? love" "? Who" "A Whoareyou" "? is" NO NO YES diff --git a/subjects/nruneprog.en.md b/subjects/nruneprog.en.md index 15b49e05..50053431 100644 --- a/subjects/nruneprog.en.md +++ b/subjects/nruneprog.en.md @@ -1,16 +1,5 @@ ## nruneprog -##**WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function that returns the nth `rune` of a `string`. diff --git a/subjects/piglatin.en.md b/subjects/piglatin.en.md index 890e6ba0..d12029d7 100644 --- a/subjects/piglatin.en.md +++ b/subjects/piglatin.en.md @@ -11,14 +11,13 @@ The rules used by Pig Latin are as follows: If the word has no vowels the program should print "No vowels". -If the number of arguments is different from one, the program prints a newline ("`\n`"). +If the number of arguments is different from one, the program prints nothing. ### Usage ```console student@ubuntu:~/student/test$ go build student@ubuntu:~/student/test$ ./piglatin - student@ubuntu:~/student/test$ ./piglatin pig | cat -e igpay$ student@ubuntu:~/student/test$ ./piglatin Is | cat -e diff --git a/subjects/printmemory.en.md b/subjects/printmemory.en.md index 2807b631..d62fc65a 100644 --- a/subjects/printmemory.en.md +++ b/subjects/printmemory.en.md @@ -1,16 +1,5 @@ ## printmemory -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function that takes `(arr [10]int)`, and displays the memory as in the example. diff --git a/subjects/printprogramname.en.md b/subjects/printprogramname.en.md index 8337b14c..5b3c7d17 100644 --- a/subjects/printprogramname.en.md +++ b/subjects/printprogramname.en.md @@ -11,7 +11,7 @@ student@ubuntu:~/[[ROOT]]/printprogramname$ go build main.go student@ubuntu:~/[[ROOT]]/printprogramname$ ./main main student@ubuntu:~/[[ROOT]]/printprogramname$ go build -student@ubuntu:~/[[ROOT]]/printprogramname$ ./printprogramname -printprogramname +student@ubuntu:~/[[ROOT]]/printprogramname$ ./printprogramname | cat -e +printprogramname$ student@ubuntu:~/[[ROOT]]/printprogramname$ ``` diff --git a/subjects/printwordstables.en.md b/subjects/printwordstables.en.md index dc2f7141..3a06a5ca 100644 --- a/subjects/printwordstables.en.md +++ b/subjects/printwordstables.en.md @@ -2,11 +2,9 @@ ### Instructions -Write a function that prints the words of a `string` array that will be returned a function `SplitWhiteSpaces`. (the testing will be done with ours) +Write a function that prints the words of a `string` slice that will be returned a function `SplitWhiteSpaces`. -Each word is on a single line. - -Each word ends with a `\n`. +Each word is on a single line (each word ends with a `\n`). ### Expected function diff --git a/subjects/priorprime.en.md b/subjects/priorprime.en.md index d48da855..1ac315ad 100644 --- a/subjects/priorprime.en.md +++ b/subjects/priorprime.en.md @@ -1,16 +1,5 @@ ## priorprime -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testing are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions You are given an integer. @@ -21,7 +10,7 @@ Your function must return sum of all prime numbers prior to the number exclusive ```go package main -func Priorprime(x int) int { +func PriorPrime(x int) int { } ``` @@ -33,12 +22,10 @@ Here is a possible program to test your function: ```go package main -import ( - "fmt" -) +import "fmt" func main() { - fmt.Println(Priorprime(14)) + fmt.Println(PriorPrime(14)) } ``` diff --git a/subjects/raid1a.en.md b/subjects/raid1a.en.md index 0e02c912..6d8989cc 100644 --- a/subjects/raid1a.en.md +++ b/subjects/raid1a.en.md @@ -25,9 +25,7 @@ Program #1 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1a(5,3) @@ -50,9 +48,7 @@ Program #2 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1a(5,1) @@ -73,9 +69,7 @@ Program #3 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1a(1,1) @@ -96,9 +90,7 @@ Program #4 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1a(1,5) diff --git a/subjects/raid1b.en.md b/subjects/raid1b.en.md index 41b70568..fbe73ade 100644 --- a/subjects/raid1b.en.md +++ b/subjects/raid1b.en.md @@ -25,9 +25,7 @@ Program #1 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1b(5,3) @@ -50,9 +48,7 @@ Program #2 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1b(5,1) @@ -73,9 +69,7 @@ Program #3 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1b(1,1) @@ -96,9 +90,7 @@ Program #4 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1b(1,5) diff --git a/subjects/raid1c.en.md b/subjects/raid1c.en.md index 77aa21ee..1dd3e2ef 100644 --- a/subjects/raid1c.en.md +++ b/subjects/raid1c.en.md @@ -25,9 +25,7 @@ Program #1 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1c(5,3) @@ -50,9 +48,7 @@ Program #2 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1c(5,1) @@ -73,9 +69,7 @@ Program #3 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1c(1,1) @@ -96,9 +90,7 @@ Program #4 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1c(1,5) diff --git a/subjects/raid1d.en.md b/subjects/raid1d.en.md index 3bfd67d4..fc68d54d 100644 --- a/subjects/raid1d.en.md +++ b/subjects/raid1d.en.md @@ -25,9 +25,7 @@ Program #1 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1d(5,3) @@ -50,9 +48,7 @@ Program #2 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1d(5,1) @@ -73,9 +69,7 @@ Program #3 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1d(1,1) @@ -96,9 +90,7 @@ Program #4 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1d(1,5) diff --git a/subjects/raid1e.en.md b/subjects/raid1e.en.md index 36d54a6e..ed66922e 100644 --- a/subjects/raid1e.en.md +++ b/subjects/raid1e.en.md @@ -25,9 +25,7 @@ Program #1 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1e(5,3) @@ -50,9 +48,7 @@ Program #2 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1e(5,1) @@ -73,9 +69,7 @@ Program #3 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1e(1,1) @@ -96,9 +90,7 @@ Program #4 ```go package main -import ( - piscine ".." -) +import piscine ".." func main() { piscine.Raid1e(1,5) diff --git a/subjects/range.en.md b/subjects/range.en.md index cdee44ce..5d0985e8 100644 --- a/subjects/range.en.md +++ b/subjects/range.en.md @@ -4,15 +4,15 @@ Write a program which must: -- **Allocate (with `make`)** an array of integers. +- **Allocate (with `make`)** a slice of integers. - Fill it with consecutive values that begins at the first argument and end at the second argument (Including the values of thoses arguments !). -- That prints the array. +- That prints the slice. Errors should be handled. -If the number of arguments is different from 2 the program prints a newline ("`\n`"). +If the number of arguments is different from 2 the program prints nothing. ### Expected output : diff --git a/subjects/reachablenumberprog.en.md b/subjects/reachablenumberprog.en.md index f790264c..b331300b 100644 --- a/subjects/reachablenumberprog.en.md +++ b/subjects/reachablenumberprog.en.md @@ -1,15 +1,4 @@ -## reachable_number - -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. +## reachablenumber ### Instructions @@ -18,7 +7,7 @@ Let us define a function f(x) by the following: first we add 1 to x, and then wh ### Expected function ```go -func Reachablenumber(n int) int { +func ReachableNumber(n int) int { } ``` @@ -30,14 +19,12 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { - fmt.Println(Reachablenumber(1)) - fmt.Println(Reachablenumber(10)) - fmt.Println(Reachablenumber(1001)) + fmt.Println(ReachableNumber(1)) + fmt.Println(ReachableNumber(10)) + fmt.Println(ReachableNumber(1001)) } ``` diff --git a/subjects/rectangle.en.md b/subjects/rectangle.en.md index be3bd786..ea1abc02 100644 --- a/subjects/rectangle.en.md +++ b/subjects/rectangle.en.md @@ -2,8 +2,7 @@ ### Instructions -Consider that a point is defined by its coordinates and that a rectangle -is defined by the points of the upper left and lower right corners. +Consider that a point is defined by its coordinates and that a rectangle is defined by the points of the upper left and lower right corners. - Define two structures named, `point` and `rectangle`. diff --git a/subjects/reduceint.en.md b/subjects/reduceint.en.md index 094dc279..7e28ec4a 100644 --- a/subjects/reduceint.en.md +++ b/subjects/reduceint.en.md @@ -1,16 +1,5 @@ ## reduceint -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function called `reduceint` that simulates the behaviour of reduce from JavaScript. diff --git a/subjects/repeatalpha.en.md b/subjects/repeatalpha.en.md index dc931013..d72970fe 100644 --- a/subjects/repeatalpha.en.md +++ b/subjects/repeatalpha.en.md @@ -2,29 +2,25 @@ ### Instructions -Write a program called `repeat_alpha` that takes a `string` and displays it -repeating each alphabetical character as many times as its alphabetical index. +Write a program called `repeat_alpha` that takes a `string` and displays it repeating each alphabetical character as many times as its alphabetical index. The result must be followed by a newline (`'\n'`). `'a'` becomes `'a'`, `'b'` becomes `'bb'`, `'e'` becomes `'eeeee'`, etc... -The case remains unchanged. - -If the number of arguments is different from 1, the program displays a newline (`'\n'`). +If the number of arguments is different from 1, the program displays nothing. ### Usage ```console student@ubuntu:~/[[ROOT]]/repeatalpha$ go build -student@ubuntu:~/[[ROOT]]/repeatalpha$ ./repeatalpha "abc" | cat -e +student@ubuntu:~/[[ROOT]]/repeatalpha$ ./repeatalpha abc | cat -e abbccc -student@ubuntu:~/[[ROOT]]/repeatalpha$ ./repeatalpha "Choumi." | cat -e +student@ubuntu:~/[[ROOT]]/repeatalpha$ ./repeatalpha Choumi. | cat -e CCChhhhhhhhooooooooooooooouuuuuuuuuuuuuuuuuuuuummmmmmmmmmmmmiiiiiiiii.$ student@ubuntu:~/[[ROOT]]/repeatalpha$ ./repeatalpha "abacadaba 01!" | cat -e abbacccaddddabba 01!$ -student@ubuntu:~/[[ROOT]]/repeatalpha$ ./repeatalpha | cat -e -$ +student@ubuntu:~/[[ROOT]]/repeatalpha$ ./repeatalpha student@ubuntu:~/[[ROOT]]/repeatalpha$ ./repeatalpha "" | cat -e $ student@ubuntu:~/[[ROOT]]/repeatalpha$ diff --git a/subjects/reverse.en.md b/subjects/reverse.en.md index 3fd2f862..e3b8d52a 100644 --- a/subjects/reverse.en.md +++ b/subjects/reverse.en.md @@ -1,16 +1,5 @@ ## reverse -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testing are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions You are given a linked list, where each node contains a single digit. @@ -38,9 +27,7 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func pushBack(n *NodeAddL, num int) *NodeAddL{ diff --git a/subjects/reversebits.en.md b/subjects/reversebits.en.md index d21eb1ed..818b53e7 100644 --- a/subjects/reversebits.en.md +++ b/subjects/reversebits.en.md @@ -1,16 +1,5 @@ ## reversebits -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a function that takes a `byte`, reverses it `bit` by `bit` (as shown in the example) and returns the result. @@ -26,9 +15,11 @@ func ReverseBits(oct byte) byte { Example: - 1 byte -_____________ - 0010 0110 - || - \/ - 0110 0100 +1 byte + +--- + +0010 0110 +|| +\/ +0110 0100 diff --git a/subjects/reverserange.en.md b/subjects/reverserange.en.md index ac060a15..f05529af 100644 --- a/subjects/reverserange.en.md +++ b/subjects/reverserange.en.md @@ -4,15 +4,15 @@ Write a program which must: -- **Allocate (with `make`)** an array of integers. +- **Allocate (with `make`)** a slice of integers. - Fill it with consecutive values that begins at the second argument and end at the first argument (Including the values of thoses arguments !). -- That prints the array. +- That prints the slice. Errors should be handled. -If the number of arguments is different from 2 the program prints a newline ("`\n`"). +If the number of arguments is different from 2 the program prints nothing. ### Usage : diff --git a/subjects/revivethreenums.en.md b/subjects/revivethreenums.en.md index 9da1f9d0..b0fb7afc 100644 --- a/subjects/revivethreenums.en.md +++ b/subjects/revivethreenums.en.md @@ -1,15 +1,4 @@ -## revive_three_nums - -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. +## revivethreenums ### Instructions @@ -23,7 +12,7 @@ There are basically three integers: **a**, **b**, **c**. You are given 4 integer ### Expected function ```go -func Revive_three_nums(a, b, c, d int) int { +func ReviveThreeNums(a, b, c, d int) int { } ``` @@ -35,14 +24,12 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { - fmt.Println(Revive_three_nums(3, 6, 5, 4)) - fmt.Println(Revive_three_nums(40, 40, 40, 60)) - fmt.Println(Revive_three_nums(201, 101, 101, 200)) + fmt.Println(ReviveThreeNums(3, 6, 5, 4)) + fmt.Println(ReviveThreeNums(40, 40, 40, 60)) + fmt.Println(ReviveThreeNums(201, 101, 101, 200)) } ``` diff --git a/subjects/robottoorigin.en.md b/subjects/robottoorigin.en.md index 2758776e..2b710f8d 100644 --- a/subjects/robottoorigin.en.md +++ b/subjects/robottoorigin.en.md @@ -13,7 +13,7 @@ Sequence of moves is a string, which characters state for movement direction: - R - right - L - left -If the number of arguments is not 1, output `\n`. +If the number of arguments is not 1, output nothing. ### Usage diff --git a/subjects/romannumbers.en.md b/subjects/romannumbers.en.md index e35e535b..6560d760 100644 --- a/subjects/romannumbers.en.md +++ b/subjects/romannumbers.en.md @@ -8,30 +8,30 @@ The program should have a limit of `4000`. In case of an invalid number, for exa Roman Numerals reminder: -| I | 1 | -|:-:|:----:| -| V | 5 | -| X | 10 | -| L | 50 | -| C | 100 | -| D | 500 | -| M | 1000 | +| I | 1 | +| :-: | :--: | +| V | 5 | +| X | 10 | +| L | 50 | +| C | 100 | +| D | 500 | +| M | 1000 | For example, the number 1732 would be denoted MDCCXXXII in Roman numerals. However, Roman numerals are not a purely additive number system. In particular, instead of using four symbols to represent a 4, 40, 9, 90, etc. (i.e., IIII, XXXX, VIIII, LXXXX, etc.), such numbers are instead denoted by preceding the symbol for 5, 50, 10, 100, etc., with a symbol indicating subtraction. For example, 4 is denoted IV, 9 as IX, 40 as XL, etc. -The following table gives the Roman numerals for the first few positive integers. - -| 1 | I | 11 | XI | 21 | XXI | -|:--:|:----:|:--:|:-----:|:--:|:------:| -| 2 | II | 12 | XII | 22 | XXII | -| 3 | III | 13 | XIII | 23 | XXIII | -| 4 | IV | 14 | XIV | 24 | XXIV | -| 5 | V | 15 | XV | 25 | XXV | -| 6 | VI | 16 | XVI | 26 | XXVI | -| 7 | VII | 17 | XVII | 27 | XXVII | -| 8 | VIII | 18 | XVIII | 28 | XXVIII | -| 9 | XIX | 19 | XIX | 29 | XXIX | -| 10 | X | 20 | XX | 30 | XXX | +The following table gives the Roman numerals for the first few positive integers. + +| 1 | I | 11 | XI | 21 | XXI | +| :-: | :--: | :-: | :---: | :-: | :----: | +| 2 | II | 12 | XII | 22 | XXII | +| 3 | III | 13 | XIII | 23 | XXIII | +| 4 | IV | 14 | XIV | 24 | XXIV | +| 5 | V | 15 | XV | 25 | XXV | +| 6 | VI | 16 | XVI | 26 | XXVI | +| 7 | VII | 17 | XVII | 27 | XXVII | +| 8 | VIII | 18 | XVIII | 28 | XXVIII | +| 9 | XIX | 19 | XIX | 29 | XXIX | +| 10 | X | 20 | XX | 30 | XXX | ## Usage diff --git a/subjects/rot13.en.md b/subjects/rot13.en.md index fc90ad0b..20ba3f7a 100644 --- a/subjects/rot13.en.md +++ b/subjects/rot13.en.md @@ -9,7 +9,7 @@ letters by the letter 13 spaces ahead in alphabetical order. - The output will be followed by a newline (`'\n'`). -- If the number of arguments is different from 1, the program displays a newline (`'\n'`). +- If the number of arguments is different from 1, the program displays nothing. ### Usage @@ -22,6 +22,5 @@ uryyb gurer student@ubuntu:~/[[ROOT]]/test$ ./test "HELLO, HELP" URYYB, URYC student@ubuntu:~/[[ROOT]]/test$ ./test - student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/rot14.en.md b/subjects/rot14.en.md index db6880ee..4c6e8e52 100644 --- a/subjects/rot14.en.md +++ b/subjects/rot14.en.md @@ -7,7 +7,7 @@ Write a function `rot14` that returns the `string` within the parameter transfor ### Expected function ```go -func Rot14(str string) string { +func Rot14(s string) string { } ``` @@ -26,10 +26,9 @@ import ( func main() { result := piscine.Rot14("Hello How are You") - arrayRune := []rune(result) - for _, s := range arrayRune { - z01.PrintRune(s) + for _, r := range result { + z01.PrintRune(r) } z01.PrintRune('\n') } diff --git a/subjects/rot14prog.en.md b/subjects/rot14prog.en.md index c421a1f7..28ac2c09 100644 --- a/subjects/rot14prog.en.md +++ b/subjects/rot14prog.en.md @@ -11,8 +11,6 @@ student@ubuntu:~/rot14prog$ go build student@ubuntu:~/rot14prog$ ./rot14prog "Hello How are You" | cat -e Vszzc Vck ofs Mci$ student@ubuntu:~/rot14prog$ ./rot14prog Hello How are You - student@ubuntu:~/rot14prog$ ./rot14prog - student@ubuntu:~/rot14prog$ ``` diff --git a/subjects/sametree.en.md b/subjects/sametree.en.md index 16f6aae3..da2621c0 100644 --- a/subjects/sametree.en.md +++ b/subjects/sametree.en.md @@ -1,16 +1,5 @@ ## sametree -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testing are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Given two binary trees, write a function to check if they are the same or not. diff --git a/subjects/searchreplace.en.md b/subjects/searchreplace.en.md index 275a7253..24ba9287 100644 --- a/subjects/searchreplace.en.md +++ b/subjects/searchreplace.en.md @@ -4,7 +4,7 @@ Write a program that takes 3 arguments, the first argument is a `string` in which to replace a letter (the 2nd argument) by another one (the 3rd argument). -- If the number of arguments is different from 3, the program displays a newline (`'\n'`). +- If the number of arguments is different from 3, the program displays nothing. - If the second argument is not contained in the first one (the string) then the program rewrites the `string` followed by a newline (`'\n'`). @@ -17,6 +17,5 @@ hello there student@ubuntu:~/[[ROOT]]/test$ ./test "abcd" "z" "l" abcd student@ubuntu:~/[[ROOT]]/test$ ./test "something" "a" "o" "b" "c" - student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/sliceprog.en.md b/subjects/sliceprog.en.md index 8d848479..86edbe49 100644 --- a/subjects/sliceprog.en.md +++ b/subjects/sliceprog.en.md @@ -1,30 +1,19 @@ ## slice -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions Write a **function** that replicates the javascript function `slice`. -The function receives an array of strings and one or more integers, and returns an array of strings. The returned array is part of the received one but cut from the position indicated in the first int, until the position indicated by the second int. +The function receives a slice of strings and one or more integers, and returns a slice of strings. The returned slice is part of the received one but cut from the position indicated in the first int, until the position indicated by the second int. -In case there only exists one int, the resulting array begins in the position indicated by the int and ends at the end of the received array. +In case there only exists one int, the resulting slice begins in the position indicated by the int and ends at the end of the received slice. -The ints can be lower than 0. +The integers can be lower than 0. ### Expected function ```go -func Slice(arr []string, nbrs... int) []string{ +func Slice(a []string, nbrs... int) []string{ } ``` @@ -39,12 +28,12 @@ package main import "fmt" func main(){ - arr := []string{"coding", "algorithm", "ascii", "package", "golang"} - fmt.Println(Slice(arr, 1)) - fmt.Println(Slice(arr, 2, 4)) - fmt.Println(Slice(arr, -3)) - fmt.Println(Slice(arr, -2, -1)) - fmt.Println(Slice(arr, 2, 0)) + a := []string{"coding", "algorithm", "ascii", "package", "golang"} + fmt.Println(Slice(a, 1)) + fmt.Println(Slice(a, 2, 4)) + fmt.Println(Slice(a, -3)) + fmt.Println(Slice(a, -2, -1)) + fmt.Println(Slice(a, 2, 0)) } ``` diff --git a/subjects/sortintegertable.en.md b/subjects/sortintegertable.en.md index e0ba79e0..2c664980 100644 --- a/subjects/sortintegertable.en.md +++ b/subjects/sortintegertable.en.md @@ -2,7 +2,7 @@ ### Instructions -- Write a function that reorder an array of `int` in ascending order. +- Write a function that reorder a slice of `int` in ascending order. ### Expected function diff --git a/subjects/sortll.en.md b/subjects/sortll.en.md index 0c91a5f2..462381ff 100644 --- a/subjects/sortll.en.md +++ b/subjects/sortll.en.md @@ -1,16 +1,5 @@ ## sortlinkedlist -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions You are given a linked list, where each node contains a single digit. @@ -38,9 +27,7 @@ Here is a possible program to test your function: ```go package main -import ( - "fmt" -) +import "fmt" // I implemented pushBack for this @@ -65,7 +52,7 @@ func main() { Its output: ```console -$> go build -$> ./main +$ go build +$ ./main 5 -> 3 -> 3 -> 1 -> 1 ``` diff --git a/subjects/sortwordarr.en.md b/subjects/sortwordarr.en.md index 5960ce31..8fe3b3f1 100644 --- a/subjects/sortwordarr.en.md +++ b/subjects/sortwordarr.en.md @@ -2,12 +2,12 @@ ### Instructions -Write a function `SortWordArr` that sorts by `ascii` (in ascending order) a `string` array. +Write a function `SortWordArr` that sorts by `ascii` (in ascending order) a `string` slice. ### Expected function ```go -func SortWordArr(array []string) { +func SortWordArr(a []string) { } ``` @@ -25,7 +25,6 @@ import ( ) func main() { - result := []string{"a", "A", "1", "b", "B", "2", "c", "C", "3"} piscine.SortWordArr(result) diff --git a/subjects/sortwordarrprog.en.md b/subjects/sortwordarrprog.en.md index 15371c33..f742666c 100644 --- a/subjects/sortwordarrprog.en.md +++ b/subjects/sortwordarrprog.en.md @@ -1,24 +1,13 @@ ## sortwordarrprog -##**WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions -Write a function `SortWordArr` that sorts by `ascii` (in ascending order) a `string` array. +Write a function `SortWordArr` that sorts by ASCII (in ascending order) a `string` slice. ### Expected function ```go -func SortWordArr(array []string) { +func SortWordArr(a []string) { } ``` @@ -30,15 +19,11 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { - result := []string{"a", "A", "1", "b", "B", "2", "c", "C", "3"} SortWordArr(result) - fmt.Println(result) } ``` diff --git a/subjects/split.en.md b/subjects/split.en.md index fd8e6e46..05ca3853 100644 --- a/subjects/split.en.md +++ b/subjects/split.en.md @@ -2,14 +2,14 @@ ### Instructions -Write a function that separates the words of a `string` and puts them in a `string` array. +Write a function that separates the words of a `string` and puts them in a `string` slice. -The separators are the characters of the `charset string` given in parameter. +The separators are the characters of the separator string given in parameter. ### Expected function ```go -func Split(str, charset string) []string { +func Split(s, sep string) []string { } ``` @@ -27,8 +27,8 @@ import ( ) func main() { - str := "HelloHAhowHAareHAyou?" - fmt.Println(piscine.Split(str, "HA")) + s := "HelloHAhowHAareHAyou?" + fmt.Printf("%#v\n", piscine.Split(s, "HA")) } ``` @@ -37,6 +37,6 @@ And its output : ```console student@ubuntu:~/[[ROOT]]/test$ go build student@ubuntu:~/[[ROOT]]/test$ ./test -[Hello how are you?] +[]string{"Hello", "how", "are", "you?"} student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/splitprog.en.md b/subjects/splitprog.en.md index 831ee504..700a683b 100644 --- a/subjects/splitprog.en.md +++ b/subjects/splitprog.en.md @@ -1,26 +1,15 @@ ## splitprog -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions -Write a function that separates the words of a `string` and puts them in a `string` array. +Write a function that separates the words of a `string` and puts them in a `string` slice. -The separators are the characters of the `charset string` given in parameter. +The separators are the characters of the separator string given in parameter. ### Expected function ```go -func Split(str, charset string) []string { +func Split(s, sep string) []string { } ``` @@ -38,8 +27,8 @@ import ( ) func main() { - str := "HelloHAhowHAareHAyou?" - fmt.Println(piscine.Split(str, "HA")) + s := "HelloHAhowHAareHAyou?" + fmt.Printf("%#v\n", piscine.Split(s, "HA")) } ``` @@ -48,6 +37,6 @@ And its output : ```console student@ubuntu:~/[[ROOT]]/test$ go build student@ubuntu:~/[[ROOT]]/test$ ./test -[Hello how are you?] +[]string{"Hello", "how", "are", "you?"} student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/splitwhitespaces.en.md b/subjects/splitwhitespaces.en.md index d2f29673..13dffb31 100644 --- a/subjects/splitwhitespaces.en.md +++ b/subjects/splitwhitespaces.en.md @@ -2,7 +2,7 @@ ### Instructions -Write a function that separates the words of a `string` and puts them in a `string` array. +Write a function that separates the words of a `string` and puts them in a `string` slice. The separators are spaces, tabs and newlines. @@ -27,8 +27,8 @@ import ( ) func main() { - str := "Hello how are you?" - fmt.Println(piscine.SplitWhiteSpaces(str)) + s := "Hello how are you?" + fmt.Printf("%#v\n", piscine.SplitWhiteSpaces(s)) } ``` @@ -37,6 +37,6 @@ And its output : ```console student@ubuntu:~/[[ROOT]]/test$ go build student@ubuntu:~/[[ROOT]]/test$ ./test -[Hello how are you?] +[]string{"Hello", "how", "are", "you?"} student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/strlenprog.en.md b/subjects/strlenprog.en.md index cf6dab42..272ddc7d 100644 --- a/subjects/strlenprog.en.md +++ b/subjects/strlenprog.en.md @@ -1,16 +1,5 @@ ## strlenprog -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions - Write a function that counts the `runes` of a `string` and that returns that count. @@ -18,7 +7,7 @@ This means that: ### Expected function ```go -func StrLen(str string) int { +func StrLen(s string) int { } ``` @@ -30,13 +19,11 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { - str := "Hello World!" - nb := StrLen(str) + s := "Hello World!" + nb := StrLen(s) fmt.Println(nb) } ``` diff --git a/subjects/swapbits.en.md b/subjects/swapbits.en.md index 8c7f3937..3cb6933f 100644 --- a/subjects/swapbits.en.md +++ b/subjects/swapbits.en.md @@ -1,20 +1,8 @@ ## swapbits -##**WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions -Write a function that takes a `byte`, swaps its halfs (like the -example) and returns the result. +Write a function that takes a `byte`, swaps its halfs (like the example) and returns the result. ### Expected function diff --git a/subjects/swapprog.en.md b/subjects/swapprog.en.md index c0083f0a..9b5bf4ba 100644 --- a/subjects/swapprog.en.md +++ b/subjects/swapprog.en.md @@ -1,16 +1,5 @@ ## swapprog -##**WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions - Write a function that swaps the contents of two **pointers to an int** (`*int`). diff --git a/subjects/sweetproblem.en.md b/subjects/sweetproblem.en.md index 9386384d..b5e93a22 100644 --- a/subjects/sweetproblem.en.md +++ b/subjects/sweetproblem.en.md @@ -1,16 +1,5 @@ ## sweet_problem -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). @@ -35,9 +24,7 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { fmt.Println(Sweetproblem(1, 1, 1)) diff --git a/subjects/switchcase.en.md b/subjects/switchcase.en.md index d915a088..a4ebee95 100644 --- a/subjects/switchcase.en.md +++ b/subjects/switchcase.en.md @@ -8,7 +8,7 @@ Write a program that takes a `string` and reverses the case of all its letters. - The result must be followed by a newline (`'\n'`). -- If the number of arguments is different from 1, the program displays a newline (`'\n'`). +- If the number of arguments is different from 1, the program displays nothing. ### Usage @@ -17,6 +17,5 @@ student@ubuntu:~/[[ROOT]]/test$ go build student@ubuntu:~/[[ROOT]]/test$ ./test "SometHingS iS WronG" sOMEThINGs Is wRONg student@ubuntu:~/[[ROOT]]/test$ ./test - student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/twosum.en.md b/subjects/twosum.en.md index 1d8bc286..1d1cbd40 100644 --- a/subjects/twosum.en.md +++ b/subjects/twosum.en.md @@ -1,19 +1,8 @@ ## twosum -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions -Given an array of integers, return indexes of the two numbers such that they add up to a specific target. +Given a slice of integers, return indexes of the two numbers such that they add up to a specific target. If there are more than one solution, return the first one. @@ -31,9 +20,7 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { case1 := []int{1, 2, 3, 4} diff --git a/subjects/volumechanger.en.md b/subjects/volumechanger.en.md index 26380686..4ddd8148 100644 --- a/subjects/volumechanger.en.md +++ b/subjects/volumechanger.en.md @@ -1,16 +1,5 @@ ## volumechanger -## **WARNING! VERY IMPORTANT!** - -For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program: - -This means that: - -- The package needs to be named `package main`. -- The submitted code needs one declared function main(`func main()`) even if empty. -- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. -- Every other rules are obviously the same than for a `program`. - ### Instructions It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). @@ -37,9 +26,7 @@ Here is a possible program to test your function : ```go package main -import ( - "fmt" -) +import "fmt" func main() { fmt.Println(Volumechanger(4, 0)) diff --git a/tests/README.md b/tests/README.md index 495603f0..894e5e4d 100644 --- a/tests/README.md +++ b/tests/README.md @@ -4,18 +4,18 @@ The tests must be in a Docker image that will be executed with (among others) the following options : -- `--read-only` Mount the container's root filesystem as read only -- `--user 1000:1000` Avoid to give root rights -- `--tmpfs /jail:size=200M,noatime,exec,nodev,nosuid,uid=1000,gid=1000,nr_inodes=5k,mode=1700` Mount a 200MB tmpfs directory to create files and run tests -- `--memory 500M` Memory limit of 500 MB -- `--cpus 2.0` Number of CPUs (2 threads) -- `--mount readonly,type=volume,source=student/username,destination=/app/student` The student's code is available in /app/student -- `--env HOME=/jail` Set the only writable folder as home directory -- `--env TMPDIR=/jail` Set the only writable folder as temporary directory -- `--env USERNAME=` Username -- `--env EXERCISE=` Exercise name -- `--env DOMAIN=` Domain name (e.g. gp.ynov-bordeaux.com) -- `--env EXPECTED_FILES=` A space-separated list of required files +- `--read-only` Mount the container's root filesystem as read only +- `--user 1000:1000` Avoid to give root rights +- `--tmpfs /jail:size=200M,noatime,exec,nodev,nosuid,uid=1000,gid=1000,nr_inodes=5k,mode=1700` Mount a 200MB tmpfs directory to create files and run tests +- `--memory 500M` Memory limit of 500 MB +- `--cpus 2.0` Number of CPUs (2 threads) +- `--mount readonly,type=volume,source=student/username,destination=/app/student` The student's code is available in /app/student +- `--env HOME=/jail` Set the only writable folder as home directory +- `--env TMPDIR=/jail` Set the only writable folder as temporary directory +- `--env USERNAME=` Username +- `--env EXERCISE=` Exercise name +- `--env DOMAIN=` Domain name (e.g. gp.ynov-bordeaux.com) +- `--env EXPECTED_FILES=` A space-separated list of required files The username is the Gitea login. No command or arguments are used, the entrypoint has to run the tests. diff --git a/tests/go/abort_test.go b/tests/go/abort_test.go index 773c4956..02b4e090 100644 --- a/tests/go/abort_test.go +++ b/tests/go/abort_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { diff --git a/tests/go/activebits_test.go b/tests/go/activebits_test.go index b70bda34..65ba8d70 100644 --- a/tests/go/activebits_test.go +++ b/tests/go/activebits_test.go @@ -1,17 +1,16 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { args := []int{z01.RandIntBetween(2, 20)} - - for i := 0; i < 20; i++ { - args = append(args, z01.RandIntBetween(2, 20)) - } + args = append(args, z01.MultRandIntBetween(2, 20)...) + args = append(args, z01.MultRandIntBetween(2, 20)...) for _, v := range args { z01.Challenge("ActiveBits", student.ActiveBits, solutions.ActiveBits, v) diff --git a/tests/go/advancedsortwordarr_test.go b/tests/go/advancedsortwordarr_test.go index 5e994e6d..c4600324 100644 --- a/tests/go/advancedsortwordarr_test.go +++ b/tests/go/advancedsortwordarr_test.go @@ -1,8 +1,8 @@ -package student_test +package main import ( "reflect" - "testing" + "strings" "github.com/01-edu/z01" @@ -10,29 +10,25 @@ import ( student "./student" ) -func TestAdvancedSortWordArr(t *testing.T) { - var table [][]string +func main() { + table := [][]string{{"a", "A", "1", "b", "B", "2", "c", "C", "3"}} - for i := 0; i < 10; i++ { - table = append(table, z01.MultRandWords()) - } - - table = append(table, []string{"a", "A", "1", "b", "B", "2", "c", "C", "3"}) + table = append(table, z01.MultMultRandWords()...) for _, org := range table { - //copy for using the solution function + // copy for using the solution function cp_sol := make([]string, len(org)) - //copy for using the student function + // copy for using the student function cp_stu := make([]string, len(org)) copy(cp_sol, org) copy(cp_stu, org) - solutions.AdvancedSortWordArr(cp_sol, solutions.CompArray) - student.AdvancedSortWordArr(cp_stu, solutions.CompArray) + solutions.AdvancedSortWordArr(cp_sol, strings.Compare) + student.AdvancedSortWordArr(cp_stu, strings.Compare) if !reflect.DeepEqual(cp_stu, cp_sol) { - t.Fatalf("%s(%v) == %v instead of %v\n", + z01.Fatalf("%s(%v) == %v instead of %v\n", "AdvancedSortWordArr", org, cp_stu, diff --git a/tests/go/alphacount_test.go b/tests/go/alphacount_test.go index 50842dd3..7ca84653 100644 --- a/tests/go/alphacount_test.go +++ b/tests/go/alphacount_test.go @@ -8,20 +8,17 @@ import ( ) func main() { - var arr []string + table := []string{ + " ", + "Hello 78 World! 4455 /", + } for l := 0; l < 7; l++ { a := z01.RandIntBetween(5, 20) b := z01.RandASCII() - str := z01.RandStr(a, b) - arr = append(arr, str) + table = append(table, z01.RandStr(a, b)) } - arr = append(arr, " ") - - // example from the subject - arr = append(arr, "Hello 78 World! 4455 /") - - for i := 0; i < len(arr); i++ { - z01.Challenge("AlphaCount", student.AlphaCount, solutions.AlphaCount, arr[i]) + for _, arg := range table { + z01.Challenge("AlphaCount", student.AlphaCount, solutions.AlphaCount, arg) } } diff --git a/tests/go/any_test.go b/tests/go/any_test.go index dfb62095..12a66ed3 100644 --- a/tests/go/any_test.go +++ b/tests/go/any_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { diff --git a/tests/go/appendrange_test.go b/tests/go/appendrange_test.go index 0ffb12fc..11479858 100644 --- a/tests/go/appendrange_test.go +++ b/tests/go/appendrange_test.go @@ -12,10 +12,9 @@ func main() { min int max int } - table := []node{} - //15 random pairs of ints for a Valid Range + // 15 random pairs of ints for a Valid Range for i := 0; i < 15; i++ { minVal := z01.RandIntBetween(-10000000, 1000000) gap := z01.RandIntBetween(1, 20) @@ -25,7 +24,8 @@ func main() { } table = append(table, val) } - //15 random pairs of ints with ||invalid range|| + + // 15 random pairs of ints with ||invalid range|| for i := 0; i < 15; i++ { minVal := z01.RandIntBetween(-10000000, 1000000) gap := z01.RandIntBetween(1, 20) diff --git a/tests/go/atoibase_test.go b/tests/go/atoibase_test.go index b1c9c7ef..4a618e0b 100644 --- a/tests/go/atoibase_test.go +++ b/tests/go/atoibase_test.go @@ -3,6 +3,8 @@ package main import ( "github.com/01-edu/z01" + "./base" + solutions "./solutions" student "./student" ) @@ -18,16 +20,16 @@ func main() { // 15 random pairs of string numbers with valid bases for i := 0; i < 15; i++ { - validBaseToInput := solutions.RandomValidBase() + validBaseToInput := base.Valid() val := node{ - s: solutions.RandomStringFromBase(validBaseToInput), + s: base.StringFrom(validBaseToInput), base: validBaseToInput, } table = append(table, val) } // 15 random pairs of string numbers with invalid bases for i := 0; i < 15; i++ { - invalidBaseToInput := solutions.RandomInvalidBase() + invalidBaseToInput := base.Invalid() val := node{ s: "thisinputshouldnotmatter", base: invalidBaseToInput, @@ -45,3 +47,5 @@ func main() { z01.Challenge("AtoiBase", student.AtoiBase, solutions.AtoiBase, arg.s, arg.base) } } + +// TODO: fix base exercises diff --git a/tests/go/base/base.go b/tests/go/base/base.go new file mode 100644 index 00000000..be435289 --- /dev/null +++ b/tests/go/base/base.go @@ -0,0 +1,71 @@ +package base + +import ( + "math/rand" + + "github.com/01-edu/z01" +) + +func Valid() string { + valid := []string{ + "01", + "CHOUMIisDAcat!", + "choumi", + "0123456789", + "abc", + "Zone01", + "0123456789ABCDEF", + "WhoAmI?", + } + i := rand.Intn(len(valid)) + return valid[i] +} + +func Invalid() string { + invalid := []string{ + "0", + "1", + "CHOUMIisdacat!", + "choumiChoumi", + "01234567890", + "abca", + "Zone01Zone01", + "0123456789ABCDEF0", + "WhoAmI?IamWhoIam", + } + i := rand.Intn(len(invalid)) + return invalid[i] +} + +func StringFrom(base string) string { + letters := []rune(base) + size := z01.RandIntBetween(1, 10) + runes := make([]rune, size) + for i := range runes { + runes[i] = letters[rand.Intn(len(letters))] + } + return string(runes) +} + +func ConvertNbr(n int, base string) string { + var result string + length := len(base) + + for n >= length { + result = string(base[(n%length)]) + result + n = n / length + } + result = string(base[n]) + result + + return result +} + +func Convert(nbr, baseFrom, baseTo string) string { + resultIntermediary := AtoiBase(nbr, baseFrom) + + resultFinal := ConvertNbr(resultIntermediary, baseTo) + + return resultFinal +} + +// TODO: fix base exercises diff --git a/tests/go/btreeapplybylevel_test.go b/tests/go/btreeapplybylevel_test.go index 20bd1a6a..294ce80a 100644 --- a/tests/go/btreeapplybylevel_test.go +++ b/tests/go/btreeapplybylevel_test.go @@ -1,14 +1,13 @@ -package student_test +package main import ( "fmt" - "testing" solutions "./solutions" student "./student" ) -func TestBTreeApplyByLevel(t *testing.T) { +func main() { root := &solutions.TreeNode{Data: "04"} rootS := &student.TreeNode{Data: "04"} @@ -19,5 +18,5 @@ func TestBTreeApplyByLevel(t *testing.T) { rootS = student.BTreeInsertData(rootS, v) } - solutions.ChallengeTree(t, solutions.BTreeApplyByLevel, student.BTreeApplyByLevel, root, rootS, fmt.Print) + solutions.ChallengeTree("BTreeApplyByLevel", solutions.BTreeApplyByLevel, student.BTreeApplyByLevel, root, rootS, fmt.Print) } diff --git a/tests/go/btreeapplyinorder_test.go b/tests/go/btreeapplyinorder_test.go index 2915bab8..62e69ee4 100644 --- a/tests/go/btreeapplyinorder_test.go +++ b/tests/go/btreeapplyinorder_test.go @@ -1,19 +1,16 @@ -package student_test +package main import ( "fmt" - "testing" solutions "./solutions" student "./student" ) -func TestBTreeApplyInorder(t *testing.T) { +func main() { root := &solutions.TreeNode{Data: "08"} rootS := &student.TreeNode{Data: "08"} - var pos []string - - pos = append(pos, + pos := []string{ "x", "z", "y", @@ -25,12 +22,12 @@ func TestBTreeApplyInorder(t *testing.T) { "c", "a", "d", - ) + } for _, arg := range pos { root = solutions.BTreeInsertData(root, arg) rootS = student.BTreeInsertData(rootS, arg) } - solutions.ChallengeTree(t, solutions.BTreeApplyInorder, student.BTreeApplyInorder, root, rootS, fmt.Println) + solutions.ChallengeTree("BTreeApplyInorder", solutions.BTreeApplyInorder, student.BTreeApplyInorder, root, rootS, fmt.Println) } diff --git a/tests/go/btreeapplypostorder_test.go b/tests/go/btreeapplypostorder_test.go index cab0b345..36770e11 100644 --- a/tests/go/btreeapplypostorder_test.go +++ b/tests/go/btreeapplypostorder_test.go @@ -1,19 +1,16 @@ -package student_test +package main import ( "fmt" - "testing" solutions "./solutions" student "./student" ) -func TestBTreeApplyPostorder(t *testing.T) { +func main() { root := &solutions.TreeNode{Data: "08"} rootS := &student.TreeNode{Data: "08"} - var pos []string - - pos = append(pos, + pos := []string{ "x", "z", "y", @@ -25,12 +22,12 @@ func TestBTreeApplyPostorder(t *testing.T) { "c", "a", "d", - ) + } for _, arg := range pos { root = solutions.BTreeInsertData(root, arg) rootS = student.BTreeInsertData(rootS, arg) } - solutions.ChallengeTree(t, solutions.BTreeApplyPostorder, student.BTreeApplyPostorder, root, rootS, fmt.Println) + solutions.ChallengeTree("BTreeApplyPostorder", solutions.BTreeApplyPostorder, student.BTreeApplyPostorder, root, rootS, fmt.Println) } diff --git a/tests/go/btreeapplypreorder_test.go b/tests/go/btreeapplypreorder_test.go index c0b32b62..ad9ac054 100644 --- a/tests/go/btreeapplypreorder_test.go +++ b/tests/go/btreeapplypreorder_test.go @@ -1,19 +1,16 @@ -package student_test +package main import ( "fmt" - "testing" solutions "./solutions" student "./student" ) -func TestBTreeApplyPreorder(t *testing.T) { +func main() { root := &solutions.TreeNode{Data: "08"} rootS := &student.TreeNode{Data: "08"} - var pos []string - - pos = append(pos, + pos := []string{ "x", "z", "y", @@ -25,12 +22,12 @@ func TestBTreeApplyPreorder(t *testing.T) { "c", "a", "d", - ) + } for _, arg := range pos { root = solutions.BTreeInsertData(root, arg) rootS = student.BTreeInsertData(rootS, arg) } - solutions.ChallengeTree(t, solutions.BTreeApplyPreorder, student.BTreeApplyPreorder, root, rootS, fmt.Println) + solutions.ChallengeTree("BTreeApplyPreorder", solutions.BTreeApplyPreorder, student.BTreeApplyPreorder, root, rootS, fmt.Println) } diff --git a/tests/go/btreedeletenode_test.go b/tests/go/btreedeletenode_test.go index e9fa7b1b..5c3a391e 100644 --- a/tests/go/btreedeletenode_test.go +++ b/tests/go/btreedeletenode_test.go @@ -1,8 +1,6 @@ -package student_test +package main import ( - "testing" - "github.com/01-edu/z01" solutions "./solutions" @@ -81,9 +79,9 @@ func formatSubTree_delete(root *student.TreeNode, prefix string) string { return res } -func errorMessage_delete(t *testing.T, fn interface{}, deleted string, rootOr, root *solutions.TreeNode, rootS *student.TreeNode) { - t.Fatalf("%s(\n%s, %s\n) ==\n%s instead of\n%s\n", - z01.NameOfFunc(fn), +func errorMessage_delete(fn interface{}, deleted string, rootOr, root *solutions.TreeNode, rootS *student.TreeNode) { + z01.Fatalf("%s(\n%s, %s\n) ==\n%s instead of\n%s\n", + "BTreeDeleteNode", solutions.FormatTree(rootOr), deleted, FormatTree_delete(rootS), @@ -91,15 +89,15 @@ func errorMessage_delete(t *testing.T, fn interface{}, deleted string, rootOr, r ) } -func CompareTrees_delete(t *testing.T, fn interface{}, deleted string, rootOr, root *solutions.TreeNode, rootS *student.TreeNode) { +func CompareTrees_delete(fn interface{}, deleted string, rootOr, root *solutions.TreeNode, rootS *student.TreeNode) { sel := student.BTreeSearchItem(rootS, deleted) if !student.BTreeIsBinary(rootS) || sel != nil { - errorMessage_delete(t, fn, deleted, rootOr, root, rootS) + errorMessage_delete(fn, deleted, rootOr, root, rootS) } } -func TestBTreeDeleteNode(t *testing.T) { +func main() { root := &solutions.TreeNode{Data: "04"} rootS := &student.TreeNode{Data: "04"} rootOr := &solutions.TreeNode{Data: "04"} @@ -118,5 +116,5 @@ func TestBTreeDeleteNode(t *testing.T) { root = solutions.BTreeDeleteNode(root, selected) rootS = student.BTreeDeleteNode(rootS, selectedS) fn := interface{}(solutions.BTreeDeleteNode) - CompareTrees_delete(t, fn, selected.Data, rootOr, root, rootS) + CompareTrees_delete(fn, selected.Data, rootOr, root, rootS) } diff --git a/tests/go/btreeinsertdata_test.go b/tests/go/btreeinsertdata_test.go index 02d10495..bd5604e7 100644 --- a/tests/go/btreeinsertdata_test.go +++ b/tests/go/btreeinsertdata_test.go @@ -1,8 +1,6 @@ -package student_test +package main import ( - "testing" - "github.com/01-edu/z01" solutions "./solutions" @@ -81,9 +79,9 @@ func formatSubTree_insert(root *student.TreeNode, prefix string) string { return res } -func errorMessage_insert(t *testing.T, fn interface{}, inserted string, root *solutions.TreeNode, rootS *student.TreeNode) { - t.Fatalf("%s(\n%s, %s\n) ==\n%s instead of\n%s\n", - z01.NameOfFunc(fn), +func errorMessage_insert(fn interface{}, inserted string, root *solutions.TreeNode, rootS *student.TreeNode) { + z01.Fatalf("%s(\n%s, %s\n) ==\n%s instead of\n%s\n", + "BTreeInsertData", solutions.FormatTree(root), inserted, FormatTree_insert(rootS), @@ -91,16 +89,16 @@ func errorMessage_insert(t *testing.T, fn interface{}, inserted string, root *so ) } -func CompareTrees_insert(t *testing.T, fn interface{}, inserted string, root *solutions.TreeNode, rootS *student.TreeNode) { +func CompareTrees_insert(fn interface{}, inserted string, root *solutions.TreeNode, rootS *student.TreeNode) { solTree := solutions.FormatTree(root) stuTree := FormatTree_insert(rootS) if solTree != stuTree { - errorMessage_insert(t, fn, inserted, root, rootS) + errorMessage_insert(fn, inserted, root, rootS) } } -func TestBTreeInsertData(t *testing.T) { +func main() { root := &solutions.TreeNode{Data: "08"} rootS := &student.TreeNode{Data: "08"} @@ -123,6 +121,6 @@ func TestBTreeInsertData(t *testing.T) { for _, arg := range pos { root = solutions.BTreeInsertData(root, arg) rootS = student.BTreeInsertData(rootS, arg) - CompareTrees_insert(t, fn, arg, root, rootS) + CompareTrees_insert(fn, arg, root, rootS) } } diff --git a/tests/go/btreeisbinary_test.go b/tests/go/btreeisbinary_test.go index c9cce3d0..b7024692 100644 --- a/tests/go/btreeisbinary_test.go +++ b/tests/go/btreeisbinary_test.go @@ -1,8 +1,7 @@ -package student_test +package main import ( "reflect" - "testing" "github.com/01-edu/z01" @@ -14,58 +13,49 @@ func BTreeMinStu(root *student.TreeNode) *student.TreeNode { if root == nil || root.Left == nil { return root } - return BTreeMinStu(root.Left) } -func errorMessage_isbin(t *testing.T, fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) { - t.Fatalf("%s(\n%s\n) == %s instead of %s\n", - z01.NameOfFunc(fn), +func errorMessage_isbin(fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) { + z01.Fatalf("%s(\n%s\n) == %s instead of %s\n", + "BTreeIsBinary", solutions.FormatTree(root), b.Data, a.Data, ) } -func CompareNode_isbin(t *testing.T, fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) { +func CompareNode_isbin(fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) { if a == nil || b == nil { - t.Fatalf("Expected %v instead of %v\n", a, b) - return + z01.Fatalf("Expected %v instead of %v\n", a, b) } - if a.Data != b.Data { - errorMessage_isbin(t, fn, arg1, a, b) + errorMessage_isbin(fn, arg1, a, b) } - - if a.Parent != nil && b.Parent != nil { - if a.Parent.Data != b.Parent.Data { - errorMessage_isbin(t, fn, arg1, a, b) - t.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) - } - } else if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) { - t.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) + if a.Parent != nil && b.Parent != nil && a.Parent.Data != b.Parent.Data { + errorMessage_isbin(fn, arg1, a, b) + z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) } - - if a.Right != nil && b.Right != nil { - if a.Right.Data != b.Right.Data { - errorMessage_isbin(t, fn, arg1, a, b) - t.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) - } - } else if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) { - t.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) + if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) { + z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) } - - if a.Left != nil && b.Left != nil { - if a.Left.Data != b.Left.Data { - errorMessage_isbin(t, fn, arg1, a, b) - t.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) - } - } else if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) { - t.Fatalf("Expected left child value %v instead of %v\n", a, b) + if a.Right != nil && b.Right != nil && a.Right.Data != b.Right.Data { + errorMessage_isbin(fn, arg1, a, b) + z01.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) + } + if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) { + z01.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) + } + if a.Left != nil && b.Left != nil && a.Left.Data != b.Left.Data { + errorMessage_isbin(fn, arg1, a, b) + z01.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) + } + if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) { + z01.Fatalf("Expected left child value %v instead of %v\n", a, b) } } -func CompareReturn_isbin(t *testing.T, fn1, fn2 interface{}, arg1 *solutions.TreeNode, arg2 interface{}) { +func CompareReturn_isbin(fn1, fn2 interface{}, arg1 *solutions.TreeNode, arg2 interface{}) { arar1 := []interface{}{arg1} arar2 := []interface{}{arg2} @@ -75,11 +65,11 @@ func CompareReturn_isbin(t *testing.T, fn1, fn2 interface{}, arg1 *solutions.Tre for i, v := range out1.Results { switch str := v.(type) { case *solutions.TreeNode: - CompareNode_isbin(t, fn1, arg1, str, out2.Results[i].(*student.TreeNode)) + CompareNode_isbin(fn1, arg1, str, out2.Results[i].(*student.TreeNode)) default: if !reflect.DeepEqual(str, out2.Results[i]) { - t.Fatalf("%s(\n%s) == %s instead of %s\n", - z01.NameOfFunc(fn1), + z01.Fatalf("%s(\n%s) == %s instead of %s\n", + "BTreeIsBinary", solutions.FormatTree(arg1), z01.Format(out2.Results...), z01.Format(out1.Results...), @@ -89,7 +79,7 @@ func CompareReturn_isbin(t *testing.T, fn1, fn2 interface{}, arg1 *solutions.Tre } } -func TestBTreeIsBinary(t *testing.T) { +func main() { root := &solutions.TreeNode{Data: "04"} rootS := &student.TreeNode{Data: "04"} @@ -100,11 +90,11 @@ func TestBTreeIsBinary(t *testing.T) { rootS = student.BTreeInsertData(rootS, v) } - CompareReturn_isbin(t, solutions.BTreeIsBinary, student.BTreeIsBinary, root, rootS) + CompareReturn_isbin(solutions.BTreeIsBinary, student.BTreeIsBinary, root, rootS) rootNB := &solutions.TreeNode{Data: "04"} rootNB_stu := &student.TreeNode{Data: "04"} - //Test a non-binarysearch tree + // Test a non-binarysearch tree for _, v := range ins { rootNB = solutions.BTreeInsertData(rootNB, v) rootNB_stu = student.BTreeInsertData(rootNB_stu, v) @@ -116,5 +106,5 @@ func TestBTreeIsBinary(t *testing.T) { min.Left = &solutions.TreeNode{Data: "123"} minStu.Left = &student.TreeNode{Data: "123"} - CompareReturn_isbin(t, solutions.BTreeIsBinary, student.BTreeIsBinary, rootNB, rootNB_stu) + CompareReturn_isbin(solutions.BTreeIsBinary, student.BTreeIsBinary, rootNB, rootNB_stu) } diff --git a/tests/go/btreelevelcount_test.go b/tests/go/btreelevelcount_test.go index d8b794cb..8143ab21 100644 --- a/tests/go/btreelevelcount_test.go +++ b/tests/go/btreelevelcount_test.go @@ -1,8 +1,7 @@ -package student_test +package main import ( "reflect" - "testing" solutions "./solutions" student "./student" @@ -10,54 +9,54 @@ import ( "github.com/01-edu/z01" ) -func errorMessage_level(t *testing.T, fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) { - t.Fatalf("%s(\n%s\n) == %s instead of %s\n", - z01.NameOfFunc(fn), +func errorMessage_level(fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) { + z01.Fatalf("%s(\n%s\n) == %s instead of %s\n", + "BTreeLevelCount", solutions.FormatTree(root), b.Data, a.Data, ) } -func CompareNode_level(t *testing.T, fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) { +func CompareNode_level(fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) { if a == nil || b == nil { - t.Fatalf("Expected %v instead of %v\n", a, b) + z01.Fatalf("Expected %v instead of %v\n", a, b) return } if a.Data != b.Data { - errorMessage_level(t, fn, arg1, a, b) + errorMessage_level(fn, arg1, a, b) } if a.Parent != nil && b.Parent != nil { if a.Parent.Data != b.Parent.Data { - errorMessage_level(t, fn, arg1, a, b) - t.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) + errorMessage_level(fn, arg1, a, b) + z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) } } else if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) { - t.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) + z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) } if a.Right != nil && b.Right != nil { if a.Right.Data != b.Right.Data { - errorMessage_level(t, fn, arg1, a, b) - t.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) + errorMessage_level(fn, arg1, a, b) + z01.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) } } else if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) { - t.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) + z01.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) } if a.Left != nil && b.Left != nil { if a.Left.Data != b.Left.Data { - errorMessage_level(t, fn, arg1, a, b) - t.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) + errorMessage_level(fn, arg1, a, b) + z01.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) } } else if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) { - t.Fatalf("Expected left child value %v instead of %v\n", a, b) + z01.Fatalf("Expected left child value %v instead of %v\n", a, b) } } -func CompareReturn_level(t *testing.T, fn1, fn2 interface{}, arg1 *solutions.TreeNode, arg2 interface{}) { +func CompareReturn_level(fn1, fn2 interface{}, arg1 *solutions.TreeNode, arg2 interface{}) { arar1 := []interface{}{arg1} arar2 := []interface{}{arg2} @@ -67,11 +66,11 @@ func CompareReturn_level(t *testing.T, fn1, fn2 interface{}, arg1 *solutions.Tre for i, v := range out1.Results { switch str := v.(type) { case *solutions.TreeNode: - CompareNode_level(t, fn1, arg1, str, out2.Results[i].(*student.TreeNode)) + CompareNode_level(fn1, arg1, str, out2.Results[i].(*student.TreeNode)) default: if !reflect.DeepEqual(str, out2.Results[i]) { - t.Fatalf("%s(\n%s) == %s instead of %s\n", - z01.NameOfFunc(fn1), + z01.Fatalf("%s(\n%s) == %s instead of %s\n", + "BTreeLevelCount", solutions.FormatTree(arg1), z01.Format(out2.Results...), z01.Format(out1.Results...), @@ -81,7 +80,7 @@ func CompareReturn_level(t *testing.T, fn1, fn2 interface{}, arg1 *solutions.Tre } } -func TestBTreeLevelCount(t *testing.T) { +func main() { root := &solutions.TreeNode{Data: "04"} rootS := &student.TreeNode{Data: "04"} @@ -90,6 +89,6 @@ func TestBTreeLevelCount(t *testing.T) { for _, v := range ins { root = solutions.BTreeInsertData(root, v) rootS = student.BTreeInsertData(rootS, v) - CompareReturn_level(t, solutions.BTreeLevelCount, student.BTreeLevelCount, root, rootS) + CompareReturn_level(solutions.BTreeLevelCount, student.BTreeLevelCount, root, rootS) } } diff --git a/tests/go/btreemax_test.go b/tests/go/btreemax_test.go index 0622c935..4d010e30 100644 --- a/tests/go/btreemax_test.go +++ b/tests/go/btreemax_test.go @@ -1,8 +1,7 @@ -package student_test +package main import ( "reflect" - "testing" solutions "./solutions" student "./student" @@ -10,54 +9,54 @@ import ( "github.com/01-edu/z01" ) -func errorMessage_max(t *testing.T, fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) { - t.Fatalf("%s(\n%s) == %s instead of %s\n", - z01.NameOfFunc(fn), +func errorMessage_max(fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) { + z01.Fatalf("%s(\n%s) == %s instead of %s\n", + "BTreeMax", solutions.FormatTree(root), b.Data, a.Data, ) } -func CompareNode_max(t *testing.T, fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) { +func CompareNode_max(fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) { if a == nil || b == nil { - t.Fatalf("Expected %v instead of %v\n", a, b) + z01.Fatalf("Expected %v instead of %v\n", a, b) return } if a.Data != b.Data { - errorMessage_max(t, fn, arg1, a, b) + errorMessage_max(fn, arg1, a, b) } if a.Parent != nil && b.Parent != nil { if a.Parent.Data != b.Parent.Data { - errorMessage_max(t, fn, arg1, a, b) - t.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) + errorMessage_max(fn, arg1, a, b) + z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) } } else if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) { - t.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) + z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) } if a.Right != nil && b.Right != nil { if a.Right.Data != b.Right.Data { - errorMessage_max(t, fn, arg1, a, b) - t.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) + errorMessage_max(fn, arg1, a, b) + z01.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) } } else if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) { - t.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) + z01.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) } if a.Left != nil && b.Left != nil { if a.Left.Data != b.Left.Data { - errorMessage_max(t, fn, arg1, a, b) - t.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) + errorMessage_max(fn, arg1, a, b) + z01.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) } } else if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) { - t.Fatalf("Expected left child value %v instead of %v\n", a, b) + z01.Fatalf("Expected left child value %v instead of %v\n", a, b) } } -func CompareReturn_max(t *testing.T, fn1, fn2 interface{}, arg1 *solutions.TreeNode, arg2 interface{}) { +func CompareReturn_max(fn1, fn2 interface{}, arg1 *solutions.TreeNode, arg2 interface{}) { arar1 := []interface{}{arg1} arar2 := []interface{}{arg2} @@ -67,11 +66,11 @@ func CompareReturn_max(t *testing.T, fn1, fn2 interface{}, arg1 *solutions.TreeN for i, v := range out1.Results { switch str := v.(type) { case *solutions.TreeNode: - CompareNode_max(t, fn1, arg1, str, out2.Results[i].(*student.TreeNode)) + CompareNode_max(fn1, arg1, str, out2.Results[i].(*student.TreeNode)) default: if !reflect.DeepEqual(str, out2.Results[i]) { - t.Fatalf("%s(\n%s) == %s instead of\n %s\n", - z01.NameOfFunc(fn1), + z01.Fatalf("%s(\n%s) == %s instead of\n %s\n", + "BTreeMax", solutions.FormatTree(arg1), z01.Format(out2.Results...), z01.Format(out1.Results...), @@ -81,7 +80,7 @@ func CompareReturn_max(t *testing.T, fn1, fn2 interface{}, arg1 *solutions.TreeN } } -func TestBTreeMax(t *testing.T) { +func main() { root := &solutions.TreeNode{Data: "04"} rootS := &student.TreeNode{Data: "04"} @@ -92,5 +91,5 @@ func TestBTreeMax(t *testing.T) { rootS = student.BTreeInsertData(rootS, v) } - CompareReturn_max(t, solutions.BTreeMax, student.BTreeMax, root, rootS) + CompareReturn_max(solutions.BTreeMax, student.BTreeMax, root, rootS) } diff --git a/tests/go/btreemin_test.go b/tests/go/btreemin_test.go index 1478c77c..16dbe062 100644 --- a/tests/go/btreemin_test.go +++ b/tests/go/btreemin_test.go @@ -1,8 +1,7 @@ -package student_test +package main import ( "reflect" - "testing" solutions "./solutions" student "./student" @@ -10,54 +9,54 @@ import ( "github.com/01-edu/z01" ) -func errorMessage_min(t *testing.T, fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) { - t.Fatalf("%s(\n%s) == %s instead of %s\n", - z01.NameOfFunc(fn), +func errorMessage_min(fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode) { + z01.Fatalf("%s(\n%s) == %s instead of %s\n", + "BTreeMin", solutions.FormatTree(root), b.Data, a.Data, ) } -func CompareNode_min(t *testing.T, fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) { +func CompareNode_min(fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode) { if a == nil || b == nil { - t.Fatalf("Expected %v instead of %v\n", a, b) + z01.Fatalf("Expected %v instead of %v\n", a, b) return } if a.Data != b.Data { - errorMessage_min(t, fn, arg1, a, b) + errorMessage_min(fn, arg1, a, b) } if a.Parent != nil && b.Parent != nil { if a.Parent.Data != b.Parent.Data { - errorMessage_min(t, fn, arg1, a, b) - t.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) + errorMessage_min(fn, arg1, a, b) + z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) } } else if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) { - t.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) + z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) } if a.Right != nil && b.Right != nil { if a.Right.Data != b.Right.Data { - errorMessage_min(t, fn, arg1, a, b) - t.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) + errorMessage_min(fn, arg1, a, b) + z01.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) } } else if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) { - t.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) + z01.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) } if a.Left != nil && b.Left != nil { if a.Left.Data != b.Left.Data { - errorMessage_min(t, fn, arg1, a, b) - t.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) + errorMessage_min(fn, arg1, a, b) + z01.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) } } else if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) { - t.Fatalf("Expected left child value %v instead of %v\n", a, b) + z01.Fatalf("Expected left child value %v instead of %v\n", a, b) } } -func CompareReturn_min(t *testing.T, fn1, fn2, arg1, arg2 interface{}) { +func CompareReturn_min(fn1, fn2, arg1, arg2 interface{}) { arar1 := []interface{}{arg1} arar2 := []interface{}{arg2} @@ -67,11 +66,11 @@ func CompareReturn_min(t *testing.T, fn1, fn2, arg1, arg2 interface{}) { for i, v := range out1.Results { switch str := v.(type) { case *solutions.TreeNode: - CompareNode_min(t, fn1, arg1.(*solutions.TreeNode), str, out2.Results[i].(*student.TreeNode)) + CompareNode_min(fn1, arg1.(*solutions.TreeNode), str, out2.Results[i].(*student.TreeNode)) default: if !reflect.DeepEqual(str, out2.Results[i]) { - t.Fatalf("%s(%s) == %s instead of %s\n", - z01.NameOfFunc(fn1), + z01.Fatalf("%s(%s) == %s instead of %s\n", + "BTreeMin", z01.Format(arg1), z01.Format(out2.Results...), z01.Format(out1.Results...), @@ -81,7 +80,7 @@ func CompareReturn_min(t *testing.T, fn1, fn2, arg1, arg2 interface{}) { } } -func TestBTreeMin(t *testing.T) { +func main() { root := &solutions.TreeNode{Data: "04"} rootS := &student.TreeNode{Data: "04"} @@ -92,5 +91,5 @@ func TestBTreeMin(t *testing.T) { rootS = student.BTreeInsertData(rootS, v) } - CompareReturn_min(t, solutions.BTreeMin, student.BTreeMin, root, rootS) + CompareReturn_min(solutions.BTreeMin, student.BTreeMin, root, rootS) } diff --git a/tests/go/btreerotateleft_test.go b/tests/go/btreerotateleft_test.go deleted file mode 100644 index 983fb301..00000000 --- a/tests/go/btreerotateleft_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package student_test - -import ( - "reflect" - "testing" - - "github.com/01-edu/z01" - - solutions "./solutions" - student "./student" -) - -func parentListRotLeft(root *student.TreeNode) string { - if root == nil { - return "" - } - - var parent string - - if root.Parent == nil { - parent = "nil" - } else { - parent = root.Parent.Data - } - - r := "Node: " + root.Data + " Parent: " + parent + "\n" - r += parentListRotLeft(root.Left) + parentListRotLeft(root.Right) - return r -} - -func FormatTree_rotleft(root *student.TreeNode) string { - if root == nil { - return "" - } - res := root.Data + "\n" - res += formatSubTree_rotleft(root, "") - return res -} - -func formatSubTree_rotleft(root *student.TreeNode, prefix string) string { - if root == nil { - return "" - } - - var res string - - hasLeft := root.Left != nil - hasRight := root.Right != nil - - if !hasLeft && !hasRight { - return res - } - - res += prefix - if hasLeft && hasRight { - res += "├── " - } - - if !hasLeft && hasRight { - res += "└── " - } - - if hasRight { - printStrand := (hasLeft && hasRight && (root.Right.Right != nil || root.Right.Left != nil)) - newPrefix := prefix - if printStrand { - newPrefix += "│ " - } else { - newPrefix += " " - } - res += root.Right.Data + "\n" - res += formatSubTree_rotleft(root.Right, newPrefix) - } - - if hasLeft { - if hasRight { - res += prefix - } - res += "└── " + root.Left.Data + "\n" - res += formatSubTree_rotleft(root.Left, prefix+" ") - } - return res -} - -func errorMessage_rotleft(t *testing.T, fn interface{}, rootOr, root *solutions.TreeNode, rootS *student.TreeNode) { - t.Fatalf("%s(\n%s\n)\n == \n%s instead of \n%s\n", - z01.NameOfFunc(fn), - solutions.FormatTree(rootOr), - FormatTree_rotleft(rootS), - solutions.FormatTree(root), - ) -} - -func CompareTreesRotLeft(t *testing.T, fn interface{}, root, rootA *solutions.TreeNode, rootAS *student.TreeNode) { - parentSol := solutions.ParentList(rootA) - parentStu := parentListRotLeft(rootAS) - solTree := solutions.FormatTree(root) - if parentSol != parentStu { - t.Fatalf("Tree:\n%s\nExpected\n%s instead of\n%s\n", solTree, parentSol, parentStu) - } -} - -func CompareNode_rotleft(t *testing.T, fn interface{}, rootOr, root *solutions.TreeNode, rootS *student.TreeNode) { - solTree := solutions.FormatTree(root) - stuTree := FormatTree_rotleft(rootS) - - if solTree != stuTree { - errorMessage_rotleft(t, fn, rootOr, root, rootS) - } -} - -func CompareReturn_rotleft(t *testing.T, fn1, fn2, rootOr, arg1, arg2 interface{}) { - arar1 := []interface{}{arg1} - arar2 := []interface{}{arg2} - - out1 := z01.Monitor(fn1, arar1) - out2 := z01.Monitor(fn2, arar2) - - for i, v := range out1.Results { - switch str := v.(type) { - case *solutions.TreeNode: - CompareNode_rotleft(t, fn1, rootOr.(*solutions.TreeNode), str, out2.Results[i].(*student.TreeNode)) - default: - if !reflect.DeepEqual(str, out2.Results[i]) { - t.Fatalf("%s(%s) == %s instead of %s\n", - z01.NameOfFunc(fn1), - z01.Format(arg1), - z01.Format(out2.Results...), - z01.Format(out1.Results...), - ) - } - } - } -} - -func TestBTreeRotateLeft(t *testing.T) { - root := &solutions.TreeNode{Data: "04"} - rootOr := &solutions.TreeNode{Data: "04"} - rootS := &student.TreeNode{Data: "04"} - - ins := []string{"01", "07", "05", "12", "02", "03", "10"} - - for _, v := range ins { - root = solutions.BTreeInsertData(root, v) - rootS = student.BTreeInsertData(rootS, v) - rootOr = solutions.BTreeInsertData(rootOr, v) - } - - fn := interface{}(solutions.BTreeRotateLeft) - CompareReturn_rotleft(t, fn, student.BTreeRotateLeft, rootOr, root, rootS) - CompareTreesRotLeft(t, fn, rootOr, root, rootS) -} diff --git a/tests/go/btreerotateright_test.go b/tests/go/btreerotateright_test.go deleted file mode 100644 index 74f241c7..00000000 --- a/tests/go/btreerotateright_test.go +++ /dev/null @@ -1,151 +0,0 @@ -package student_test - -import ( - "reflect" - "testing" - - "github.com/01-edu/z01" - - solutions "./solutions" - student "./student" -) - -func parentListRotRight(root *student.TreeNode) string { - if root == nil { - return "" - } - - var parent string - - if root.Parent == nil { - parent = "nil" - } else { - parent = root.Parent.Data - } - - r := "Node: " + root.Data + " Parent: " + parent + "\n" - r += parentListRotRight(root.Left) + parentListRotRight(root.Right) - return r -} - -func CompareTreesRotRight(t *testing.T, fn interface{}, root, rootA *solutions.TreeNode, rootAS *student.TreeNode) { - parentSol := solutions.ParentList(rootA) - parentStu := parentListRotRight(rootAS) - solTree := solutions.FormatTree(root) - if parentSol != parentStu { - t.Fatalf("Tree:\n%s\nExpected\n%s instead of\n%s\n", solTree, parentSol, parentStu) - } -} - -func FormatTree_rotright(root *student.TreeNode) string { - if root == nil { - return "" - } - res := root.Data + "\n" - res += formatSubTree_rotright(root, "") - return res -} - -func formatSubTree_rotright(root *student.TreeNode, prefix string) string { - if root == nil { - return "" - } - - var res string - - hasLeft := root.Left != nil - hasRight := root.Right != nil - - if !hasLeft && !hasRight { - return res - } - - res += prefix - if hasLeft && hasRight { - res += "├── " - } - - if !hasLeft && hasRight { - res += "└── " - } - - if hasRight { - printStrand := (hasLeft && hasRight && (root.Right.Right != nil || root.Right.Left != nil)) - newPrefix := prefix - if printStrand { - newPrefix += "│ " - } else { - newPrefix += " " - } - res += root.Right.Data + "\n" - res += formatSubTree_rotright(root.Right, newPrefix) - } - - if hasLeft { - if hasRight { - res += prefix - } - res += "└── " + root.Left.Data + "\n" - res += formatSubTree_rotright(root.Left, prefix+" ") - } - return res -} - -func errorMessage_rotright(t *testing.T, fn interface{}, rootOr, root *solutions.TreeNode, rootS *student.TreeNode) { - t.Fatalf("%s(\n%s\n)\n == \n%s instead of \n%s\n", - z01.NameOfFunc(fn), - solutions.FormatTree(rootOr), - FormatTree_rotright(rootS), - solutions.FormatTree(root), - ) -} - -func CompareNode_rotright(t *testing.T, fn interface{}, rootOr, root *solutions.TreeNode, rootS *student.TreeNode) { - solTree := solutions.FormatTree(root) - stuTree := FormatTree_rotright(rootS) - - if solTree != stuTree { - errorMessage_rotright(t, fn, rootOr, root, rootS) - } -} - -func CompareReturn_rotright(t *testing.T, fn1, fn2, rootOr, arg1, arg2 interface{}) { - arar1 := []interface{}{arg1} - arar2 := []interface{}{arg2} - - out1 := z01.Monitor(fn1, arar1) - out2 := z01.Monitor(fn2, arar2) - - for i, v := range out1.Results { - switch str := v.(type) { - case *solutions.TreeNode: - CompareNode_rotright(t, fn1, rootOr.(*solutions.TreeNode), str, out2.Results[i].(*student.TreeNode)) - default: - if !reflect.DeepEqual(str, out2.Results[i]) { - t.Fatalf("%s(%s) == %s instead of %s\n", - z01.NameOfFunc(fn1), - z01.Format(arg1), - z01.Format(out2.Results...), - z01.Format(out1.Results...), - ) - } - } - } -} - -func TestBTreeRotateRight(t *testing.T) { - root := &solutions.TreeNode{Data: "04"} - rootOr := &solutions.TreeNode{Data: "04"} - rootS := &student.TreeNode{Data: "04"} - - ins := []string{"01", "07", "05", "12", "02", "03", "10"} - - for _, v := range ins { - root = solutions.BTreeInsertData(root, v) - rootS = student.BTreeInsertData(rootS, v) - rootOr = solutions.BTreeInsertData(rootOr, v) - } - fn := interface{}(solutions.BTreeRotateRight) - CompareReturn_rotright(t, fn, student.BTreeRotateRight, rootOr, root, rootS) - CompareTreesRotRight(t, fn, rootOr, root, rootS) -} diff --git a/tests/go/btreesearchitem_test.go b/tests/go/btreesearchitem_test.go index ed73acca..9404b5ed 100644 --- a/tests/go/btreesearchitem_test.go +++ b/tests/go/btreesearchitem_test.go @@ -1,8 +1,6 @@ -package student_test +package main import ( - "testing" - "github.com/01-edu/z01" "fmt" @@ -11,10 +9,10 @@ import ( student "./student" ) -func errorMessage_search(t *testing.T, fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode, +func errorMessage_search(fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode, seaVal string) { - t.Fatalf("%s(\n%s\n, %s) == %s instead of %s\n", - z01.NameOfFunc(fn), + z01.Fatalf("%s(\n%s\n, %s) == %s instead of %s\n", + "BTreeSearchItem", solutions.FormatTree(root), seaVal, b.Data, @@ -22,53 +20,53 @@ func errorMessage_search(t *testing.T, fn interface{}, root, a *solutions.TreeNo ) } -func CompareNode_search(t *testing.T, fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode, +func CompareNode_search(fn interface{}, arg1, a *solutions.TreeNode, b *student.TreeNode, seaVal string) { if a == nil && b == nil { return } if (a == nil && b != nil) || (b == nil && a != nil) { - t.Fatalf("Expected %v instead of %v\n", a, b) + z01.Fatalf("Expected %v instead of %v\n", a, b) return } if a.Data != b.Data { - errorMessage_search(t, fn, arg1, a, b, seaVal) + errorMessage_search(fn, arg1, a, b, seaVal) } if a.Parent != nil && b.Parent != nil { if a.Parent.Data != b.Parent.Data { - errorMessage_search(t, fn, arg1, a, b, seaVal) - t.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) + errorMessage_search(fn, arg1, a, b, seaVal) + z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data) fmt.Println("Parent.Data", a.Parent.Data, b.Parent.Data) } } else if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) { - t.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) + z01.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent) } if a.Right != nil && b.Right != nil { if a.Right.Data != b.Right.Data { - errorMessage_search(t, fn, arg1, a, b, seaVal) - t.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) + errorMessage_search(fn, arg1, a, b, seaVal) + z01.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data) fmt.Println("Right.Data", a.Right.Data, b.Right.Data) } } else if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) { - t.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) + z01.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right) } if a.Left != nil && b.Left != nil { if a.Left.Data != b.Left.Data { - errorMessage_search(t, fn, arg1, a, b, seaVal) - t.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) + errorMessage_search(fn, arg1, a, b, seaVal) + z01.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left) fmt.Println("Left.Data", a.Left.Data, b.Left.Data) } } else if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) { - t.Fatalf("Expected left child value %v instead of %v\n", a, b) + z01.Fatalf("Expected left child value %v instead of %v\n", a, b) } } -func TestBTreeSearchItem(t *testing.T) { +func main() { root := &solutions.TreeNode{Data: "04"} rootS := &student.TreeNode{Data: "04"} @@ -84,6 +82,6 @@ func TestBTreeSearchItem(t *testing.T) { for _, v := range ins { selectedSol := solutions.BTreeSearchItem(root, v) selectedStu := student.BTreeSearchItem(rootS, v) - CompareNode_search(t, fn, root, selectedSol, selectedStu, v) + CompareNode_search(fn, root, selectedSol, selectedStu, v) } } diff --git a/tests/go/btreetransplant_test.go b/tests/go/btreetransplant_test.go index c9cecab6..aa31f11d 100644 --- a/tests/go/btreetransplant_test.go +++ b/tests/go/btreetransplant_test.go @@ -1,8 +1,6 @@ -package student_test +package main import ( - "testing" - "github.com/01-edu/z01" "fmt" @@ -83,9 +81,9 @@ func formatSubTree_transp(root *student.TreeNode, prefix string) string { return res } -func errorMessage_transp(t *testing.T, fn interface{}, root, sel, repl *solutions.TreeNode, rootA *solutions.TreeNode, rootAS *student.TreeNode) { - t.Fatalf("%s(\nRoot:\n %s, Selected:\n%s, Replacement:\n%s\n) ==\n%s instead of\n%s\n", - z01.NameOfFunc(fn), +func errorMessage_transp(fn interface{}, root, sel, repl *solutions.TreeNode, rootA *solutions.TreeNode, rootAS *student.TreeNode) { + z01.Fatalf("%s(\nRoot:\n %s, Selected:\n%s, Replacement:\n%s\n) ==\n%s instead of\n%s\n", + "BTreeTransplant", solutions.FormatTree(root), solutions.FormatTree(sel), solutions.FormatTree(repl), @@ -94,23 +92,23 @@ func errorMessage_transp(t *testing.T, fn interface{}, root, sel, repl *solution ) } -func CompareTrees_transp(t *testing.T, fn interface{}, root, sel, repl *solutions.TreeNode, rootA *solutions.TreeNode, rootAS *student.TreeNode) { +func CompareTrees_transp(fn interface{}, root, sel, repl *solutions.TreeNode, rootA *solutions.TreeNode, rootAS *student.TreeNode) { solTree := solutions.FormatTree(rootA) stuTree := FormatTree_transp(rootAS) if solTree != stuTree { - errorMessage_transp(t, fn, root, sel, repl, rootA, rootAS) + errorMessage_transp(fn, root, sel, repl, rootA, rootAS) } parentSol := solutions.ParentList(rootA) parentStu := parentListTransp(rootAS) if parentSol != parentStu { fmt.Println("Tree:\n", solTree) - t.Fatalf("Expected\n%s instead of\n%s\n", parentSol, parentStu) + z01.Fatalf("Expected\n%s instead of\n%s\n", parentSol, parentStu) } } -func TestBTreeTransplant(t *testing.T) { +func main() { root := &solutions.TreeNode{Data: "04"} rootS := &student.TreeNode{Data: "04"} rootOr := &solutions.TreeNode{Data: "04"} @@ -139,5 +137,5 @@ func TestBTreeTransplant(t *testing.T) { rootS = student.BTreeTransplant(rootS, selectedS, replacementS) fn := interface{}(solutions.BTreeTransplant) - CompareTrees_transp(t, fn, rootOr, selected, replacement, root, rootS) + CompareTrees_transp(fn, rootOr, selected, replacement, root, rootS) } diff --git a/tests/go/collatzcountdown_test.go b/tests/go/collatzcountdown_test.go index 02fa4fd7..99e1adce 100644 --- a/tests/go/collatzcountdown_test.go +++ b/tests/go/collatzcountdown_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { diff --git a/tests/go/compact_test.go b/tests/go/compact_test.go index 1c90959c..10ad7ba9 100644 --- a/tests/go/compact_test.go +++ b/tests/go/compact_test.go @@ -1,8 +1,7 @@ -package student_test +package main import ( "reflect" - "testing" "github.com/01-edu/z01" @@ -10,8 +9,8 @@ import ( student "./student" ) -func TestCompact(t *testing.T) { - var arg [][]string +func main() { + arg := [][]string{{"hello", "", "hi", "", "salut", "", ""}} for i := 0; i < 20; i++ { n := z01.RandIntBetween(5, 20) // random size of the slice @@ -28,8 +27,6 @@ func TestCompact(t *testing.T) { arg = append(arg, orig) } - arg = append(arg, []string{"hello", "", "hi", "", "salut", "", ""}) - for _, v := range arg { sli_sol := make([]string, len(arg)) // slice to apply the solution function sli_stu := make([]string, len(arg)) // slice to apply the student function @@ -41,14 +38,14 @@ func TestCompact(t *testing.T) { stu_size := student.Compact(&sli_stu) if !reflect.DeepEqual(sli_stu, sli_sol) { - t.Fatalf("Produced slice: %v, instead of %v\n", + z01.Fatalf("Produced slice: %v, instead of %v\n", sli_stu, sli_sol, ) } if sol_size != stu_size { - t.Fatalf("%s(%v) == %v instead of %v\n", + z01.Fatalf("%s(%v) == %v instead of %v\n", "Compact", v, sli_stu, diff --git a/tests/go/concatparams_test.go b/tests/go/concatparams_test.go index 226497da..3186094a 100644 --- a/tests/go/concatparams_test.go +++ b/tests/go/concatparams_test.go @@ -8,18 +8,12 @@ import ( ) func main() { - table := [][]string{} - //30 random slice of strings + table := [][]string{{"Hello", "how", "are", "you?"}} + // 30 random slice of strings for i := 0; i < 30; i++ { - val := z01.MultRandASCII() - table = append(table, val) + table = append(table, z01.MultRandASCII()) } - - table = append(table, - []string{"Hello", "how", "are", "you?"}, - ) - for _, arg := range table { z01.Challenge("ConcatParams", student.ConcatParams, solutions.ConcatParams, arg) } diff --git a/tests/go/convertbase_test.go b/tests/go/convertbase_test.go index a45f7e76..e997b136 100644 --- a/tests/go/convertbase_test.go +++ b/tests/go/convertbase_test.go @@ -3,6 +3,8 @@ package main import ( "github.com/01-edu/z01" + "./base" + solutions "./solutions" student "./student" ) @@ -16,9 +18,9 @@ func main() { table := []node{} for i := 0; i < 30; i++ { - validBaseToInput1 := solutions.RandomValidBase() - validBaseToInput2 := solutions.RandomValidBase() - str := solutions.ConvertNbrBase(z01.RandIntBetween(0, 1000000), validBaseToInput1) + validBaseToInput1 := base.Valid() + validBaseToInput2 := base.Valid() + str := base.ConvertNbr(z01.RandIntBetween(0, 1000000), validBaseToInput1) val := node{ nbr: str, baseFrom: validBaseToInput1, diff --git a/tests/go/createelem_test.go b/tests/go/createelem_test.go index 4e630046..79e624a3 100644 --- a/tests/go/createelem_test.go +++ b/tests/go/createelem_test.go @@ -1,50 +1,36 @@ -package student_test +package main import ( - "testing" + "github.com/01-edu/z01" solution "./solutions" student "./student" - "github.com/01-edu/z01" ) -//the structs from the other packages -//struct just for the first exercise +// the structs from the other packages +// struct just for the first exercise type NodeF = student.Node type NodeFS = solution.Node -//exercise 1 -//simple struct, just insert a element in the struct -func TestCreateElem(t *testing.T) { - n := &NodeFS{} - n1 := &NodeF{} +// simple struct, just insert a element in the struct +func main() { + n1 := &NodeFS{} + n2 := &NodeF{} - type nodeTest struct { - data []int - } - - table := []nodeTest{} + table := [][]int{{{132423}}} for i := 0; i < 5; i++ { - val := nodeTest{ - data: z01.MultRandIntBetween(-1000000, 10000000), - } - table = append(table, val) + table = append(table, z01.MultRandIntBetween(-1000000, 10000000)) } - table = append(table, - nodeTest{ - data: []int{132423}, - }, - ) - for _, arg := range table { - for i := 0; i < len(arg.data); i++ { - solution.CreateElem(n, arg.data[i]) - student.CreateElem(n1, arg.data[i]) + for _, items := range table { + for _, item := range items { + solution.CreateElem(n1, item) + student.CreateElem(n2, item) } - if n.Data != n1.Data { - t.Fatalf("CreateElem == %d instead of %d\n", n, n1) + if n1.Data != n2.Data { + z01.Fatalf("CreateElem == %d instead of %d\n", n1, n2) } } } diff --git a/tests/go/divmod_test.go b/tests/go/divmod_test.go index 23887369..a028cef3 100644 --- a/tests/go/divmod_test.go +++ b/tests/go/divmod_test.go @@ -1,14 +1,12 @@ -package student_test +package main import ( - "testing" - "github.com/01-edu/z01" student "./student" ) -func TestDivMod(t *testing.T) { +func main() { i := 0 for i < z01.SliceLen { a := z01.RandInt() @@ -17,10 +15,10 @@ func TestDivMod(t *testing.T) { var mod int student.DivMod(a, b, &div, &mod) if div != a/b { - t.Fatalf("DivMod(%d, %d, &div, &mod), div == %d instead of %d", a, b, div, a/b) + z01.Fatalf("DivMod(%d, %d, &div, &mod), div == %d instead of %d", a, b, div, a/b) } if mod != a%b { - t.Fatalf("DivMod(%d, %d, &div, &mod), mod == %d instead of %d", a, b, mod, a%b) + z01.Fatalf("DivMod(%d, %d, &div, &mod), mod == %d instead of %d", a, b, mod, a%b) } i++ } diff --git a/tests/go/enigma_test.go b/tests/go/enigma_test.go index a285a50f..3d58f610 100644 --- a/tests/go/enigma_test.go +++ b/tests/go/enigma_test.go @@ -1,18 +1,14 @@ -package student_test +package main import ( - "testing" + "github.com/01-edu/z01" solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) -func TestEnigma(t *testing.T) { - args := []int{z01.RandIntBetween(2, 20)} - for i := 0; i < 3; i++ { - args = append(args, z01.RandIntBetween(2, 20)) - } +func main() { + args := append([]int, z01.MultRandIntBetween(2, 20)...) aval := args[0] x := args[0] @@ -45,27 +41,29 @@ func TestEnigma(t *testing.T) { solutions.Decript(a, b, c, d) if aval != ***a { - t.Fatalf("Expected ***a = %d instead of %d\n", + z01.Fatalf("Expected ***a = %d instead of %d\n", aval, ***a, ) } if bval != *b { - t.Fatalf("Expected *b = %d instead of %d\n", + z01.Fatalf("Expected *b = %d instead of %d\n", bval, *b, ) } if cval != *******c { - t.Fatalf("Expected *******c = %d instead of %d\n", + z01.Fatalf("Expected *******c = %d instead of %d\n", cval, *******c, ) } if dval != ****d { - t.Fatalf("Expected ****d = %d instead of %d\n", + z01.Fatalf("Expected ****d = %d instead of %d\n", dval, ****d, ) } } + +// TODO: remove all those pointers... diff --git a/tests/go/entrypoint.sh b/tests/go/entrypoint.sh index df6388e9..69e2ba2e 100644 --- a/tests/go/entrypoint.sh +++ b/tests/go/entrypoint.sh @@ -1,23 +1,23 @@ #!/bin/sh -# Unofficial Bash Strict Mode -set -euo pipefail +set -o errexit +set -o pipefail IFS=' ' cp -rT /app /jail -if test -v EXPECTED_FILES; then - echo -n "Formatting... " +if test "$EXPECTED_FILES"; then + echo -n 'Formatting (with `goimports -d .`) ... ' cd /jail/student - s=$(goimports -d $(echo $EXPECTED_FILES | fmt -w1 | grep '\.go$')) + s=$(goimports -d .) if test "$s"; then echo echo "$s" exit 1 fi echo OK - if test -v ALLOWED_FUNCTIONS; then + if test "$ALLOWED_FUNCTIONS"; then rc "$EXPECTED_FILES" $ALLOWED_FUNCTIONS fi fi @@ -31,5 +31,4 @@ fi # TODO: maybe change btree exercises so that they work without student code and then delete this line find . -name '*_test.go' ! -name ${EXERCISE}_test.go -delete - -go test -failfast -run=\(?i\)test${EXERCISE} +go test -failfast '-run=(?i)'test${EXERCISE} diff --git a/tests/go/foreach_test.go b/tests/go/foreach_test.go index 6a4eab21..cfa277c2 100644 --- a/tests/go/foreach_test.go +++ b/tests/go/foreach_test.go @@ -1,39 +1,52 @@ package main import ( + "fmt" + "github.com/01-edu/z01" solutions "./solutions" student "./student" ) +func add0(i int) { + fmt.Println(i) +} +func add1(i int) { + fmt.Println(i + 1) +} +func add2(i int) { + fmt.Println(i + 2) +} +func add3(i int) { + fmt.Println(i + 3) +} + func main() { - functionsArray := []func(int){solutions.Add0, solutions.Add1, solutions.Add2, solutions.Add3} + functions := []func(int){add0, add1, add2, add3} type node struct { - f func(int) - arr []int + f func(int) + a []int } table := []node{} - //15 random slice of random ints with a random function from selection - + // 15 random slice of random ints with a random function from selection for i := 0; i < 15; i++ { - functionSelected := functionsArray[z01.RandIntBetween(0, len(functionsArray)-1)] - val := node{ - f: functionSelected, - arr: z01.MultRandIntBetween(-1000000, 1000000), - } - table = append(table, val) + function := functions[z01.RandIntBetween(0, len(functions)-1)] + table = append(table, node{ + f: function, + a: z01.MultRandIntBetween(-1000000, 1000000), + }) } table = append(table, node{ - f: solutions.Add0, - arr: []int{1, 2, 3, 4, 5, 6}, + f: add0, + a: []int{1, 2, 3, 4, 5, 6}, }) for _, arg := range table { - z01.Challenge("ForEach", student.ForEach, solutions.ForEach, arg.f, arg.arr) + z01.Challenge("ForEach", student.ForEach, solutions.ForEach, arg.f, arg.a) } } diff --git a/tests/go/issorted_test.go b/tests/go/issorted_test.go index 83981a14..99e5de93 100644 --- a/tests/go/issorted_test.go +++ b/tests/go/issorted_test.go @@ -9,72 +9,96 @@ import ( student "./student" ) +func isSortedBy1(a, b int) int { + if a-b < 0 { + return -1 + } + if a-b > 0 { + return 1 + } + return 0 +} + +func isSortedBy10(a, b int) int { + if a-b < 0 { + return -10 + } + if a-b > 0 { + return 10 + } + return 0 +} + +func isSortedByDiff(a, b int) int { + return a - b +} + func main() { - functionsArray := []func(int, int) int{solutions.IsSortedByDiff, solutions.IsSortedBy1, solutions.IsSortedBy10} + functions := []func(int, int) int{isSortedByDiff, isSortedBy1, isSortedBy10} type node struct { - f func(int, int) int - arr []int + f func(int, int) int + a []int } table := []node{} - //5 unordered slices + // 5 unordered slices for i := 0; i < 5; i++ { - functionSelected := functionsArray[z01.RandIntBetween(0, len(functionsArray)-1)] + functionSelected := functions[z01.RandIntBetween(0, len(functions)-1)] val := node{ - f: functionSelected, - arr: z01.MultRandIntBetween(-1000000, 1000000), + f: functionSelected, + a: z01.MultRandIntBetween(-1000000, 1000000), } table = append(table, val) } - //5 slices ordered in ascending order + // 5 slices ordered in ascending order for i := 0; i < 5; i++ { - functionSelected := functionsArray[z01.RandIntBetween(0, len(functionsArray)-1)] - orderedArr := z01.MultRandIntBetween(-1000000, 1000000) - sort.Ints(orderedArr) + functionSelected := functions[z01.RandIntBetween(0, len(functions)-1)] + ordered := z01.MultRandIntBetween(-1000000, 1000000) + sort.Ints(ordered) val := node{ - f: functionSelected, - arr: orderedArr, + f: functionSelected, + a: ordered, } table = append(table, val) } - //5 slices ordered in descending order + // 5 slices ordered in descending order for i := 0; i < 5; i++ { - functionSelected := functionsArray[z01.RandIntBetween(0, len(functionsArray)-1)] - reverseArr := z01.MultRandIntBetween(-1000000, 1000000) - sort.Sort(sort.Reverse(sort.IntSlice(reverseArr))) + functionSelected := functions[z01.RandIntBetween(0, len(functions)-1)] + reversed := z01.MultRandIntBetween(-1000000, 1000000) + sort.Sort(sort.Reverse(sort.IntSlice(reversed))) val := node{ - f: functionSelected, - arr: reverseArr, + f: functionSelected, + a: reversed, } table = append(table, val) } table = append(table, node{ - f: solutions.IsSortedByDiff, - arr: []int{1, 2, 3, 4, 5, 6}, + f: solutions.IsSortedByDiff, + a: []int{1, 2, 3, 4, 5, 6}, }) table = append(table, node{ - f: solutions.IsSortedByDiff, - arr: []int{6, 5, 4, 3, 2, 1}, + f: solutions.IsSortedByDiff, + a: []int{6, 5, 4, 3, 2, 1}, }) table = append(table, node{ - f: solutions.IsSortedByDiff, - arr: []int{0, 0, 0, 0, 0, 0, 0}, + f: solutions.IsSortedByDiff, + a: []int{0, 0, 0, 0, 0, 0, 0}, }) table = append(table, node{ - f: solutions.IsSortedByDiff, - arr: []int{0}, + f: solutions.IsSortedByDiff, + a: []int{0}, }) for _, arg := range table { - z01.Challenge("IsSorted", student.IsSorted, solutions.IsSorted, arg.f, arg.arr) + z01.Challenge("IsSorted", student.IsSorted, solutions.IsSorted, arg.f, arg.a) } } diff --git a/tests/go/itoa_test.go b/tests/go/itoa_test.go index 7a7215a3..5ae5442b 100644 --- a/tests/go/itoa_test.go +++ b/tests/go/itoa_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { diff --git a/tests/go/join_test.go b/tests/go/join_test.go index 6a2de659..3c837063 100644 --- a/tests/go/join_test.go +++ b/tests/go/join_test.go @@ -1,23 +1,25 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { - arg1 := []string{"hello", "how", "are", "you", "doing"} - arg2 := []string{"fine", "and", "you"} - arg3 := []string{"I'm", "O.K."} seps := []string{" ", "-", " ,", "_", "SPC", " . "} - args := [][]string{arg1, arg2, arg3} + args := [][]string{ + {"hello", "how", "are", "you", "doing"}, + {"fine", "and", "you"}, + {"I'm", "O.K."}, + } for i := 0; i < 5; i++ { - //random position for the array of arguments + // random position for the slice of arguments posA := z01.RandIntBetween(0, len(args)-1) - //random position for the array of separators + // random position for the slice of separators posS := z01.RandIntBetween(0, len(seps)-1) z01.Challenge("Join", student.Join, solutions.Join, args[posA], seps[posS]) diff --git a/tests/go/listat_test.go b/tests/go/listat_test.go index d502be77..a656ff53 100644 --- a/tests/go/listat_test.go +++ b/tests/go/listat_test.go @@ -1,59 +1,58 @@ -package student_test +package main import ( - "testing" + "github.com/01-edu/z01" solution "./solutions" student "./student" - "github.com/01-edu/z01" ) type Node5 = student.NodeL type NodeS5 = solution.NodeL -func nodePushBackList5(l *Node5, l1 *NodeS5, data interface{}) (*Node5, *NodeS5) { - n := &Node5{Data: data} - n1 := &NodeS5{Data: data} - it := l - itS := l1 +func nodePushBackList5(l1 *Node5, l2 *NodeS5, data interface{}) (*Node5, *NodeS5) { + n1 := &Node5{Data: data} + n2 := &NodeS5{Data: data} - if it == nil { - it = n + if l1 == nil { + l1 = n1 } else { - iterator := it + iterator := l1 for iterator.Next != nil { iterator = iterator.Next } - iterator.Next = n + iterator.Next = n1 } - if itS == nil { - itS = n1 + if l2 == nil { + l2 = n2 } else { - iterator1 := itS + iterator1 := l2 for iterator1.Next != nil { iterator1 = iterator1.Next } - iterator1.Next = n1 + iterator1.Next = n2 } - return it, itS + return l1, l2 } // compare functions that consist on inserting using the structure node -func comparFuncNode5(solutionList *NodeS5, l *Node5, l1 *NodeS5, t *testing.T, arg int) { - if l == nil && l1 == nil { - } else if l != nil && l1 == nil { - t.Fatalf("\nListAt(%s, %d) == %v instead of %v\n\n", - solution.ListToString(solutionList), arg, l, l1) - } else if l.Data != l1.Data { - t.Fatalf("\nListAt(%s, %d) == %v instead of %v\n\n", - solution.ListToString(solutionList), arg, l.Data, l1.Data) +func comparFuncNode5(solutionList *NodeS5, l1 *Node5, l2 *NodeS5, arg int) { + if l1 == nil && l2 == nil { + return + } + if l1 != nil && l2 == nil { + z01.Fatalf("\nListAt(%s, %d) == %v instead of %v\n\n", + solution.ListToString(solutionList), arg, l1, l2) + } + if l1.Data != l2.Data { + z01.Fatalf("\nListAt(%s, %d) == %v instead of %v\n\n", + solution.ListToString(solutionList), arg, l1.Data, l2.Data) } } -// exercise 7 // finds an element of a solution.ListS using a given position -func TestListAt(t *testing.T) { - var link *Node5 +func main() { + var link1 *Node5 var link2 *NodeS5 type nodeTest struct { @@ -64,38 +63,34 @@ func TestListAt(t *testing.T) { var table []nodeTest for i := 0; i < 4; i++ { - val := nodeTest{ + table = append(table, nodeTest{ data: solution.ConvertIntToInterface(z01.MultRandInt()), pos: z01.RandIntBetween(1, 12), - } - table = append(table, val) + }) } for i := 0; i < 4; i++ { - val := nodeTest{ + table = append(table, nodeTest{ data: solution.ConvertIntToStringface(z01.MultRandWords()), pos: z01.RandIntBetween(1, 12), - } - table = append(table, val) + }) } - table = append(table, - nodeTest{ - data: []interface{}{"I", 1, "something", 2}, - pos: z01.RandIntBetween(1, 4), - }, - ) + table = append(table, nodeTest{ + data: []interface{}{"I", 1, "something", 2}, + pos: z01.RandIntBetween(1, 4), + }) for _, arg := range table { for i := 0; i < len(arg.data); i++ { - link, link2 = nodePushBackList5(link, link2, arg.data[i]) + link1, link2 = nodePushBackList5(link1, link2, arg.data[i]) } - result := student.ListAt(link, arg.pos) + result1 := student.ListAt(link1, arg.pos) result2 := solution.ListAt(link2, arg.pos) - comparFuncNode5(link2, result, result2, t, arg.pos) - link = nil + comparFuncNode5(link2, result1, result2, arg.pos) + link1 = nil link2 = nil } } diff --git a/tests/go/listclear_test.go b/tests/go/listclear_test.go index 8f6f52d5..5000409f 100644 --- a/tests/go/listclear_test.go +++ b/tests/go/listclear_test.go @@ -1,8 +1,9 @@ -package student_test +package main import ( "strconv" - "testing" + + "github.com/01-edu/z01" solution "./solutions" student "./student" @@ -29,22 +30,22 @@ func listToStringStu5(l *ListS4) string { return res } -func listPushBackTest4(l *ListS4, l1 *List4, data interface{}) { +func listPushBackTest4(l1 *ListS4, l2 *List4, data interface{}) { n := &Node4{Data: data} n1 := &NodeS4{Data: data} - if l.Head == nil { - l.Head = n + if l1.Head == nil { + l1.Head = n } else { - iterator := l.Head + iterator := l1.Head for iterator.Next != nil { iterator = iterator.Next } iterator.Next = n } - if l1.Head == nil { - l1.Head = n1 + if l2.Head == nil { + l2.Head = n1 } else { - iterator1 := l1.Head + iterator1 := l2.Head for iterator1.Next != nil { iterator1 = iterator1.Next } @@ -52,10 +53,9 @@ func listPushBackTest4(l *ListS4, l1 *List4, data interface{}) { } } -//exercise 6 -//simply cleans the linked solution.ListS -func TestListClear(t *testing.T) { - link := &List4{} +// simply cleans the linked solution.ListS +func main() { + link1 := &List4{} link2 := &ListS4{} table := []solution.NodeTest{} @@ -70,14 +70,14 @@ func TestListClear(t *testing.T) { for _, arg := range table { for i := 0; i < len(arg.Data); i++ { - listPushBackTest4(link2, link, arg.Data[i]) + listPushBackTest4(link2, link1, arg.Data[i]) } - solution.ListClear(link) + solution.ListClear(link1) student.ListClear(link2) if link2.Head != nil { - t.Fatalf("\nstudent list:%s\nlist:%s\n\nListClear() == %v instead of %v\n\n", - listToStringStu5(link2), solution.ListToString(link.Head), link2.Head, link.Head) + z01.Fatalf("\nstudent list:%s\nlist:%s\n\nListClear() == %v instead of %v\n\n", + listToStringStu5(link2), solution.ListToString(link1.Head), link2.Head, link1.Head) } } } diff --git a/tests/go/listfind_test.go b/tests/go/listfind_test.go index ed63be25..11442dcb 100644 --- a/tests/go/listfind_test.go +++ b/tests/go/listfind_test.go @@ -1,7 +1,7 @@ -package student_test +package main import ( - "testing" + "github.com/01-edu/z01" solution "./solutions" student "./student" @@ -12,22 +12,22 @@ type List9 = solution.List type NodeS9 = solution.NodeL type ListS9 = student.List -func listPushBackTest9(l *ListS9, l1 *List9, data interface{}) { +func listPushBackTest9(l1 *ListS9, l2 *List9, data interface{}) { n := &Node9{Data: data} n1 := &NodeS9{Data: data} - if l.Head == nil { - l.Head = n + if l1.Head == nil { + l1.Head = n } else { - iterator := l.Head + iterator := l1.Head for iterator.Next != nil { iterator = iterator.Next } iterator.Next = n } - if l1.Head == nil { - l1.Head = n1 + if l2.Head == nil { + l2.Head = n1 } else { - iterator1 := l1.Head + iterator1 := l2.Head for iterator1.Next != nil { iterator1 = iterator1.Next } @@ -35,9 +35,8 @@ func listPushBackTest9(l *ListS9, l1 *List9, data interface{}) { } } -// exercise 11 -func TestListFind(t *testing.T) { - link := &List9{} +func main() { + link1 := &List9{} link2 := &ListS9{} table := []solution.NodeTest{} @@ -50,31 +49,31 @@ func TestListFind(t *testing.T) { for _, arg := range table { for i := 0; i < len(arg.Data); i++ { - listPushBackTest9(link2, link, arg.Data[i]) + listPushBackTest9(link2, link1, arg.Data[i]) } if len(arg.Data) != 0 { - aux := student.ListFind(link2, arg.Data[(len(arg.Data)-1)/2], student.CompStr) - aux1 := solution.ListFind(link, arg.Data[(len(arg.Data)-1)/2], solution.CompStr) + aux1 := student.ListFind(link2, arg.Data[(len(arg.Data)-1)/2], student.CompStr) + aux2 := solution.ListFind(link1, arg.Data[(len(arg.Data)-1)/2], solution.CompStr) - if aux != nil || aux1 != nil { - if *aux != *aux1 { - t.Fatalf("ListFind(ref: %s) == %s instead of %s\n", arg.Data[(len(arg.Data)-1)/2], *aux, *aux1) + if aux1 != nil || aux2 != nil { + if *aux1 != *aux2 { + z01.Fatalf("ListFind(ref: %s) == %s instead of %s\n", arg.Data[(len(arg.Data)-1)/2], *aux1, *aux2) } } } - link = &List9{} + link1 = &List9{} link2 = &ListS9{} } for i := 0; i < len(table[0].Data); i++ { - listPushBackTest9(link2, link, table[0].Data[i]) + listPushBackTest9(link2, link1, table[0].Data[i]) } - aux := student.ListFind(link2, "lksdf", student.CompStr) - aux1 := solution.ListFind(link, "lksdf", solution.CompStr) - if aux != nil && aux1 != nil { - if *aux != *aux1 { - t.Fatalf("ListFind(ref: lksdf) == %s instead of %s\n", *aux, *aux1) + aux1 := student.ListFind(link2, "lksdf", student.CompStr) + aux2 := solution.ListFind(link1, "lksdf", solution.CompStr) + if aux1 != nil && aux2 != nil { + if *aux1 != *aux2 { + z01.Fatalf("ListFind(ref: lksdf) == %s instead of %s\n", *aux1, *aux2) } } } diff --git a/tests/go/listforeach_test.go b/tests/go/listforeach_test.go index 1ed6326e..e4e9a8cd 100644 --- a/tests/go/listforeach_test.go +++ b/tests/go/listforeach_test.go @@ -1,8 +1,9 @@ -package student_test +package main import ( "strconv" - "testing" + + "github.com/01-edu/z01" solution "./solutions" student "./student" @@ -29,22 +30,22 @@ func listToStringStu8(l *ListS7) string { return res } -func listPushBackTest7(l *ListS7, l1 *List7, data interface{}) { +func listPushBackTest7(l1 *ListS7, l2 *List7, data interface{}) { n := &Node7{Data: data} n1 := &NodeS7{Data: data} - if l.Head == nil { - l.Head = n + if l1.Head == nil { + l1.Head = n } else { - iterator := l.Head + iterator := l1.Head for iterator.Next != nil { iterator = iterator.Next } iterator.Next = n } - if l1.Head == nil { - l1.Head = n1 + if l2.Head == nil { + l2.Head = n1 } else { - iterator1 := l1.Head + iterator1 := l2.Head for iterator1.Next != nil { iterator1 = iterator1.Next } @@ -52,27 +53,25 @@ func listPushBackTest7(l *ListS7, l1 *List7, data interface{}) { } } -func comparFuncList7(l *List7, l1 *ListS7, t *testing.T, f func(*Node7)) { +func comparFuncList7(l1 *List7, l2 *ListS7, f func(*Node7)) { funcName := solution.GetName(f) - for l.Head != nil || l1.Head != nil { - if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) { - t.Fatalf("\nstudent list: %s\nlist: %s\nfunction used: %s\n\nListForEach() == %v instead of %v\n\n", - listToStringStu8(l1), solution.ListToString(l.Head), funcName, l1.Head, l.Head) - return - } else if l.Head.Data != l1.Head.Data { - t.Fatalf("\nstudent list: %s\nlist: %s\nfunction used: %s\n\nListForEach() == %v instead of %v\n\n", - listToStringStu8(l1), solution.ListToString(l.Head), funcName, l1.Head.Data, l.Head.Data) - return + for l1.Head != nil || l2.Head != nil { + if (l1.Head == nil && l2.Head != nil) || (l1.Head != nil && l2.Head == nil) { + z01.Fatalf("\nstudent list: %s\nlist: %s\nfunction used: %s\n\nListForEach() == %v instead of %v\n\n", + listToStringStu8(l2), solution.ListToString(l1.Head), funcName, l2.Head, l1.Head) + } + if l1.Head.Data != l2.Head.Data { + z01.Fatalf("\nstudent list: %s\nlist: %s\nfunction used: %s\n\nListForEach() == %v instead of %v\n\n", + listToStringStu8(l2), solution.ListToString(l1.Head), funcName, l2.Head.Data, l1.Head.Data) } - l.Head = l.Head.Next l1.Head = l1.Head.Next + l2.Head = l2.Head.Next } } -//exercise 9 -//applies a function to the solution.ListS -func TestListForEach(t *testing.T) { - link := &List7{} +// applies a function to the solution.ListS +func main() { + link1 := &List7{} link2 := &ListS7{} table := []solution.NodeTest{} table = solution.ElementsToTest(table) @@ -83,19 +82,19 @@ func TestListForEach(t *testing.T) { ) for _, arg := range table { for i := 0; i < len(arg.Data); i++ { - listPushBackTest7(link2, link, arg.Data[i]) + listPushBackTest7(link2, link1, arg.Data[i]) } student.ListForEach(link2, student.Add2_node) - solution.ListForEach(link, solution.Add2_node) + solution.ListForEach(link1, solution.Add2_node) - comparFuncList7(link, link2, t, student.Add2_node) + comparFuncList7(link1, link2, student.Add2_node) student.ListForEach(link2, student.Subtract3_node) - solution.ListForEach(link, solution.Subtract3_node) + solution.ListForEach(link1, solution.Subtract3_node) - comparFuncList7(link, link2, t, student.Subtract3_node) + comparFuncList7(link1, link2, student.Subtract3_node) - link = &List7{} + link1 = &List7{} link2 = &ListS7{} } } diff --git a/tests/go/listforeachif_test.go b/tests/go/listforeachif_test.go index 5229bfc3..3f4abaac 100644 --- a/tests/go/listforeachif_test.go +++ b/tests/go/listforeachif_test.go @@ -1,12 +1,12 @@ -package student_test +package main import ( "strconv" - "testing" + + "github.com/01-edu/z01" solution "./solutions" student "./student" - "github.com/01-edu/z01" ) type Node8 = student.NodeL @@ -56,53 +56,51 @@ func listToStringStu7(l *ListS8) string { return res } -func listPushBackTest8(l *ListS8, l1 *List8, data interface{}) { - n := &Node8{Data: data} - n1 := &NodeS8{Data: data} +func listPushBackTest8(l1 *ListS8, l2 *List8, data interface{}) { + n1 := &Node8{Data: data} + n2 := &NodeS8{Data: data} - if l.Head == nil { - l.Head = n + if l1.Head == nil { + l1.Head = n1 } else { - iterator := l.Head + iterator := l1.Head for iterator.Next != nil { iterator = iterator.Next } - iterator.Next = n + iterator.Next = n1 } - if l1.Head == nil { - l1.Head = n1 + if l2.Head == nil { + l2.Head = n2 } else { - iterator1 := l1.Head + iterator1 := l2.Head for iterator1.Next != nil { iterator1 = iterator1.Next } - iterator1.Next = n1 + iterator1.Next = n2 } } -func comparFuncList8(l *List8, l1 *ListS8, t *testing.T, f func(*Node8) bool, comp func(*Node8)) { +func comparFuncList8(l1 *List8, l2 *ListS8, f func(*Node8) bool, comp func(*Node8)) { funcFName := solution.GetName(f) funcComp := solution.GetName(comp) - for l.Head != nil || l1.Head != nil { - if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) { - t.Fatalf("\nstudent list:%s\nlist:%s\nfunction f used: %s\nfunction comp: %s\n\nListForEachIf() == %v instead of %v\n\n", - listToStringStu7(l1), solution.ListToString(l.Head), funcComp, funcFName, l1.Head, l.Head) - return - } else if l.Head.Data != l1.Head.Data { - t.Fatalf("\nstudent list:%s\nlist:%s\nfunction f used: %s\nfunction comp: %s\n\nListForEachIf() == %v instead of %v\n\n", - listToStringStu7(l1), solution.ListToString(l.Head), funcComp, funcFName, l1.Head.Data, l.Head.Data) - return + for l1.Head != nil || l2.Head != nil { + if (l1.Head == nil && l2.Head != nil) || (l1.Head != nil && l2.Head == nil) { + z01.Fatalf("\nstudent list:%s\nlist:%s\nfunction f used: %s\nfunction comp: %s\n\nListForEachIf() == %v instead of %v\n\n", + listToStringStu7(l2), solution.ListToString(l1.Head), funcComp, funcFName, l2.Head, l1.Head) + } + if l1.Head.Data != l2.Head.Data { + z01.Fatalf("\nstudent list:%s\nlist:%s\nfunction f used: %s\nfunction comp: %s\n\nListForEachIf() == %v instead of %v\n\n", + listToStringStu7(l2), solution.ListToString(l1.Head), funcComp, funcFName, l2.Head.Data, l1.Head.Data) } - l.Head = l.Head.Next l1.Head = l1.Head.Next + l2.Head = l2.Head.Next } } -// exercise 10 // applies a function to an element of the linked solution.ListS -func TestListForEachIf(t *testing.T) { - link := &ListS8{} +func main() { + link1 := &ListS8{} link2 := &List8{} table := []solution.NodeTest{} @@ -133,17 +131,17 @@ func TestListForEachIf(t *testing.T) { ) for _, arg := range table { for i := 0; i < len(arg.Data); i++ { - listPushBackTest8(link, link2, arg.Data[i]) + listPushBackTest8(link1, link2, arg.Data[i]) } solution.ListForEachIf(link2, addOneS, solution.IsPositive_node) - student.ListForEachIf(link, addOne, student.IsPositive_node) - comparFuncList8(link2, link, t, student.IsPositive_node, addOne) + student.ListForEachIf(link1, addOne, student.IsPositive_node) + comparFuncList8(link2, link1, student.IsPositive_node, addOne) solution.ListForEachIf(link2, subtract1_sol, solution.IsPositive_node) - student.ListForEachIf(link, subtractOne, student.IsPositive_node) - comparFuncList8(link2, link, t, student.IsPositive_node, subtractOne) + student.ListForEachIf(link1, subtractOne, student.IsPositive_node) + comparFuncList8(link2, link1, student.IsPositive_node, subtractOne) - link = &ListS8{} + link1 = &ListS8{} link2 = &List8{} } } diff --git a/tests/go/listlast_test.go b/tests/go/listlast_test.go index 32faf482..81e81b9c 100644 --- a/tests/go/listlast_test.go +++ b/tests/go/listlast_test.go @@ -1,8 +1,9 @@ -package student_test +package main import ( "strconv" - "testing" + + "github.com/01-edu/z01" solution "./solutions" student "./student" @@ -29,7 +30,7 @@ func listToStringStu9(l *ListS3) string { return res } -//inserts node on two lists +// inserts node on two lists func listPushBackTest3(l *ListS3, l1 *List3, data interface{}) { n := &Node3{Data: data} n1 := &NodeS3{Data: data} @@ -49,10 +50,9 @@ func listPushBackTest3(l *ListS3, l1 *List3, data interface{}) { } } -//exercise 5 -//last element of the solution.ListS -func TestListLast(t *testing.T) { - link := &List3{} +// last element of the solution.ListS +func main() { + link1 := &List3{} link2 := &ListS3{} table := []solution.NodeTest{} @@ -64,16 +64,16 @@ func TestListLast(t *testing.T) { ) for _, arg := range table { for i := 0; i < len(arg.Data); i++ { - listPushBackTest3(link2, link, arg.Data[i]) + listPushBackTest3(link2, link1, arg.Data[i]) } - aux := solution.ListLast(link) - aux1 := student.ListLast(link2) + aux1 := solution.ListLast(link1) + aux2 := student.ListLast(link2) - if aux != aux1 { - t.Fatalf("\nlist:%s\n\nListLast() == %v instead of %v\n\n", - listToStringStu9(link2), aux1, aux) + if aux1 != aux2 { + z01.Fatalf("\nlist:%s\n\nListLast() == %v instead of %v\n\n", + listToStringStu9(link2), aux2, aux1) } - link = &List3{} + link1 = &List3{} link2 = &ListS3{} } } diff --git a/tests/go/listmerge_test.go b/tests/go/listmerge_test.go index fda272c7..3f536595 100644 --- a/tests/go/listmerge_test.go +++ b/tests/go/listmerge_test.go @@ -1,8 +1,7 @@ -package student_test +package main import ( "strconv" - "testing" "github.com/01-edu/z01" @@ -31,76 +30,74 @@ func listToStringStu(l *ListS11) string { return res } -func listPushBackTest11(l *ListS11, l1 *List11, data interface{}) { - n := &Node11{Data: data} - n1 := &NodeS11{Data: data} +func listPushBackTest11(l1 *ListS11, l2 *List11, data interface{}) { + n1 := &Node11{Data: data} + n2 := &NodeS11{Data: data} - if l.Head == nil { - l.Head = n + if l1.Head == nil { + l1.Head = n1 } else { - iterator := l.Head + iterator := l1.Head for iterator.Next != nil { iterator = iterator.Next } - iterator.Next = n + iterator.Next = n1 } - l.Tail = n + l1.Tail = n1 - if l1.Head == nil { - l1.Head = n1 + if l2.Head == nil { + l2.Head = n2 } else { - iterator1 := l1.Head + iterator1 := l2.Head for iterator1.Next != nil { iterator1 = iterator1.Next } - iterator1.Next = n1 + iterator1.Next = n2 } - l1.Tail = n1 + l2.Tail = n2 } -func comparFuncList11(l *List11, l1 *ListS11, t *testing.T) { - for l.Head != nil || l1.Head != nil { - if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) { - t.Fatalf("\nstudent list:%s\nlist:%s\n\nListMerge() == %v instead of %v\n\n", - listToStringStu(l1), solution.ListToString(l.Head), l1.Head, l.Head) - return - } else if l.Head.Data != l1.Head.Data { - t.Fatalf("\nstudent list:%s\nlist:%s\n\nListMerge() == %v instead of %v\n\n", - listToStringStu(l1), solution.ListToString(l.Head), l1.Head.Data, l.Head.Data) - return +func comparFuncList11(l1 *List11, l2 *ListS11) { + for l1.Head != nil || l2.Head != nil { + if (l1.Head == nil && l2.Head != nil) || (l1.Head != nil && l2.Head == nil) { + z01.Fatalf("\nstudent list:%s\nlist:%s\n\nListMerge() == %v instead of %v\n\n", + listToStringStu(l2), solution.ListToString(l1.Head), l2.Head, l1.Head) + } + if l1.Head.Data != l2.Head.Data { + z01.Fatalf("\nstudent list:%s\nlist:%s\n\nListMerge() == %v instead of %v\n\n", + listToStringStu(l2), solution.ListToString(l1.Head), l2.Head.Data, l1.Head.Data) } - l.Head = l.Head.Next l1.Head = l1.Head.Next + l2.Head = l2.Head.Next } } -//exercise 14 -func TestListMerge(t *testing.T) { - link := &List11{} +func main() { + link1 := &List11{} linkTest := &List11{} link2 := &ListS11{} link2Test := &ListS11{} type nodeTest struct { - data []interface{} + data1 []interface{} data2 []interface{} } table := []nodeTest{} // empty list table = append(table, nodeTest{ - data: []interface{}{}, + data1: []interface{}{}, data2: []interface{}{}, }) table = append(table, nodeTest{ - data: solution.ConvertIntToInterface(z01.MultRandInt()), + data1: solution.ConvertIntToInterface(z01.MultRandInt()), data2: []interface{}{}, }) // jut ints for i := 0; i < 3; i++ { val := nodeTest{ - data: solution.ConvertIntToInterface(z01.MultRandInt()), + data1: solution.ConvertIntToInterface(z01.MultRandInt()), data2: solution.ConvertIntToInterface(z01.MultRandInt()), } table = append(table, val) @@ -108,32 +105,30 @@ func TestListMerge(t *testing.T) { // just strings for i := 0; i < 2; i++ { val := nodeTest{ - data: solution.ConvertIntToStringface(z01.MultRandWords()), + data1: solution.ConvertIntToStringface(z01.MultRandWords()), data2: solution.ConvertIntToStringface(z01.MultRandWords()), } table = append(table, val) } table = append(table, nodeTest{ - data: []interface{}{}, + data1: []interface{}{}, data2: []interface{}{"a", 1}, }, ) for _, arg := range table { - for i := 0; i < len(arg.data); i++ { - listPushBackTest11(link2, link, arg.data[i]) + for i := 0; i < len(arg.data1); i++ { + listPushBackTest11(link2, link1, arg.data1[i]) } for i := 0; i < len(arg.data2); i++ { listPushBackTest11(link2Test, linkTest, arg.data2[i]) } - solution.ListMerge(link, linkTest) - + solution.ListMerge(link1, linkTest) student.ListMerge(link2, link2Test) + comparFuncList11(link1, link2) - comparFuncList11(link, link2, t) - - link = &List11{} + link1 = &List11{} linkTest = &List11{} link2 = &ListS11{} link2Test = &ListS11{} diff --git a/tests/go/listpushback_test.go b/tests/go/listpushback_test.go index e59eefd6..0527c546 100644 --- a/tests/go/listpushback_test.go +++ b/tests/go/listpushback_test.go @@ -1,8 +1,9 @@ -package student_test +package main import ( "strconv" - "testing" + + "github.com/01-edu/z01" solution "./solutions" student "./student" @@ -28,25 +29,23 @@ func listToStringStu10(l *List) string { } // makes the test, compares 2 lists one from the solutions and the other from the student -func comparFuncList(l *ListS, l1 *List, t *testing.T, data []interface{}) { +func comparFuncList(l *ListS, l1 *List, data []interface{}) { for l.Head != nil || l1.Head != nil { if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) { - t.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushBack()== %v instead of %v\n\n", + z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushBack()== %v instead of %v\n\n", data, listToStringStu10(l1), solution.ListToString(l.Head), l1.Head, l.Head) - return - } else if l.Head.Data != l1.Head.Data { - t.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushBack()== %v instead of %v\n\n", + } + if l.Head.Data != l1.Head.Data { + z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushBack()== %v instead of %v\n\n", data, listToStringStu10(l1), solution.ListToString(l.Head), l1.Head.Data, l.Head.Data) - return } l.Head = l.Head.Next l1.Head = l1.Head.Next } } -// exercise 2 -func TestListPushBack(t *testing.T) { - link := &ListS{} +func main() { + link1 := &ListS{} link2 := &List{} table := []solution.NodeTest{} @@ -57,10 +56,10 @@ func TestListPushBack(t *testing.T) { }, ) for _, arg := range table { - for i := 0; i < len(arg.Data); i++ { - student.ListPushBack(link2, arg.Data[i]) - solution.ListPushBack(link, arg.Data[i]) + for _, item := range arg.Data { + student.ListPushBack(link2, item) + solution.ListPushBack(link1, item) } - comparFuncList(link, link2, t, arg.Data) + comparFuncList(link1, link2, arg.Data) } } diff --git a/tests/go/listpushfront_test.go b/tests/go/listpushfront_test.go index 9cc32f5f..ce95a30e 100644 --- a/tests/go/listpushfront_test.go +++ b/tests/go/listpushfront_test.go @@ -1,8 +1,9 @@ -package student_test +package main import ( "strconv" - "testing" + + "github.com/01-edu/z01" solution "./solutions" student "./student" @@ -27,27 +28,25 @@ func listToStringStu11(l *Lista) string { return res } -//makes the test, compares 2 lists one from the solutions and the other from the student -func comparFuncList1(l *Lista, l1 *ListSa, t *testing.T, data []interface{}) { +// makes the test, compares 2 lists one from the solutions and the other from the student +func comparFuncList1(l *Lista, l1 *ListSa, data []interface{}) { for l.Head != nil || l1.Head != nil { if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) { - t.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushFront()== %v instead of %v\n\n", + z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushFront()== %v instead of %v\n\n", data, listToStringStu11(l), solution.ListToString(l1.Head), l.Head, l1.Head) - return - } else if l.Head.Data != l1.Head.Data { - t.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushFront()== %v instead of %v\n\n", + } + if l.Head.Data != l1.Head.Data { + z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListPushFront()== %v instead of %v\n\n", data, listToStringStu11(l), solution.ListToString(l1.Head), l.Head, l1.Head) - return } l1.Head = l1.Head.Next l.Head = l.Head.Next } } -//exercise 3 -//to insert a value in the first position of the list -func TestListPushFront(t *testing.T) { - link := &Lista{} +// to insert a value in the first position of the list +func main() { + link1 := &Lista{} link2 := &ListSa{} table := []solution.NodeTest{} table = solution.ElementsToTest(table) @@ -57,12 +56,12 @@ func TestListPushFront(t *testing.T) { }, ) for _, arg := range table { - for i := 0; i < len(arg.Data); i++ { - student.ListPushFront(link, arg.Data[i]) - solution.ListPushFront(link2, arg.Data[i]) + for _, item := range arg.Data { + student.ListPushFront(link1, item) + solution.ListPushFront(link2, item) } - comparFuncList1(link, link2, t, arg.Data) - link = &Lista{} + comparFuncList1(link1, link2, arg.Data) + link1 = &Lista{} link2 = &ListSa{} } } diff --git a/tests/go/listremoveif_test.go b/tests/go/listremoveif_test.go index 1d00d997..6567c04d 100644 --- a/tests/go/listremoveif_test.go +++ b/tests/go/listremoveif_test.go @@ -1,12 +1,12 @@ -package student_test +package main import ( "strconv" - "testing" + + "github.com/01-edu/z01" solution "./solutions" student "./student" - "github.com/01-edu/z01" ) type Node10 = student.NodeL @@ -53,26 +53,24 @@ func listPushBackTest10(l *ListS10, l1 *List10, data interface{}) { } } -func comparFuncList10(l *List10, l1 *ListS10, t *testing.T, data interface{}) { +func comparFuncList10(l *List10, l1 *ListS10, data interface{}) { for l.Head != nil || l1.Head != nil { if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) { - t.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n", + z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n", data, listToStringStu12(l1), solution.ListToString(l.Head), l1.Head, l.Head) - return - } else if l.Head.Data != l1.Head.Data { - t.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n", + } + if l.Head.Data != l1.Head.Data { + z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n", data, listToStringStu12(l1), solution.ListToString(l.Head), l1.Head.Data, l.Head.Data) - return } l.Head = l.Head.Next l1.Head = l1.Head.Next } } -//exercise 13 -//removes all the elements that are equal to a value -func TestListRemoveIf(t *testing.T) { - link := &List10{} +// removes all the elements that are equal to a value +func main() { + link1 := &List10{} link2 := &ListS10{} var index int table := []solution.NodeTest{} @@ -87,23 +85,23 @@ func TestListRemoveIf(t *testing.T) { for _, arg := range table { for i := 0; i < len(arg.Data); i++ { - listPushBackTest10(link2, link, arg.Data[i]) + listPushBackTest10(link2, link1, arg.Data[i]) } aux := len(arg.Data) - 1 index = z01.RandIntBetween(0, aux) - if link.Head != nil && link2.Head != nil { + if link1.Head != nil && link2.Head != nil { cho := arg.Data[index] student.ListRemoveIf(link2, cho) - solution.ListRemoveIf(link, cho) - comparFuncList10(link, link2, t, cho) + solution.ListRemoveIf(link1, cho) + comparFuncList10(link1, link2, cho) } else { student.ListRemoveIf(link2, 1) - solution.ListRemoveIf(link, 1) - comparFuncList10(link, link2, t, 1) + solution.ListRemoveIf(link1, 1) + comparFuncList10(link1, link2, 1) } - link = &List10{} + link1 = &List10{} link2 = &ListS10{} } } diff --git a/tests/go/listreverse_test.go b/tests/go/listreverse_test.go index 500a8fae..991e2b0e 100644 --- a/tests/go/listreverse_test.go +++ b/tests/go/listreverse_test.go @@ -1,8 +1,9 @@ -package student_test +package main import ( "strconv" - "testing" + + "github.com/01-edu/z01" solution "./solutions" student "./student" @@ -29,21 +30,21 @@ func listToStringStu13(l *ListS6) string { return res } -func comparFuncList6(l *List6, l1 *ListS6, t *testing.T) { +func comparFuncList6(l *List6, l1 *ListS6) { for l.Head != nil || l1.Head != nil { if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) { - t.Fatalf("\nstudent list:%s\nlist:%s\n\nListReverse() == %v instead of %v\n\n", + z01.Fatalf("\nstudent list:%s\nlist:%s\n\nListReverse() == %v instead of %v\n\n", listToStringStu13(l1), solution.ListToString(l.Head), l1.Head, l.Head) - return - } else if l.Head.Data != l1.Head.Data { - t.Fatalf("\nstudent list:%s\nlist:%s\n\nListReverse() == %v instead of %v\n\n", + } + if l.Head.Data != l1.Head.Data { + z01.Fatalf("\nstudent list:%s\nlist:%s\n\nListReverse() == %v instead of %v\n\n", listToStringStu13(l1), solution.ListToString(l.Head), l1.Head.Data, l.Head.Data) - return } l.Head = l.Head.Next l1.Head = l1.Head.Next } } + func listPushBackTest6(l *ListS6, l1 *List6, data interface{}) { n := &Node6{Data: data} n1 := &NodeS6{Data: data} @@ -67,25 +68,21 @@ func listPushBackTest6(l *ListS6, l1 *List6, data interface{}) { } } -// exercise 8 -func TestListReverse(t *testing.T) { - link := &List6{} +func main() { + link1 := &List6{} link2 := &ListS6{} - table := []solution.NodeTest{} + table := []solution.NodeTest{{ + Data: []interface{}{"I", 1, "something", 2}, + }} table = solution.ElementsToTest(table) - table = append(table, - solution.NodeTest{ - Data: []interface{}{"I", 1, "something", 2}, - }, - ) for _, arg := range table { - for i := 0; i < len(arg.Data); i++ { - listPushBackTest6(link2, link, arg.Data[i]) + for _, item := range arg.Data { + listPushBackTest6(link2, link1, item) } student.ListReverse(link2) - solution.ListReverse(link) - comparFuncList6(link, link2, t) - link = &List6{} + solution.ListReverse(link1) + comparFuncList6(link1, link2) + link1 = &List6{} link2 = &ListS6{} } } diff --git a/tests/go/listsize_test.go b/tests/go/listsize_test.go index 2cb61226..c09cd188 100644 --- a/tests/go/listsize_test.go +++ b/tests/go/listsize_test.go @@ -1,7 +1,7 @@ -package student_test +package main import ( - "testing" + "github.com/01-edu/z01" solution "./solutions" student "./student" @@ -36,8 +36,7 @@ func listPushBackTest2(l *ListS2, l1 *List2, data interface{}) { } } -//exercise 4 -func TestListSize(t *testing.T) { +func main() { link := &List2{} link2 := &ListS2{} table := []solution.NodeTest{} @@ -54,7 +53,7 @@ func TestListSize(t *testing.T) { aux := solution.ListSize(link) aux2 := student.ListSize(link2) if aux != aux2 { - t.Fatalf("ListSize(%v) == %d instead of %d\n", solution.ListToString(link.Head), aux2, aux) + z01.Fatalf("ListSize(%v) == %d instead of %d\n", solution.ListToString(link.Head), aux2, aux) } link = &List2{} link2 = &ListS2{} diff --git a/tests/go/listsort_test.go b/tests/go/listsort_test.go index d7b1a678..f221f750 100644 --- a/tests/go/listsort_test.go +++ b/tests/go/listsort_test.go @@ -1,12 +1,12 @@ -package student_test +package main import ( "strconv" - "testing" + + "github.com/01-edu/z01" solution "./solutions" student "./student" - "github.com/01-edu/z01" ) type NodeI12 = student.NodeI @@ -23,19 +23,9 @@ func printListStudent(n *NodeI12) string { return res } -func nodePushBackListInt12(l *NodeI12, l1 *NodeIS12, data int) { - n := &NodeI12{Data: data} - n1 := &NodeIS12{Data: data} - - if l == nil { - l = n - } else { - iterator := l - for iterator.Next != nil { - iterator = iterator.Next - } - iterator.Next = n - } +func nodePushBackListInt12(l1 *NodeI12, l2 *NodeIS12, data int) { + n1 := &NodeI12{Data: data} + n2 := &NodeIS12{Data: data} if l1 == nil { l1 = n1 @@ -46,61 +36,59 @@ func nodePushBackListInt12(l *NodeI12, l1 *NodeIS12, data int) { } iterator1.Next = n1 } + + if l2 == nil { + l2 = n2 + } else { + iterator2 := l2 + for iterator2.Next != nil { + iterator2 = iterator2.Next + } + iterator2.Next = n2 + } } -func comparFuncNodeInt12(l *NodeI12, l1 *NodeIS12, t *testing.T) { - for l != nil || l1 != nil { - if (l == nil && l1 != nil) || (l != nil && l1 == nil) { - t.Fatalf("\nstudent list:%s\nlist:%s\n\nListSort() == %v instead of %v\n\n", - printListStudent(l), solution.PrintList(l1), l, l1) - return - } else if l.Data != l1.Data { - t.Fatalf("\nstudent list:%s\nlist:%s\n\nListSort() == %v instead of %v\n\n", - printListStudent(l), solution.PrintList(l1), l.Data, l1.Data) - return +func comparFuncNodeInt12(l1 *NodeI12, l2 *NodeIS12) { + for l1 != nil || l2 != nil { + if (l1 == nil && l2 != nil) || (l1 != nil && l2 == nil) { + z01.Fatalf("\nstudent list:%s\nlist:%s\n\nListSort() == %v instead of %v\n\n", + printListStudent(l1), solution.PrintList(l2), l1, l2) + } + if l1.Data != l2.Data { + z01.Fatalf("\nstudent list:%s\nlist:%s\n\nListSort() == %v instead of %v\n\n", + printListStudent(l1), solution.PrintList(l2), l1.Data, l2.Data) } - l = l.Next l1 = l1.Next + l2 = l2.Next } } -//exercise 15 -func TestListSort(t *testing.T) { - var link *NodeI12 +func main() { + var link1 *NodeI12 var link2 *NodeIS12 type nodeTest struct { data []int } table := []nodeTest{} + table = append(table, nodeTest{[]int{}}) - table = append(table, - nodeTest{ - data: []int{}, - }) - //just numbers/ints + // just numbers/ints for i := 0; i < 2; i++ { - val := nodeTest{ - data: z01.MultRandInt(), - } - table = append(table, val) + table = append(table, nodeTest{z01.MultRandInt()}) } + table = append(table, nodeTest{[]int{5, 4, 3, 2, 1}}) - table = append(table, - nodeTest{ - data: []int{5, 4, 3, 2, 1}, - }, - ) for _, arg := range table { for i := 0; i < len(arg.data); i++ { - nodePushBackListInt12(link, link2, arg.data[i]) + nodePushBackListInt12(link1, link2, arg.data[i]) } - aux := solution.ListSort(link2) - aux2 := student.ListSort(link) + aux1 := solution.ListSort(link2) + aux2 := student.ListSort(link1) - comparFuncNodeInt12(aux2, aux, t) + comparFuncNodeInt12(aux2, aux1) - link = &NodeI12{} + link1 = &NodeI12{} link2 = &NodeIS12{} } } diff --git a/tests/go/max_test.go b/tests/go/max_test.go index 77ef9b83..d1241d3f 100644 --- a/tests/go/max_test.go +++ b/tests/go/max_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { diff --git a/tests/go/pointone_test.go b/tests/go/pointone_test.go index 4a34a059..e221bef8 100644 --- a/tests/go/pointone_test.go +++ b/tests/go/pointone_test.go @@ -1,15 +1,15 @@ -package student_test +package main import ( - "testing" - student "./student" + + "github.com/01-edu/z01" ) -func TestPointOne(t *testing.T) { +func main() { n := 0 student.PointOne(&n) if n != 1 { - t.Fatalf("PointOne(&n), n == %d instead of 1", n) + z01.Fatalf("PointOne(&n), n == %d instead of 1\n", n) } } diff --git a/tests/go/printnbrbase_test.go b/tests/go/printnbrbase_test.go index 333180cd..607dbd17 100644 --- a/tests/go/printnbrbase_test.go +++ b/tests/go/printnbrbase_test.go @@ -3,6 +3,8 @@ package main import ( "github.com/01-edu/z01" + "./base" + solutions "./solutions" student "./student" ) @@ -17,7 +19,7 @@ func main() { // 15 random pairs of ints with valid bases for i := 0; i < 15; i++ { - validBaseToInput := solutions.RandomValidBase() + validBaseToInput := base.Valid() val := node{ n: z01.RandIntBetween(-1000000, 1000000), base: validBaseToInput, @@ -27,7 +29,7 @@ func main() { // 15 random pairs of ints with invalid bases for i := 0; i < 15; i++ { - invalidBaseToInput := solutions.RandomInvalidBase() + invalidBaseToInput := base.Invalid() val := node{ n: z01.RandIntBetween(-1000000, 1000000), base: invalidBaseToInput, @@ -47,3 +49,5 @@ func main() { z01.Challenge("PrintNbrBase", student.PrintNbrBase, solutions.PrintNbrBase, arg.n, arg.base) } } + +// TODO: fix base exercises diff --git a/tests/go/printnbrinorder_test.go b/tests/go/printnbrinorder_test.go index 4fd8ef86..adfc66ce 100644 --- a/tests/go/printnbrinorder_test.go +++ b/tests/go/printnbrinorder_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { diff --git a/tests/go/printprogramname_test.go b/tests/go/printprogramname_test.go index 80c67504..faff074d 100644 --- a/tests/go/printprogramname_test.go +++ b/tests/go/printprogramname_test.go @@ -1,19 +1,31 @@ -package student_test +package main import ( - "bytes" + "os" "os/exec" - "testing" + + "github.com/01-edu/z01" ) -func TestPrintProgramName(t *testing.T) { - b, err := exec.Command("go", "run", "./student/printprogramname").Output() +var name = "student" + +func test(newName string) { + if err := os.Rename(name, newName); err != nil { + z01.Fatalln(err) + } + b, err := exec.Command("./" + name).CombinedOutput() if err != nil { - t.Fatal(err) + z01.Fatalln(b) } - if string(bytes.TrimSpace(b)) != "printprogramname" { - t.Fatal("Failed to print the program name") + if string(b) != name+"\n" { + z01.Fatalln("Failed to print the program name") } + name = newName } -// TODO: add more test cases (different program names), to do so compile then rename and test the binary several times +func main() { + test("student") + test("choumi") + test("🤦🏻‍♀️") + test("€") +} diff --git a/tests/go/printwordstables_test.go b/tests/go/printwordstables_test.go index 30c6d55e..76a710b9 100644 --- a/tests/go/printwordstables_test.go +++ b/tests/go/printwordstables_test.go @@ -11,7 +11,7 @@ import ( func main() { table := [][]string{} - //30 random slice of slice of strings + // 30 random slice of slice of strings for i := 0; i < 30; i++ { val := solutions.SplitWhiteSpaces(strings.Join(z01.MultRandASCII(), " ")) diff --git a/tests/go/raid1a_test.go b/tests/go/raid1a_test.go index 7a41ab01..a0466d43 100644 --- a/tests/go/raid1a_test.go +++ b/tests/go/raid1a_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { @@ -23,8 +24,8 @@ func main() { z01.RandIntBetween(1, 20), z01.RandIntBetween(1, 20), ) - //Tests all possibilities including 0 0, -x y, x -y - for i := 0; i < len(table); i = i + 2 { + // Tests all possibilities including 0 0, -x y, x -y + for i := 0; i < len(table); i += 2 { if i != len(table)-1 { z01.Challenge("Raid1a", solutions.Raid1a, student.Raid1a, table[i], table[i+1]) } diff --git a/tests/go/raid1b_test.go b/tests/go/raid1b_test.go index a832c215..5eab92d3 100644 --- a/tests/go/raid1b_test.go +++ b/tests/go/raid1b_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { @@ -23,8 +24,8 @@ func main() { z01.RandIntBetween(1, 20), z01.RandIntBetween(1, 20), ) - //Tests all possibilities including 0 0, -x y, x -y - for i := 0; i < len(table); i = i + 2 { + // Tests all possibilities including 0 0, -x y, x -y + for i := 0; i < len(table); i += 2 { if i != len(table)-1 { z01.Challenge("Raid1b", solutions.Raid1b, student.Raid1b, table[i], table[i+1]) } diff --git a/tests/go/raid1c_test.go b/tests/go/raid1c_test.go index 1e864814..3eca0d9f 100644 --- a/tests/go/raid1c_test.go +++ b/tests/go/raid1c_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { @@ -23,8 +24,8 @@ func main() { z01.RandIntBetween(1, 20), z01.RandIntBetween(1, 20), ) - //Tests all possibilities including 0 0, -x y, x -y - for i := 0; i < len(table); i = i + 2 { + // Tests all possibilities including 0 0, -x y, x -y + for i := 0; i < len(table); i += 2 { if i != len(table)-1 { z01.Challenge("Raid1c", solutions.Raid1c, student.Raid1c, table[i], table[i+1]) } diff --git a/tests/go/raid1d_test.go b/tests/go/raid1d_test.go index 12bb7db5..b76610be 100644 --- a/tests/go/raid1d_test.go +++ b/tests/go/raid1d_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { @@ -23,8 +24,8 @@ func main() { z01.RandIntBetween(1, 20), z01.RandIntBetween(1, 20), ) - //Tests all possibilities including 0 0, -x y, x -y - for i := 0; i < len(table); i = i + 2 { + // Tests all possibilities including 0 0, -x y, x -y + for i := 0; i < len(table); i += 2 { if i != len(table)-1 { z01.Challenge("Raid1d", solutions.Raid1d, student.Raid1d, table[i], table[i+1]) } diff --git a/tests/go/raid1e_test.go b/tests/go/raid1e_test.go index 299df5b1..5cfcd645 100644 --- a/tests/go/raid1e_test.go +++ b/tests/go/raid1e_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { @@ -23,8 +24,8 @@ func main() { z01.RandIntBetween(1, 20), z01.RandIntBetween(1, 20), ) - //Tests all possibilities including 0 0, -x y, x -y - for i := 0; i < len(table); i = i + 2 { + // Tests all possibilities including 0 0, -x y, x -y + for i := 0; i < len(table); i += 2 { if i != len(table)-1 { z01.Challenge("Raid1e", solutions.Raid1e, student.Raid1e, table[i], table[i+1]) } diff --git a/tests/go/raid3_test.go b/tests/go/raid3_test.go index 18662e49..575de0a3 100644 --- a/tests/go/raid3_test.go +++ b/tests/go/raid3_test.go @@ -1,19 +1,18 @@ -package student_test +package main import ( "os/exec" "strconv" - "testing" "github.com/01-edu/z01" ) -func TestRaid3(t *testing.T) { +func main() { execFatal := func(name string, arg ...string) string { b, err := exec.Command(name, arg...).CombinedOutput() s := string(b) if err != nil { - t.Fatal(s) + z01.Fatal(s) } return s } @@ -30,7 +29,7 @@ func TestRaid3(t *testing.T) { correct = execFatal("sh", "-c", "./"+args+" "+strconv.Itoa(x)+" "+strconv.Itoa(y)+" | ./raid3") } if output != correct { - t.Fatalf("./%s %d %d | ./raid3 prints %q instead of %q\n", + z01.Fatalf("./%s %d %d | ./raid3 prints %q instead of %q\n", args, x, y, output, correct) } } @@ -53,7 +52,7 @@ func TestRaid3(t *testing.T) { } // testing special case AA, AC, A, A - // A C + // A C executeTest("raid1e", 2, 1) executeTest("raid1c", 2, 1) executeTest("raid1d", 1, 2) diff --git a/tests/go/solutions/abort.go b/tests/go/solutions/abort.go index 70bbeac8..5e20cc1b 100644 --- a/tests/go/solutions/abort.go +++ b/tests/go/solutions/abort.go @@ -1,12 +1,10 @@ package solutions -import ( - "sort" -) +import "sort" -//Receives 5 ints and returns the number in the middle +// 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.Sort(sort.IntSlice(arg)) + sort.Ints(arg) return arg[2] } diff --git a/tests/go/solutions/activebits.go b/tests/go/solutions/activebits.go index bc1afa67..26ee55d1 100644 --- a/tests/go/solutions/activebits.go +++ b/tests/go/solutions/activebits.go @@ -1,12 +1,10 @@ package solutions -//Function that return the number of active bits in the number passed as the argument -func ActiveBits(n int) uint { - total := 0 +// 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 uint(total) + return } diff --git a/tests/go/solutions/addlinkednumbers/addlinkednumbers_test.go b/tests/go/solutions/addlinkednumbers/addlinkednumbers_test.go index fdc8bcfd..9a87dc30 100644 --- a/tests/go/solutions/addlinkednumbers/addlinkednumbers_test.go +++ b/tests/go/solutions/addlinkednumbers/addlinkednumbers_test.go @@ -2,7 +2,6 @@ package main import ( "strconv" - "testing" "github.com/01-edu/z01" @@ -82,51 +81,39 @@ func solNodeString(node *solNode) string { return result } -func compareNodes(t *testing.T, stuResult *stuNode, solResult *solNode, num1, num2 int) { +func compareNodes(stuResult *stuNode, solResult *solNode, num1, num2 int) { if stuResult == nil && solResult == nil { - } else if stuResult != nil && solResult == nil { + return + } + if stuResult != nil && solResult == nil { stuNum := stuNodeString(stuResult) - t.Fatalf("\nAddLinkedNumbers(%v, %v) == %v instead of %v\n\n", + z01.Fatalf("\nAddLinkedNumbers(%v, %v) == %v instead of %v\n\n", num1, num2, stuNum, "") - } else if stuResult == nil && solResult != nil { + } + if stuResult == nil && solResult != nil { solNum := solNodeString(solResult) - t.Fatalf("\nAddLinkedNumbers(%v, %v) == %v instead of %v\n\n", + z01.Fatalf("\nAddLinkedNumbers(%v, %v) == %v instead of %v\n\n", num1, num2, "", solNum) - } else { - stuNum := stuNodeString(stuResult) - solNum := solNodeString(solResult) - if stuNum != solNum { - t.Fatalf("\nAddLinkedNumbers(%v, %v) == %v instead of %v\n\n", - num1, num2, stuNum, solNum) - } } -} - -func TestAddLinkedNumbers(t *testing.T) { - type node struct { - num1 int - num2 int + stuNum := stuNodeString(stuResult) + solNum := solNodeString(solResult) + if stuNum != solNum { + z01.Fatalf("\nAddLinkedNumbers(%v, %v) == %v instead of %v\n\n", + num1, num2, stuNum, solNum) } +} - table := []node{} - - table = append(table, - node{315, 592}, - ) +func main() { + args := [][2]int{{315, 592}} for i := 0; i < 15; i++ { - value := node{ - num1: z01.RandIntBetween(0, 1000000000), - num2: z01.RandIntBetween(0, 1000000000), - } - - table = append(table, value) + args = append(args, [2]int{z01.RandPosZ(), z01.RandPosZ()}) } - for _, arg := range table { - stuResult := AddLinkedNumbers(stuNumToList(arg.num1), stuNumToList(arg.num2)) - solResult := solutions.AddLinkedNumbers(solNumToList(arg.num1), solNumToList(arg.num2)) + for _, arg := range args { + stuResult := AddLinkedNumbers(stuNumToList(arg[0]), stuNumToList(arg[1])) + solResult := solutions.AddLinkedNumbers(solNumToList(arg[0]), solNumToList(arg[1])) - compareNodes(t, stuResult, solResult, arg.num1, arg.num2) + compareNodes(stuResult, solResult, arg[0], arg[1]) } } diff --git a/tests/go/solutions/addprimesum/main.go b/tests/go/solutions/addprimesum/main.go index 6775aaba..781bb32a 100644 --- a/tests/go/solutions/addprimesum/main.go +++ b/tests/go/solutions/addprimesum/main.go @@ -14,7 +14,8 @@ func isPrime(nb int) bool { } if nb <= 3 { return true - } else if nb%2 == 0 || nb%3 == 0 { + } + if nb%2 == 0 || nb%3 == 0 { return false } @@ -23,7 +24,7 @@ func isPrime(nb int) bool { if nb%i == 0 || nb%(i+2) == 0 { return false } - i = i + 6 + i += 6 } return true } @@ -41,10 +42,9 @@ func main() { } else { result := 0 for ; argument >= 0; argument-- { - if isPrime(argument) == true { - result = result + argument + if isPrime(argument) { + result += argument } - } fmt.Println(result) } diff --git a/tests/go/solutions/addprimesum/test_addprimesum.go b/tests/go/solutions/addprimesum/test_addprimesum.go index 4b1ed796..04dee8ef 100644 --- a/tests/go/solutions/addprimesum/test_addprimesum.go +++ b/tests/go/solutions/addprimesum/test_addprimesum.go @@ -2,7 +2,6 @@ package main import ( "strconv" - "strings" "github.com/01-edu/z01" ) @@ -13,7 +12,8 @@ func isAPrime(nb int) bool { } if nb <= 3 { return true - } else if nb%2 == 0 || nb%3 == 0 { + } + if nb%2 == 0 || nb%3 == 0 { return false } @@ -22,33 +22,27 @@ func isAPrime(nb int) bool { if nb%i == 0 || nb%(i+2) == 0 { return false } - i = i + 6 + i += 6 } return true } func main() { - var table []string - - // fill with all rpime numbers between 0 and 100 + // adds random numbers + table := z01.MultRandIntBetween(1, 10000) + // fill with all prime numbers between 0 and 100 for i := 0; i < 100; i++ { if isAPrime(i) { - str := strconv.Itoa(i) - table = append(table, str) + table = append(table, i) } } - // adds 15 random numbers - for i := 0; i < 15; i++ { - table = append(table, strconv.Itoa(z01.RandIntBetween(1, 10000))) + for _, i := range table { + z01.ChallengeMain("addprimesum", strconv.Itoa(i)) } - // special cases - table = append(table, "\"\"") - table = append(table, "1 2") - - for _, s := range table { - z01.ChallengeMain("addprimesum", strings.Fields(s)...) - } + z01.ChallengeMain("addprimesum") + z01.ChallengeMain("addprimesum", `""`) + z01.ChallengeMain("addprimesum", "1", "2") } diff --git a/tests/go/solutions/advancedsortwordarr.go b/tests/go/solutions/advancedsortwordarr.go index f20cce3f..6cf16fc7 100644 --- a/tests/go/solutions/advancedsortwordarr.go +++ b/tests/go/solutions/advancedsortwordarr.go @@ -1,20 +1,10 @@ package solutions -func CompArray(a, b string) int { - if a < b { - return -1 - } - if a > b { - return 1 - } - return 0 -} +import "sort" -func AdvancedSortWordArr(array []string, f func(a, b string) int) { - for i := 1; i < len(array); i++ { - if f(array[i], array[i-1]) < 0 { - array[i], array[i-1] = array[i-1], array[i] - i = 0 - } - } +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 + }) + return a } diff --git a/tests/go/solutions/alphacount.go b/tests/go/solutions/alphacount.go index 7ef77951..807346bd 100644 --- a/tests/go/solutions/alphacount.go +++ b/tests/go/solutions/alphacount.go @@ -1,11 +1,12 @@ package solutions -import ( - "regexp" -) +import "unicode" -func AlphaCount(str string) int { - re := regexp.MustCompile(`[a-zA-Z]`) - found := re.FindAll([]byte(str), -1) - return len(found) +func AlphaCount(s string) (i int) { + for _, r := range s { + if unicode.IsLetter(r) { + i++ + } + } + return i } diff --git a/tests/go/solutions/alphamirror/main.go b/tests/go/solutions/alphamirror/main.go index f4ac4308..e9db5042 100644 --- a/tests/go/solutions/alphamirror/main.go +++ b/tests/go/solutions/alphamirror/main.go @@ -14,7 +14,6 @@ func main() { } else if ch >= 'A' && ch <= 'Z' { arg[i] = 'Z' - ch + 'A' } - } fmt.Print(string(arg)) } diff --git a/tests/go/solutions/alphamirror/test_alphamirror.go b/tests/go/solutions/alphamirror/test_alphamirror.go index 86951a0d..e13ac2b7 100644 --- a/tests/go/solutions/alphamirror/test_alphamirror.go +++ b/tests/go/solutions/alphamirror/test_alphamirror.go @@ -1,17 +1,16 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - arg1 := []string{""} - arg2 := []string{"One", "ring!"} - arg3 := []string{"testing spaces and #!*"} - arg4 := []string{"more", "than", "three", "arguments"} - arg5 := []string{"Upper anD LoWer cAsE"} - arg6 := []string{z01.RandWords()} - args := [][]string{arg1, arg2, arg3, arg4, arg5, arg6} + args := [][]string{ + {""}, + {"One", "ring!"}, + {"testing spaces and #!*"}, + {"more", "than", "three", "arguments"}, + {"Upper anD LoWer cAsE"}, + {z01.RandWords()}, + } for _, v := range args { z01.ChallengeMain("alphamirror", v...) diff --git a/tests/go/solutions/atoi.go b/tests/go/solutions/atoi.go index da024810..e56bd80d 100644 --- a/tests/go/solutions/atoi.go +++ b/tests/go/solutions/atoi.go @@ -1,8 +1,6 @@ package solutions -import ( - "strconv" -) +import "strconv" func Atoi(s string) int { n, _ := strconv.Atoi(s) diff --git a/tests/go/solutions/atoibase.go b/tests/go/solutions/atoibase.go index 64a52c86..510c97f9 100644 --- a/tests/go/solutions/atoibase.go +++ b/tests/go/solutions/atoibase.go @@ -1,52 +1,31 @@ package solutions -import ( - "math/rand" +import "strings" - "github.com/01-edu/z01" -) +var m = map[rune]struct{}{} -func ContainsPlusMinus(s string) bool { - for _, c := range s { - if c == '+' || c == '-' { - return true - } - } - return false -} - -func UniqueChar(s string) bool { - r := []rune(s) - n := len(r) - for i := 0; i < n-1; i++ { - if InStr(r[i], s[i+1:n]) { +func uniqueChar(s string) bool { + for _, r := range s { + if _, ok := m[r]; ok { return false } + m[r] = struct{}{} } return true } -func InStr(c rune, s string) bool { - for _, r := range s { - if c == r { - return true - } - } - return false -} - -func ValidBase(base string) bool { - return len(base) >= 2 && !ContainsPlusMinus(base) && UniqueChar(base) +func validBase(base string) bool { + return len(base) >= 2 && !strings.ContainsAny(base, "+-") && uniqueChar(base) } -func Power(nbr int, pwr int) int { +func power(nbr int, pwr int) int { if pwr == 0 { return 1 } if pwr == 1 { return nbr } - return nbr * Power(nbr, pwr-1) + return nbr * power(nbr, pwr-1) } func AtoiBase(s string, base string) int { @@ -56,7 +35,7 @@ func AtoiBase(s string, base string) int { lengthBase := len(base) lengths := len(s) - if !ValidBase(base) { + if !validBase(base) { return 0 } if s[i] == '-' { @@ -66,53 +45,9 @@ func AtoiBase(s string, base string) int { i++ } for i < len(s) { - result = result + (Index(base, string(s[i])) * Power(lengthBase, lengths-1)) + result += (Index(base, string(s[i])) * power(lengthBase, lengths-1)) i++ lengths-- } return result * sign } - -// this function is used to create the tests (input VALID bases here) - -func RandomValidBase() string { - validBases := []string{ - "01", - "CHOUMIisDAcat!", - "choumi", - "0123456789", - "abc", "Zone01", - "0123456789ABCDEF", - "WhoAmI?", - } - index := rand.Intn(len(validBases)) - return validBases[index] -} - -// this function is used to create the tests (input INVALID bases here) -func RandomInvalidBase() string { - invalidBases := []string{ - "0", - "1", - "CHOUMIisdacat!", - "choumiChoumi", - "01234567890", - "abca", - "Zone01Zone01", - "0123456789ABCDEF0", - "WhoAmI?IamWhoIam", - } - index := z01.RandIntBetween(0, len(invalidBases)-1) - return invalidBases[index] -} - -// this function is used to create the random STRING number from VALID BASES -func RandomStringFromBase(base string) string { - letters := []rune(base) - size := z01.RandIntBetween(1, 10) - r := make([]rune, size) - for i := range r { - r[i] = letters[rand.Intn(len(letters))] - } - return string(r) -} diff --git a/tests/go/solutions/atoibaseprog/atoibaseprog_test.go b/tests/go/solutions/atoibaseprog/atoibaseprog_test.go index 9a67e760..040d9a32 100644 --- a/tests/go/solutions/atoibaseprog/atoibaseprog_test.go +++ b/tests/go/solutions/atoibaseprog/atoibaseprog_test.go @@ -3,6 +3,8 @@ package main import ( "github.com/01-edu/z01" + "./base" + solutions "../../solutions" ) @@ -17,16 +19,16 @@ func main() { // 15 random pairs of string numbers with valid bases for i := 0; i < 15; i++ { - validBaseToInput := solutions.RandomValidBase() + validBaseToInput := base.Valid() val := node{ - s: solutions.RandomStringFromBase(validBaseToInput), + s: base.StringFrom(validBaseToInput), base: validBaseToInput, } table = append(table, val) } // 15 random pairs of string numbers with invalid bases for i := 0; i < 15; i++ { - invalidBaseToInput := solutions.RandomInvalidBase() + invalidBaseToInput := base.Invalid() val := node{ s: "thisinputshouldnotmatter", base: invalidBaseToInput, @@ -44,3 +46,5 @@ func main() { z01.Challenge("AtoiBaseProg", AtoiBase, solutions.AtoiBase, arg.s, arg.base) } } + +// TODO: fix base exercises diff --git a/tests/go/solutions/atoibaseprog/main.go b/tests/go/solutions/atoibaseprog/main.go index b325f9e6..a08e3220 100644 --- a/tests/go/solutions/atoibaseprog/main.go +++ b/tests/go/solutions/atoibaseprog/main.go @@ -1,65 +1,40 @@ package main -import ( - "strings" -) +import "strings" -func ContainsPlusMinus(s string) bool { - for _, c := range s { - if c == '+' || c == '-' { - return true - } - } - return false -} +var m = map[rune]struct{}{} -func UniqueChar(s string) bool { - r := []rune(s) - n := len(r) - for i := 0; i < n-1; i++ { - if InStr(r[i], s[i+1:n]) { +func uniqueChar(s string) bool { + for _, r := range s { + if _, ok := m[r]; ok { return false } + m[r] = struct{}{} } return true } -func InStr(c rune, s string) bool { - for _, r := range s { - if c == r { - return true - } - } - return false -} - -func ValidBase(base string) bool { - return len(base) >= 2 && !ContainsPlusMinus(base) && UniqueChar(base) +func validBase(base string) bool { + return len(base) >= 2 && !strings.ContainsAny(base, "+-") && uniqueChar(base) } -func Power(nbr int, pwr int) int { +func power(nbr int, pwr int) int { if pwr == 0 { return 1 } if pwr == 1 { return nbr } - return nbr * Power(nbr, pwr-1) -} - -func Index(s string, toFind string) int { - result := strings.Index(s, toFind) - return result + return nbr * power(nbr, pwr-1) } func AtoiBase(s string, base string) int { var result int var i int sign := 1 - lengthBase := len(base) - lengths := len(s) + length := len(s) - if !ValidBase(base) { + if !validBase(base) { return 0 } if s[i] == '-' { @@ -69,9 +44,9 @@ func AtoiBase(s string, base string) int { i++ } for i < len(s) { - result = result + (Index(base, string(s[i])) * Power(lengthBase, lengths-1)) + result += strings.Index(base, s[i]) * power(len(base), length-1) i++ - lengths-- + length-- } return result * sign } diff --git a/tests/go/solutions/atoiprog/main.go b/tests/go/solutions/atoiprog/main.go index e09c6098..bb8f71db 100644 --- a/tests/go/solutions/atoiprog/main.go +++ b/tests/go/solutions/atoiprog/main.go @@ -1,8 +1,6 @@ package main -import ( - "strconv" -) +import "strconv" func Atoi(s string) int { n, _ := strconv.Atoi(s) diff --git a/tests/go/solutions/balancedstring/test_balancedstring.go b/tests/go/solutions/balancedstring/test_balancedstring.go index 41cedfd6..a18ba41a 100644 --- a/tests/go/solutions/balancedstring/test_balancedstring.go +++ b/tests/go/solutions/balancedstring/test_balancedstring.go @@ -1,15 +1,9 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - // Declaration of an empty array of type string - table := []string{} - - // Filing of this array with the tests array provided. - table = append(table, + table := []string{ "CDCCDDCDCD", "CDDDDCCCDC", "DDDDCCCC", @@ -18,10 +12,10 @@ func main() { "CCCDDDCDCCCCDC", "DDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCC", "DDDDCDDDDCDDDCCC", - ) + } for i := 0; i < 15; i++ { - value := "" + s := "" chunks := z01.RandIntBetween(5, 10) for j := 0; j < chunks; j++ { countC := z01.RandIntBetween(1, 5) @@ -32,10 +26,10 @@ func main() { letter := z01.RandStr(1, "CD") if tmpC > 0 && letter == "C" { tmpC-- - value += letter + s += letter } else if tmpD > 0 && letter == "D" { tmpD-- - value += letter + s += letter } } @@ -45,20 +39,16 @@ func main() { letter := z01.RandStr(1, "CD") if tmpC > 0 && letter == "D" { tmpC-- - value += letter + s += letter } else if tmpD > 0 && letter == "C" { tmpD-- - value += letter + s += letter } } } - table = append(table, value) + table = append(table, s) } - //The table with 8 specific exercises and 15 randoms is now ready to be "challenged" - //This time, contrary to the nauuo exercise, - //We can use the ChallengeMainExam function. - for _, arg := range table { z01.ChallengeMain("balancedstring", arg) } diff --git a/tests/go/solutions/basicatoi.go b/tests/go/solutions/basicatoi.go index 6fdccdc7..837004bd 100644 --- a/tests/go/solutions/basicatoi.go +++ b/tests/go/solutions/basicatoi.go @@ -1,8 +1,6 @@ package solutions -import ( - "strconv" -) +import "strconv" func BasicAtoi(s string) int { n, _ := strconv.Atoi(s) diff --git a/tests/go/solutions/basicatoi2.go b/tests/go/solutions/basicatoi2.go index 00ce3468..cc585d8d 100644 --- a/tests/go/solutions/basicatoi2.go +++ b/tests/go/solutions/basicatoi2.go @@ -1,8 +1,6 @@ package solutions -import ( - "strconv" -) +import "strconv" func BasicAtoi2(s string) int { n, _ := strconv.Atoi(s) diff --git a/tests/go/solutions/boolean/main.go b/tests/go/solutions/boolean/main.go index 27cab30c..611016a1 100644 --- a/tests/go/solutions/boolean/main.go +++ b/tests/go/solutions/boolean/main.go @@ -25,7 +25,7 @@ func main() { lenOfArg := len(os.Args) - 1 - if isEven(lenOfArg) == true { + if isEven(lenOfArg) { printStr(EvenMsg) } else { printStr(OddMsg) diff --git a/tests/go/solutions/brackets/main.go b/tests/go/solutions/brackets/main.go index bd38bc7d..27c094d9 100644 --- a/tests/go/solutions/brackets/main.go +++ b/tests/go/solutions/brackets/main.go @@ -16,31 +16,30 @@ func matchBrackets(exp string) bool { } else if c == ')' { if ptr < 0 || opened[ptr] != '(' { return false - } else { - opened = opened[:len(opened)-1] - ptr-- } + opened = opened[:len(opened)-1] + ptr-- } else if c == ']' { if ptr < 0 || opened[ptr] != '[' { return false - } else { - opened = opened[:len(opened)-1] - ptr-- } + opened = opened[:len(opened)-1] + ptr-- } else if c == '}' { if ptr < 0 || opened[ptr] != '{' { return false - } else { - opened = opened[:len(opened)-1] - ptr-- } + opened = opened[:len(opened)-1] + ptr-- } } return len(opened) == 0 } func main() { - if len(os.Args) > 1 { + if len(os.Args) == 1 { + fmt.Println() + } else { for _, v := range os.Args[1:] { if matchBrackets(v) { fmt.Println("OK") @@ -48,7 +47,5 @@ func main() { fmt.Println("Error") } } - } else { - fmt.Println() } } diff --git a/tests/go/solutions/brackets/test_brackets.go b/tests/go/solutions/brackets/test_brackets.go index ab8cd531..3c3023c1 100644 --- a/tests/go/solutions/brackets/test_brackets.go +++ b/tests/go/solutions/brackets/test_brackets.go @@ -1,33 +1,38 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - oneArgs := []string{"(johndoe)", ")()", "([)]", "{2*[d - 3]/(12)}"} + oneArgs := []string{ + "(johndoe)", + ")()", + "([)]", + "{2*[d - 3]/(12)}", + } // 18 random tests ( at least half are valid) for i := 0; i < 3; i++ { - oneArgs = append(oneArgs, "("+z01.RandASCII()+")") - oneArgs = append(oneArgs, "["+z01.RandASCII()+"]") - oneArgs = append(oneArgs, "{"+z01.RandASCII()+"}") - oneArgs = append(oneArgs, "("+z01.RandAlnum()+")") - oneArgs = append(oneArgs, "["+z01.RandAlnum()+"]") - oneArgs = append(oneArgs, "{"+z01.RandAlnum()+"}") + oneArgs = append(oneArgs, + "("+z01.RandASCII()+")", + "["+z01.RandASCII()+"]", + "{"+z01.RandASCII()+"}", + "("+z01.RandAlnum()+")", + "["+z01.RandAlnum()+"]", + "{"+z01.RandAlnum()+"}", + ) } - // No args testig z01.ChallengeMain("brackets") for _, v := range oneArgs { z01.ChallengeMain("brackets", v) } - arg1 := []string{"", "{[(0 + 0)(1 + 1)](3*(-1)){()}}"} - arg2 := []string{"{][]}", "{3*[21/(12+ 23)]}"} - arg3 := []string{"{([)])}", "{{{something }- [something]}}", "there are"} - multArg := [][]string{arg1, arg2, arg3} + multArg := [][]string{ + {"", "{[(0 + 0)(1 + 1)](3*(-1)){()}}"}, + {"{][]}", "{3*[21/(12+ 23)]}"}, + {"{([)])}", "{{{something }- [something]}}", "there are"}, + } for _, v := range multArg { z01.ChallengeMain("brackets", v...) diff --git a/tests/go/solutions/brainfuck/main.go b/tests/go/solutions/brainfuck/main.go index f12e8864..64915c30 100644 --- a/tests/go/solutions/brainfuck/main.go +++ b/tests/go/solutions/brainfuck/main.go @@ -19,22 +19,22 @@ func main() { for i >= 0 && i < N { switch progpoint[i] { case '>': - //Increment the pointer + // Increment the pointer pos++ case '<': - //decrement the pointes + // decrement the pointes pos-- case '+': - //increment the pointed byte + // increment the pointed byte arby[pos]++ case '-': - //decrement the pointed byte + // decrement the pointed byte arby[pos]-- case '.': - //print the pointed byte on std output + // print the pointed byte on std output z01.PrintRune(rune(arby[pos])) case '[': - //go to the matching ']' if the pointed byte is 0 (while start) + // go to the matching ']' if the pointed byte is 0 (while start) openBr = 0 if arby[pos] == 0 { for i < N && (progpoint[i] != byte(']') || openBr > 1) { @@ -47,7 +47,7 @@ func main() { } } case ']': - //go to the matching '[' if the pointed byte is not 0 (while end) + // go to the matching '[' if the pointed byte is not 0 (while end) openBr = 0 if arby[pos] != 0 { for i >= 0 && (progpoint[i] != byte('[') || openBr > 1) { diff --git a/tests/go/solutions/btree.go b/tests/go/solutions/btree.go index 16497ecc..1ed44c86 100644 --- a/tests/go/solutions/btree.go +++ b/tests/go/solutions/btree.go @@ -108,7 +108,7 @@ func applyGivenOrder(root *TreeNode, level int, f func(...interface{}) (int, err } } -//Apply the function f level by level +// Apply the function f level by level func BTreeApplyByLevel(root *TreeNode, f func(...interface{}) (int, error)) { h := BTreeLevelCount(root) for i := 0; i < h; i++ { @@ -191,7 +191,7 @@ func BTreeRotateLeft(node *TreeNode) *TreeNode { return temp } -//Returns the maximum node in the subtree started by root +// Returns the maximum node in the subtree started by root func BTreeMax(root *TreeNode) *TreeNode { if root == nil || root.Right == nil { return root @@ -200,7 +200,7 @@ func BTreeMax(root *TreeNode) *TreeNode { return BTreeMax(root.Right) } -//Returns the minimum value in the subtree started by root +// Returns the minimum value in the subtree started by root func BTreeMin(root *TreeNode) *TreeNode { if root == nil || root.Left == nil { return root diff --git a/tests/go/solutions/capitalize.go b/tests/go/solutions/capitalize.go index 136eea1e..09bb621c 100644 --- a/tests/go/solutions/capitalize.go +++ b/tests/go/solutions/capitalize.go @@ -2,33 +2,19 @@ package solutions import ( "strings" + "unicode" ) -func isAlphaNumerical(r rune) bool { - return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') -} - -func isLowerRune(r rune) bool { - return r >= 'a' && r <= 'z' -} - -func toUpperRune(r rune) rune { - if r >= 'a' && r <= 'z' { - return r - 32 - } - return r -} - func Capitalize(s string) string { r := []rune(strings.ToLower(s)) - if isLowerRune(r[0]) { - r[0] = toUpperRune(r[0]) + if unicode.IsLower(r[0]) { + r[0] = unicode.ToUpper(r[0]) } for i := 1; i < len(r); i++ { - if (!isAlphaNumerical(r[i-1])) && (isLowerRune(r[i])) { - r[i] = toUpperRune(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/solutions/capitalizeprog/test_capitalizeprog.go b/tests/go/solutions/capitalizeprog/test_capitalizeprog.go index bfae291d..14e2a46c 100644 --- a/tests/go/solutions/capitalizeprog/test_capitalizeprog.go +++ b/tests/go/solutions/capitalizeprog/test_capitalizeprog.go @@ -1,12 +1,9 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - table := append( - z01.MultRandASCII(), + table := append(z01.MultRandASCII(), "Hello! How are you? How+are+things+4you?", "Hello! How are you?", "a", diff --git a/tests/go/solutions/challenge.go b/tests/go/solutions/challenge.go index 7860c179..f4167c32 100644 --- a/tests/go/solutions/challenge.go +++ b/tests/go/solutions/challenge.go @@ -5,7 +5,6 @@ import ( "runtime" "strconv" "strings" - "testing" "github.com/01-edu/z01" ) @@ -82,10 +81,12 @@ func ParentList(root *TreeNode) string { return r } -func ChallengeTree(t *testing.T, +func ChallengeTree( + name string, fn1, fn2 interface{}, arg1 *TreeNode, arg2 interface{}, - args ...interface{}) { + args ...interface{}, +) { args1 := []interface{}{arg1} args2 := []interface{}{arg2} @@ -99,8 +100,8 @@ func ChallengeTree(t *testing.T, st2 := z01.Monitor(fn2, args2) if st1.Stdout != st2.Stdout { - t.Fatalf("%s(\n%s)\n prints %s instead of %s\n", - z01.NameOfFunc(fn2), + z01.Fatalf("%s(\n%s)\n prints %s instead of %s\n", + name, FormatTree(arg1), z01.Format(st2.Stdout), z01.Format(st1.Stdout), @@ -108,29 +109,6 @@ func ChallengeTree(t *testing.T, } } -func Challenge(t *testing.T, fn1, fn2 interface{}, arg1, arg2 interface{}, args ...interface{}) { - args1 := []interface{}{arg1} - args2 := []interface{}{arg2} - - if args != nil { - for _, v := range args { - args1 = append(args1, v) - args2 = append(args2, v) - } - } - st1 := z01.Monitor(fn1, args1) - st2 := z01.Monitor(fn2, args2) - - if st1.Stdout != st2.Stdout { - t.Fatalf("%s(%s) prints %s instead of %s\n", - z01.NameOfFunc(fn2), - z01.Format(arg2), - z01.Format(st2.Stdout), - z01.Format(st1.Stdout), - ) - } -} - func PrintList(n *NodeI) string { var res string it := n diff --git a/tests/go/solutions/changeorder.go b/tests/go/solutions/changeorder.go index b733caed..d6f3d84f 100644 --- a/tests/go/solutions/changeorder.go +++ b/tests/go/solutions/changeorder.go @@ -1,12 +1,5 @@ package solutions -//This solution is the comparing file of the staff -// Because the solution is a function, -// -//1) here the package is solutions -//2) it does not need an empty func main(){} -//3) its location is 1 level below the folder of the nauuo_test.go file - func pushBack(node *NodeAddL, num int) *NodeAddL { nw := &NodeAddL{Num: num} if node == nil { diff --git a/tests/go/solutions/changeorder/changeorder_test.go b/tests/go/solutions/changeorder/changeorder_test.go index 04fffaa6..26ae9170 100644 --- a/tests/go/solutions/changeorder/changeorder_test.go +++ b/tests/go/solutions/changeorder/changeorder_test.go @@ -2,11 +2,10 @@ package main import ( "strconv" - "testing" "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) type stuNode = NodeAddL @@ -71,93 +70,37 @@ func solListToNum(node *solNode) int { return n } -func compareNodes(t *testing.T, stuResult *stuNode, solResult *solNode, num1 int) { +func compareNodes(stuResult *stuNode, solResult *solNode, num1 int) { solList := printSol(solNumToList(num1)) if stuResult == nil && solResult == nil { - } else if stuResult != nil && solResult == nil { + return + } + if stuResult != nil && solResult == nil { stuNum := stuListToNum(stuResult) - t.Fatalf("\nChangeorder(%s) == %v instead of %v\n\n", + z01.Fatalf("\nChangeorder(%s) == %v instead of %v\n\n", solList, stuNum, "") - } else if stuResult == nil && solResult != nil { + } + if stuResult == nil && solResult != nil { solNum := solListToNum(solResult) - t.Fatalf("\nChangeorder(%s) == %v instead of %v\n\n", + z01.Fatalf("\nChangeorder(%s) == %v instead of %v\n\n", solList, "", solNum) - } else { - stuNum := stuListToNum(stuResult) - solNum := solListToNum(solResult) - if stuNum != solNum { - t.Fatalf("\nChangeorder(%s) == %v instead of %v\n\n", - solList, stuNum, solNum) - } - } -} - -func TestChangeorder(t *testing.T) { - // Declaration of the node that is going to take the group of arguments that are going to - // inputed during each iteration of a Challenge between the student and the staff solution. - // (note: a node is not always necessary but in this case it makes the writing of the test easier) - - type node struct { - num1 int } - - // Declaration of an empty array of type node{} - // note that in this case this is the easiest type of table to declare - // but a table can be of any other relevant type, (for example []string{}, []int{} if it - // were a single string tested or a single int) - - table := []node{} - // Initial filling of that array with the values I see in the examples of the subject - - table = append(table, - node{1234567}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library - - for i := 0; i < 15; i++ { - value := node{ - num1: z01.RandIntBetween(0, 1000000000), - //this z01.RandIntBetween function allows the randomization of - //the int for each value in a desired range. - //Note that they are many others of those functions for other types of data - //Do not hesitate to have a look at all of them https://github.com/01-edu/z01 - } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - table = append(table, value) + stuNum := stuListToNum(stuResult) + solNum := solListToNum(solResult) + if stuNum != solNum { + z01.Fatalf("\nChangeorder(%s) == %v instead of %v\n\n", + solList, stuNum, solNum) } +} - //The table with 4 specific exercises and 15 randoms is now ready to be "challenged" - //Because the exercise asks for a function we are now using the Challenge function (this function would - // be the ChallengeMainExam function) +func main() { + table := []int{1234567} + table = append(table, z01.MultRandIntBetween(0, 1000000000)...) for _, arg := range table { - stuResult := Changeorder(stuNumToList(arg.num1)) - solResult := solutions.Changeorder(solNumToList(arg.num1)) + stuResult := Changeorder(stuNumToList(arg)) + solResult := solutions.Changeorder(solNumToList(arg)) - compareNodes(t, stuResult, solResult, arg.num1) + compareNodes(stuResult, solResult, arg) } - - // the z01.Challenge function is here applied to each argument of the table. It musts contains: - // 1) first, the t argument from the T structure imported from the package "testing" - // - // 2) second, the function from the student, in this case Nauuo - //(this disapears in the ChallengeMainExam function) - // 3) third, the function from the staff, in this case solutions.Nauuo - //(this disapears as well in the ChallengeMainExam function) - // 4) all the arguments to be tested, in this case it is the plus, minus and rand from each structure, - // notice that they are accessed with arg. (the arg notation comes from the way it was name in the - // range loop over the table) - - // Now that this is done. re-read the quickReadme (the test your test recap) and apply all the commands - // and intructions. We strongly advise to check that your error messages matches your subject. - // and that you ask a colleague to double check. - - //FINAL STEP: - // When both are satisfied with the coherence between the subject and its tests. The code can be commited - // and redeployed by the team-01. - // We then advised the staff team to test the new exercise invidually with their current build of the exam } diff --git a/tests/go/solutions/changeorder/main.go b/tests/go/solutions/changeorder/main.go index 4c2a3474..3e56dfd7 100644 --- a/tests/go/solutions/changeorder/main.go +++ b/tests/go/solutions/changeorder/main.go @@ -1,11 +1,5 @@ package main -//This solution is the placeholder of the student solution -// for an exercise in the exam asking for a Function -//Remember the disclaimer!!!! -//1) here the package is main -//2) It does need an empty func main(){} - type NodeAddL struct { Next *NodeAddL Num int diff --git a/tests/go/solutions/chunk/chunk_test.go b/tests/go/solutions/chunk/chunk_test.go index c86da8d8..156564ff 100644 --- a/tests/go/solutions/chunk/chunk_test.go +++ b/tests/go/solutions/chunk/chunk_test.go @@ -1,8 +1,9 @@ package main import ( - solutions "../../solutions" "github.com/01-edu/z01" + + solutions "../../solutions" ) func randomSize() []int { diff --git a/tests/go/solutions/cleanstr/test_cleanstr.go b/tests/go/solutions/cleanstr/test_cleanstr.go index 7a2a3178..13cedaf2 100644 --- a/tests/go/solutions/cleanstr/test_cleanstr.go +++ b/tests/go/solutions/cleanstr/test_cleanstr.go @@ -1,11 +1,10 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - args := []string{"you see it's easy to display the same thing", + args := []string{ + "you see it's easy to display the same thing", " only it's harder ", "how funny", "", @@ -15,8 +14,5 @@ func main() { for _, v := range args { z01.ChallengeMain("cleanstr", v) } - - arg1 := []string{"this is not", "happening"} - - z01.ChallengeMain("cleanstr", arg1...) + z01.ChallengeMain("cleanstr", "this is not", "happening") } diff --git a/tests/go/solutions/compare.go b/tests/go/solutions/compare.go index 4a096ee6..e381b4e5 100644 --- a/tests/go/solutions/compare.go +++ b/tests/go/solutions/compare.go @@ -1,9 +1,7 @@ package solutions -import ( - "strings" -) +import "strings" -func Compare(s string, toCompare string) int { - return strings.Compare(s, toCompare) +func Compare(a, b string) int { + return strings.Compare(a, b) } diff --git a/tests/go/solutions/comparenode.go b/tests/go/solutions/comparenode.go deleted file mode 100644 index 6b98ce7e..00000000 --- a/tests/go/solutions/comparenode.go +++ /dev/null @@ -1,33 +0,0 @@ -// +build ignore - -package solutions - -import ( - "testing" - - student "../student" -) - -func CompareNode(t *testing.T, a *solutions.TreeNode, b *student.TreeNode) { - if a != nil && b != nil { - if a.Data != b.Data { - t.Fatalf("expected %s instead of %s\n", - a.Data, - b.Data, - ) - CompareNode(t, a.Parent, b.Parent) - CompareNode(t, a.Left, b.Left) - CompareNode(t, a.Right, b.Right) - } - } else if a != nil && b == nil { - t.Fatalf("expected %s instead of %v\n", - a.Data, - b, - ) - } else if a == nil && b != nil { - t.Fatalf("expected %v instead of %v\n", - a, - b.Data, - ) - } -} diff --git a/tests/go/solutions/compareprog/test_compareprog.go b/tests/go/solutions/compareprog/test_compareprog.go index d70e2a9f..afb5fe4e 100644 --- a/tests/go/solutions/compareprog/test_compareprog.go +++ b/tests/go/solutions/compareprog/test_compareprog.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { type node struct { @@ -28,11 +26,10 @@ func main() { wordToTest := z01.RandASCII() wrongMatch := z01.RandASCII() - val := node{ + table = append(table, node{ s: wordToTest, toCompare: wrongMatch, - } - table = append(table, val) + }) } // those are the test values from the README examples table = append(table, diff --git a/tests/go/solutions/comparereturn.go b/tests/go/solutions/comparereturn.go deleted file mode 100644 index 8b01e2ef..00000000 --- a/tests/go/solutions/comparereturn.go +++ /dev/null @@ -1,36 +0,0 @@ -// +build ignore - -package solutions - -import ( - "reflect" - "testing" - - "github.com/01-edu/z01" - - student "../student" -) - -func CompareReturn(t *testing.T, fn1, fn2, arg1, arg2 interface{}) { - arar1 := []interface{}{arg1} - arar2 := []interface{}{arg2} - - out1 := z01.Monitor(fn1, arar1) - out2 := z01.Monitor(fn2, arar2) - - for i, v := range out1.Results { - switch str := v.(type) { - case *solutions.TreeNode: - CompareNode(t, str, out2.Results[i].(*student.TreeNode)) - default: - if !reflect.DeepEqual(str, out2.Results[i]) { - t.Fatalf("%s(%s) == %s instead of %s\n", - z01.NameOfFunc(fn1), - z01.Format(arg1), - z01.Format(out1.Results...), - z01.Format(out2.Results...), - ) - } - } - } -} diff --git a/tests/go/solutions/comparetrees.go b/tests/go/solutions/comparetrees.go deleted file mode 100644 index 006ae503..00000000 --- a/tests/go/solutions/comparetrees.go +++ /dev/null @@ -1,24 +0,0 @@ -// +build ignore - -package solutions - -import ( - "testing" - - student "../student" -) - -func CompareTrees(root *solutions.TreeNode, rootS *student.TreeNode, t *testing.T) { - if root != nil && rootS != nil { - CompareTrees(root.Left, rootS.Left, t) - CompareTrees(root.Right, rootS.Right, t) - if root.Data != rootS.Data { - t.Fatalf("BTreeInsertData(%v), node == %v instead of %v ", - root.Data, root.Data, rootS.Data) - } - } else if root != nil && rootS == nil { - t.Fatalf("BTreeInsertData(%v), node == %v instead of %v ", root, root, rootS) - } else if root == nil && rootS != nil { - t.Fatalf("BTreeInsertData(%v), node == %v instead of %v ", root, root, rootS) - } -} diff --git a/tests/go/solutions/concatparams.go b/tests/go/solutions/concatparams.go index feaf3bc8..e84db826 100644 --- a/tests/go/solutions/concatparams.go +++ b/tests/go/solutions/concatparams.go @@ -1,8 +1,6 @@ package solutions -import ( - "strings" -) +import "strings" func ConcatParams(args []string) string { return strings.Join(args, "\n") diff --git a/tests/go/solutions/costumeprofit/main.go b/tests/go/solutions/costumeprofit/main.go index cc8fe764..443b0b0a 100644 --- a/tests/go/solutions/costumeprofit/main.go +++ b/tests/go/solutions/costumeprofit/main.go @@ -6,31 +6,24 @@ import ( "strconv" ) -//This solution is the comparing file of the staff -// Because the solution is a function, -// -//1) here the package is solutions -//2) it does not need an empty func main(){} -//3) its location is 1 level below the folder of the nauuo_test.go file - func min(numbers ...int) int { - minVal := numbers[0] - for i := 0; i < len(numbers); i++ { - if numbers[i] < minVal { - minVal = numbers[i] + min := numbers[0] + for _, i := range numbers { + if i < min { + min = i } } - return minVal + return min } func max(numbers ...int) int { - maxVal := numbers[0] - for i := 0; i < len(numbers); i++ { - if numbers[i] > maxVal { - maxVal = numbers[i] + max := numbers[0] + for _, i := range numbers { + if i > max { + max = i } } - return maxVal + return max } func Costume_profit(a, b, c, d, e, f int) int { diff --git a/tests/go/solutions/countdown/test_countdown.go b/tests/go/solutions/countdown/test_countdown.go index a51c428e..a9e0fb58 100644 --- a/tests/go/solutions/countdown/test_countdown.go +++ b/tests/go/solutions/countdown/test_countdown.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("countdown") diff --git a/tests/go/solutions/createElem.go b/tests/go/solutions/createelem.go similarity index 100% rename from tests/go/solutions/createElem.go rename to tests/go/solutions/createelem.go diff --git a/tests/go/solutions/displaya/main.go b/tests/go/solutions/displaya/main.go index 1ba1bc69..b62cea25 100644 --- a/tests/go/solutions/displaya/main.go +++ b/tests/go/solutions/displaya/main.go @@ -1,8 +1,6 @@ package main -import ( - "fmt" -) +import "fmt" func main() { fmt.Println("a") diff --git a/tests/go/solutions/displayalpham/main.go b/tests/go/solutions/displayalpham/main.go index 6ff98ea4..44ffb600 100644 --- a/tests/go/solutions/displayalpham/main.go +++ b/tests/go/solutions/displayalpham/main.go @@ -1,14 +1,12 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - dif := 'a' - 'A' + diff := 'a' - 'A' for c := 'a'; c <= 'z'; c++ { if c%2 == 0 { - z01.PrintRune(c - dif) + z01.PrintRune(c - diff) } else { z01.PrintRune(c) } diff --git a/tests/go/solutions/displayalpham/test_displayalpham.go b/tests/go/solutions/displayalpham/test_displayalpham.go index 38bf1656..8cfa9ce0 100644 --- a/tests/go/solutions/displayalpham/test_displayalpham.go +++ b/tests/go/solutions/displayalpham/test_displayalpham.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("displayalpham") diff --git a/tests/go/solutions/displayalrevm/main.go b/tests/go/solutions/displayalrevm/main.go index f98d80ea..f0ff0eb3 100644 --- a/tests/go/solutions/displayalrevm/main.go +++ b/tests/go/solutions/displayalrevm/main.go @@ -1,16 +1,14 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - dif := 'a' - 'A' + diff := 'a' - 'A' for c := 'z'; c >= 'a'; c-- { if c%2 == 0 { z01.PrintRune(c) } else { - z01.PrintRune(c - dif) + z01.PrintRune(c - diff) } } z01.PrintRune('\n') diff --git a/tests/go/solutions/displayalrevm/test_displayalrevm.go b/tests/go/solutions/displayalrevm/test_displayalrevm.go index 832d2d01..ab6bf4e2 100644 --- a/tests/go/solutions/displayalrevm/test_displayalrevm.go +++ b/tests/go/solutions/displayalrevm/test_displayalrevm.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("displayalrevm") diff --git a/tests/go/solutions/displayz/main.go b/tests/go/solutions/displayz/main.go index 425e87bc..9fe2f625 100644 --- a/tests/go/solutions/displayz/main.go +++ b/tests/go/solutions/displayz/main.go @@ -1,8 +1,6 @@ package main -import ( - "fmt" -) +import "fmt" func main() { fmt.Println("z") diff --git a/tests/go/solutions/doppelganger.go b/tests/go/solutions/doppelganger.go index bacca32c..5f471cd7 100644 --- a/tests/go/solutions/doppelganger.go +++ b/tests/go/solutions/doppelganger.go @@ -1,9 +1,7 @@ package solutions -import ( - "strings" -) +import "strings" -func DoppelGanger(big, little string) int { - return strings.LastIndex(big, little) +func DoppelGanger(s, substr string) int { + return strings.LastIndex(s, substr) } diff --git a/tests/go/solutions/doppelgangerprog/doppelgangerprog_test.go b/tests/go/solutions/doppelgangerprog/doppelgangerprog_test.go index dbb9e1e3..2e6e8851 100644 --- a/tests/go/solutions/doppelgangerprog/doppelgangerprog_test.go +++ b/tests/go/solutions/doppelgangerprog/doppelgangerprog_test.go @@ -1,8 +1,9 @@ package main import ( - solutions "../../solutions" "github.com/01-edu/z01" + + solutions "../../solutions" ) type node struct { diff --git a/tests/go/solutions/doppelgangerprog/main.go b/tests/go/solutions/doppelgangerprog/main.go index 85169a68..b1ab7fff 100644 --- a/tests/go/solutions/doppelgangerprog/main.go +++ b/tests/go/solutions/doppelgangerprog/main.go @@ -1,14 +1,9 @@ package main -import ( - "strings" -) +import "strings" -func DoppelGanger(big, little string) int { - if little == "" { - return -1 - } - return strings.LastIndex(big, little) +func DoppelGanger(s, substr string) int { + return strings.LastIndex(s, substr) } func main() { diff --git a/tests/go/solutions/eightqueens.go b/tests/go/solutions/eightqueens.go index 833faab7..a46afcfe 100644 --- a/tests/go/solutions/eightqueens.go +++ b/tests/go/solutions/eightqueens.go @@ -1,8 +1,6 @@ package solutions -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" const size = 8 @@ -20,8 +18,8 @@ func goodDirection(x, y, vx, vy int) bool { // Not a good line : the square is already occupied return false } - x = x + vx // Move x in the right direction - y = y + vy // Move y in the right direction + x += vx // Move x in the right direction + y += vy // Move y in the right direction } // All clear return true diff --git a/tests/go/solutions/enigma.go b/tests/go/solutions/enigma.go index 7d868e5f..3bdc29ae 100644 --- a/tests/go/solutions/enigma.go +++ b/tests/go/solutions/enigma.go @@ -1,6 +1,6 @@ package solutions -//this function will put a in c; c in d; d in b and b in a +// 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 @@ -11,7 +11,7 @@ func Enigma(a ***int, b *int, c *******int, d ****int) { ***a = valb } -//Helper function used in the test for checking the function Enigma() +// 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 diff --git a/tests/go/solutions/expandstr/test_expandstr.go b/tests/go/solutions/expandstr/test_expandstr.go index 2fc53d70..f2e73925 100644 --- a/tests/go/solutions/expandstr/test_expandstr.go +++ b/tests/go/solutions/expandstr/test_expandstr.go @@ -1,21 +1,16 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - arg1 := []string{"hello", "you"} - arg2 := []string{" only it's harder "} - arg3 := []string{"you see it's easy to display the same thing"} - args := [][]string{arg1, arg2, arg3} - - // adding of 15 random valid tests - for i := 0; i < 15; i++ { - randomArg := []string{z01.RandWords()} - args = append(args, randomArg) + args := [][]string{ + {"hello", "you"}, + {" only it's harder "}, + {"you see it's easy to display the same thing"}, } + args = append(args, z01.MultRandWords()) + for _, v := range args { z01.ChallengeMain("expandstr", v...) } diff --git a/tests/go/solutions/fib.go b/tests/go/solutions/fib.go index 1cca543e..67cb21f1 100644 --- a/tests/go/solutions/fib.go +++ b/tests/go/solutions/fib.go @@ -5,7 +5,6 @@ func rec(a, b, cnt int) int { return -1 } if a == b { - // fmt.Printf("%d\n", cnt) return cnt } if rec(a*2, b, cnt+1) != -1 { @@ -24,7 +23,7 @@ func Fib(n int) int { t1 := 0 t2 := 1 for i := 2; i <= n; i++ { - t1 = t1 + t2 + t1 += t2 tmp := t1 t1 = t2 t2 = tmp diff --git a/tests/go/solutions/fib/fib_test.go b/tests/go/solutions/fib/fib_test.go index d0705bfb..0c2e9b0a 100644 --- a/tests/go/solutions/fib/fib_test.go +++ b/tests/go/solutions/fib/fib_test.go @@ -3,75 +3,18 @@ package main import ( "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) func main() { - // Declaration of the node that is going to take the group of arguments that are going to - // inputed during each iteration of a Challenge between the student and the staff solution. - // (note: a node is not always necessary but in this case it makes the writing of the test easier) - - type node struct { - n int + table := []int{ + 20, + 0, + 9, + 2, } - - // Declaration of an empty array of type node{} - // note that in this case this is the easiest type of table to declare - // but a table can be of any other relevant type, (for example []string{}, []int{} if it - // were a single string tested or a single int) - - table := []node{} - // Initial filling of that array with the values I see in the examples of the subject - - table = append(table, - node{20}, - node{0}, - node{9}, - node{2}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library - - for i := 0; i < 15; i++ { - value := node{ - n: z01.RandIntBetween(-100, 150), - //this z01.RandIntBetween function allows the randomization of - //the int for each value in a desired range. - //Note that they are many others of those functions for other types of data - //Do not hesitate to have a look at all of them https://github.com/01-edu/z01 - } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - table = append(table, value) - } - - //The table with 4 specific exercises and 15 randoms is now ready to be "challenged" - //Because the exercise asks for a function we are now using the Challenge function (this function would - // be the ChallengeMainExam function) - + table = append(table, z01.MultRandIntBetween(-100, 150)...) for _, arg := range table { - z01.Challenge("Fib", Fib, solutions.Fib, arg.n) + z01.Challenge("Fib", Fib, solutions.Fib, arg) } - - // the z01.Challenge function is here applied to each argument of the table. It musts contains: - // 1) first, the t argument from the T structure imported from the package "testing" - // - // 2) second, the function from the student, in this case Nauuo - //(this disapears in the ChallengeMainExam function) - // 3) third, the function from the staff, in this case solutions.Nauuo - //(this disapears as well in the ChallengeMainExam function) - // 4) all the arguments to be tested, in this case it is the plus, minus and rand from each structure, - // notice that they are accessed with arg. (the arg notation comes from the way it was name in the - // range loop over the table) - - // Now that this is done. re-read the quickReadme (the test your test recap) and apply all the commands - // and intructions. We strongly advise to check that your error messages matches your subject. - // and that you ask a colleague to double check. - - //FINAL STEP: - // When both are satisfied with the coherence between the subject and its tests. The code can be commited - // and redeployed by the team-01. - // We then advised the staff team to test the new exercise invidually with their current build of the exam } diff --git a/tests/go/solutions/fib/main.go b/tests/go/solutions/fib/main.go index 702c1f2b..8469c14e 100644 --- a/tests/go/solutions/fib/main.go +++ b/tests/go/solutions/fib/main.go @@ -5,7 +5,6 @@ func rec(a, b, cnt int) int { return -1 } if a == b { - // fmt.Printf("%d\n", cnt) return cnt } if rec(a*2, b, cnt+1) != -1 { @@ -24,7 +23,7 @@ func Fib(n int) int { t1 := 0 t2 := 1 for i := 2; i <= n; i++ { - t1 = t1 + t2 + t1 += t2 tmp := t1 t1 = t2 t2 = tmp diff --git a/tests/go/solutions/findnextprime.go b/tests/go/solutions/findnextprime.go index a50c0698..a898ac55 100644 --- a/tests/go/solutions/findnextprime.go +++ b/tests/go/solutions/findnextprime.go @@ -1,25 +1,22 @@ package solutions -import ( - "math" -) +import "math" -func FindNextPrime(value int) int { - isPrime := func(value int) bool { - if value < 2 { +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 } - limit := int(math.Floor(math.Sqrt(float64(value)))) - i := 2 - for i <= limit { - if value%i == 0 { - return false - } - i++ - } - return true + i++ } - + return true +} +func FindNextPrime(value int) int { if isPrime(value) { return value } diff --git a/tests/go/solutions/findprevprimeprog/findprevprimeprog_test.go b/tests/go/solutions/findprevprimeprog/findprevprimeprog_test.go index a79ae3e7..f5b0cff4 100644 --- a/tests/go/solutions/findprevprimeprog/findprevprimeprog_test.go +++ b/tests/go/solutions/findprevprimeprog/findprevprimeprog_test.go @@ -1,17 +1,14 @@ package main import ( - solutions "../../solutions" "github.com/01-edu/z01" + + solutions "../../solutions" ) func main() { - array := []int{5, 4, 1} - for i := 0; i < 7; i++ { - array = append(array, z01.RandIntBetween(0, 99999)) - } - - for i := 0; i < len(array); i++ { - z01.Challenge("FindPrevPrimeProg", FindPrevPrime, solutions.FindPrevPrime, array[i]) + a := append(z01.MultRandIntBetween(0, 99999), 5, 4, 1) + for _, elem := range a { + z01.Challenge("FindPrevPrimeProg", FindPrevPrime, solutions.FindPrevPrime, elem) } } diff --git a/tests/go/solutions/firstword/test_firstword.go b/tests/go/solutions/firstword/test_firstword.go index 16de53e8..78b5310e 100644 --- a/tests/go/solutions/firstword/test_firstword.go +++ b/tests/go/solutions/firstword/test_firstword.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { table := append(z01.MultRandWords(), @@ -10,11 +8,10 @@ func main() { " a as", " f d", " asd ad", + " salut !!! ", + " salut ! ! !", + "salut ! !", ) - table = append(table, " salut !!! ") - table = append(table, " salut ! ! !") - table = append(table, "salut ! !") - for _, s := range table { z01.ChallengeMain("firstword", s) } diff --git a/tests/go/solutions/fixthemain/main.go b/tests/go/solutions/fixthemain/main.go index 71eb7a61..89205ba9 100644 --- a/tests/go/solutions/fixthemain/main.go +++ b/tests/go/solutions/fixthemain/main.go @@ -9,10 +9,9 @@ type Door struct { State int } -func PrintStr(str string) { - arrayRune := []rune(str) - for _, s := range arrayRune { - z01.PrintRune(s) +func PrintStr(s string) { + for _, r := range s { + z01.PrintRune(r) } z01.PrintRune('\n') } @@ -29,18 +28,12 @@ func OpenDoor(ptrdoor *Door) { func IsDoorOpened(ptrDoor *Door) bool { PrintStr("is the Door opened ?") - if ptrDoor.State == OPEN { - return true - } - return false + return ptrDoor.State == OPEN } func IsDoorClosed(ptrDoor *Door) bool { PrintStr("is the Door closed ?") - if ptrDoor.State == CLOSE { - return true - } - return false + return ptrDoor.State == CLOSE } func main() { diff --git a/tests/go/solutions/flags/main.go b/tests/go/solutions/flags/main.go index 9f55565b..f9632b05 100644 --- a/tests/go/solutions/flags/main.go +++ b/tests/go/solutions/flags/main.go @@ -13,22 +13,6 @@ type helpMs struct { handler string } -type sortRunes []rune - -//to implement the sort for a []rune it is necessary to -//implement Lessm, Swap and Len functions for the sort interface -func (s sortRunes) Less(i, j int) bool { - return s[i] < s[j] -} - -func (s sortRunes) Swap(i, j int) { - s[i], s[j] = s[j], s[i] -} - -func (s sortRunes) Len() int { - return len(s) -} - func obtainValues(value, strsplit string) string { values := strings.Split(value, "=") return values[len(values)-1] @@ -60,7 +44,7 @@ func main() { fmt.Println(" ", v.handler) } } else if size <= 4 { - var str []rune + var runes []rune strToInsert := "" var order bool @@ -70,17 +54,19 @@ func main() { } else if strings.Contains(os.Args[i], "--order") || strings.Contains(os.Args[i], "-o") { order = true } else { - str = []rune(os.Args[i]) + runes = []rune(os.Args[i]) } } if strToInsert != "" { - concatStr := string(str) + strToInsert - str = []rune(concatStr) + concatStr := string(runes) + strToInsert + runes = []rune(concatStr) } - if order == true { - sort.Sort(sortRunes(str)) + if order { + sort.Slice(runes, func(i, j int) bool { + return runes[i] < runes[j] + }) } - fmt.Println(string(str)) + fmt.Println(string(runes)) } } diff --git a/tests/go/solutions/foldint.go b/tests/go/solutions/foldint.go index 6291bc85..008d9804 100644 --- a/tests/go/solutions/foldint.go +++ b/tests/go/solutions/foldint.go @@ -1,12 +1,10 @@ package solutions -import ( - "fmt" -) +import "fmt" -func FoldInt(f func(int, int) int, arr []int, n int) { +func FoldInt(f func(int, int) int, a []int, n int) { result := n - for _, v := range arr { + for _, v := range a { result = f(result, v) } fmt.Println(result) diff --git a/tests/go/solutions/foldint/foldint_test.go b/tests/go/solutions/foldint/foldint_test.go index a8800609..0bf3d36b 100644 --- a/tests/go/solutions/foldint/foldint_test.go +++ b/tests/go/solutions/foldint/foldint_test.go @@ -1,8 +1,9 @@ package main import ( - solutions "../../solutions" "github.com/01-edu/z01" + + solutions "../../solutions" ) func main() { diff --git a/tests/go/solutions/foldint/main.go b/tests/go/solutions/foldint/main.go index b8ac7126..0952c988 100644 --- a/tests/go/solutions/foldint/main.go +++ b/tests/go/solutions/foldint/main.go @@ -2,12 +2,13 @@ package main import "fmt" -func FoldInt(f func(int, int) int, arr []int, n int) { +func FoldInt(f func(int, int) int, a []int, n int) { result := n - for _, v := range arr { + for _, v := range a { result = f(result, v) } fmt.Println(result) } + func main() { } diff --git a/tests/go/solutions/foreach.go b/tests/go/solutions/foreach.go index ccc27fb5..616d7c96 100644 --- a/tests/go/solutions/foreach.go +++ b/tests/go/solutions/foreach.go @@ -1,27 +1,7 @@ package solutions -import ( - "fmt" -) - -func ForEach(f func(int), arr []int) { - for _, el := range arr { +func ForEach(f func(int), a []int) { + for _, el := range a { f(el) } } - -func Add0(nbr int) { - fmt.Println(nbr) -} - -func Add1(nbr int) { - fmt.Println(nbr + 1) -} - -func Add2(nbr int) { - fmt.Println(nbr + 2) -} - -func Add3(nbr int) { - fmt.Println(nbr + 3) -} diff --git a/tests/go/solutions/foreachprog/foreachprog_test.go b/tests/go/solutions/foreachprog/foreachprog_test.go index fe2d6577..9920ca4a 100644 --- a/tests/go/solutions/foreachprog/foreachprog_test.go +++ b/tests/go/solutions/foreachprog/foreachprog_test.go @@ -1,38 +1,51 @@ package main import ( + "fmt" + "github.com/01-edu/z01" solutions "../../solutions" ) +func add0(i int) { + fmt.Println(i) +} +func add1(i int) { + fmt.Println(i + 1) +} +func add2(i int) { + fmt.Println(i + 2) +} +func add3(i int) { + fmt.Println(i + 3) +} + func main() { - functionsArray := []func(int){solutions.Add0, solutions.Add1, solutions.Add2, solutions.Add3} + functions := []func(int){add0, add1, add2, add3} type node struct { - f func(int) - arr []int + f func(int) + a []int } table := []node{} - //15 random slice of random ints with a random function from selection - + // 15 random slice of random ints with a random function from selection for i := 0; i < 15; i++ { - functionSelected := functionsArray[z01.RandIntBetween(0, len(functionsArray)-1)] - val := node{ - f: functionSelected, - arr: z01.MultRandIntBetween(-1000000, 1000000), - } - table = append(table, val) + function := functions[z01.RandIntBetween(0, len(functions)-1)] + table = append(table, node{ + f: function, + a: z01.MultRandIntBetween(-1000000, 1000000), + }) } table = append(table, node{ - f: solutions.Add0, - arr: []int{1, 2, 3, 4, 5, 6}, + f: add0, + a: []int{1, 2, 3, 4, 5, 6}, }) for _, arg := range table { - z01.Challenge("ForEachProg", ForEach, solutions.ForEach, arg.f, arg.arr) + z01.Challenge("ForEachProg", ForEach, solutions.ForEach, arg.f, arg.a) } } diff --git a/tests/go/solutions/foreachprog/main.go b/tests/go/solutions/foreachprog/main.go index ee39c13c..1b699af2 100644 --- a/tests/go/solutions/foreachprog/main.go +++ b/tests/go/solutions/foreachprog/main.go @@ -1,30 +1,10 @@ package main -import ( - "fmt" -) - -func ForEach(f func(int), arr []int) { - for _, el := range arr { +func ForEach(f func(int), a []int) { + for _, el := range a { f(el) } } -func Add0(nbr int) { - fmt.Println(nbr) -} - -func Add1(nbr int) { - fmt.Println(nbr + 1) -} - -func Add2(nbr int) { - fmt.Println(nbr + 2) -} - -func Add3(nbr int) { - fmt.Println(nbr + 3) -} - func main() { } diff --git a/tests/go/solutions/fprime/main.go b/tests/go/solutions/fprime/main.go index 0a44ea34..6e744739 100644 --- a/tests/go/solutions/fprime/main.go +++ b/tests/go/solutions/fprime/main.go @@ -9,30 +9,29 @@ import ( ) func fprime(value int) { - if value != 1 { - divisionIterator := 2 - for value > 1 { - if value%divisionIterator == 0 { - fmt.Print(divisionIterator) - value = value / divisionIterator + if value == 1 { + return + } + divisionIterator := 2 + for value > 1 { + if value%divisionIterator == 0 { + fmt.Print(divisionIterator) + value = value / divisionIterator - if value > 1 { - z01.PrintRune('*') - } - divisionIterator-- + if value > 1 { + z01.PrintRune('*') } - divisionIterator++ + divisionIterator-- } + divisionIterator++ } - z01.PrintRune('\n') } func main() { - if len(os.Args) != 2 { - z01.PrintRune('\n') - } else { - par, _ := strconv.Atoi(os.Args[1]) - fprime(par) + if len(os.Args) == 2 { + if i, err := strconv.Atoi(os.Args[1]); err == nil { + fprime(i) + } } } diff --git a/tests/go/solutions/fprime/test_fprime.go b/tests/go/solutions/fprime/test_fprime.go index 8de340e4..af4d3aba 100644 --- a/tests/go/solutions/fprime/test_fprime.go +++ b/tests/go/solutions/fprime/test_fprime.go @@ -2,31 +2,29 @@ package main import ( "strconv" - "strings" "github.com/01-edu/z01" ) func main() { - table := []string{} + table := []string{ + " ", + "1", + "1 1", + "hello", + "p 1", + "804577", + "225225", + "8333325", + "42", + "9539", + "1000002", + "1000003", + } for i := 0; i < 10; i++ { table = append(table, strconv.Itoa(z01.RandIntBetween(1, 100))) } - - table = append(table, " ") - table = append(table, "1") - table = append(table, "1 1") - table = append(table, "hello") - table = append(table, "p 1") - table = append(table, "804577") - table = append(table, "225225") - table = append(table, "8333325") - table = append(table, "42") - table = append(table, "9539") - table = append(table, "1000002") - table = append(table, "1000003") - for _, s := range table { - z01.ChallengeMain("fprime", strings.Fields(s)...) + z01.ChallengeMain("fprime", s) } } diff --git a/tests/go/solutions/game23.go b/tests/go/solutions/game23.go index f8e1df56..9832485a 100644 --- a/tests/go/solutions/game23.go +++ b/tests/go/solutions/game23.go @@ -5,7 +5,6 @@ func Game23(a, b int) int { return -1 } if a == b { - // fmt.Printf("%d\n", cnt) return 0 } if Game23(a*2, b) != -1 { diff --git a/tests/go/solutions/game23/game23_test.go b/tests/go/solutions/game23/game23_test.go index cd2a1e51..c226fbeb 100644 --- a/tests/go/solutions/game23/game23_test.go +++ b/tests/go/solutions/game23/game23_test.go @@ -3,7 +3,7 @@ package main import ( "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) func nd(a, b int) int { @@ -11,7 +11,6 @@ func nd(a, b int) int { return -1 } if a == b { - // fmt.Printf("%d\n", cnt) return 0 } if nd(a*2, b) != -1 { @@ -24,46 +23,22 @@ func nd(a, b int) int { } func main() { - // Declaration of the node that is going to take the group of arguments that are going to - // inputed during each iteration of a Challenge between the student and the staff solution. - // (note: a node is not always necessary but in this case it makes the writing of the test easier) - type node struct { init int fin int } - - // Declaration of an empty array of type node{} - // note that in this case this is the easiest type of table to declare - // but a table can be of any other relevant type, (for example []string{}, []int{} if it - // were a single string tested or a single int) - - table := []node{} - // Initial filling of that array with the values I see in the examples of the subject - - table = append(table, - node{50, 43}, - node{13, 13}, - node{10, 9}, - node{5, 9}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library + table := []node{ + {50, 43}, + {13, 13}, + {10, 9}, + {5, 9}, + } for i := 0; i < 20; i++ { - value := node{ + table = append(table, node{ init: z01.RandIntBetween(1, 1000), fin: z01.RandIntBetween(1, 1000), - //this z01.RandIntBetween function allows the randomization of - //the int for each value in a desired range. - //Note that they are many others of those functions for other types of data - //Do not hesitate to have a look at all of them https://github.com/01-edu/z01 - } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - table = append(table, value) + }) } for i := 1; i < 100; i++ { @@ -76,42 +51,10 @@ func main() { init: 1, fin: i, } - //this z01.RandIntBetween function allows the randomization of - //the int for each value in a desired range. - //Note that they are many others of those functions for other types of data - //Do not hesitate to have a look at all of them https://github.com/01-edu/z01 } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. table = append(table, value) } - - //The table with 4 specific exercises and 15 randoms is now ready to be "challenged" - //Because the exercise asks for a function we are now using the Challenge function (this function would - // be the ChallengeMainExam function) - for _, arg := range table { z01.Challenge("Game23", Game23, solutions.Game23, arg.init, arg.fin) } - - // the z01.Challenge function is here applied to each argument of the table. It musts contains: - // 1) first, the t argument from the T structure imported from the package "testing" - // - // 2) second, the function from the student, in this case Nauuo - //(this disapears in the ChallengeMainExam function) - // 3) third, the function from the staff, in this case solutions.Nauuo - //(this disapears as well in the ChallengeMainExam function) - // 4) all the arguments to be tested, in this case it is the plus, minus and rand from each structure, - // notice that they are accessed with arg. (the arg notation comes from the way it was name in the - // range loop over the table) - - // Now that this is done. re-read the quickReadme (the test your test recap) and apply all the commands - // and intructions. We strongly advise to check that your error messages matches your subject. - // and that you ask a colleague to double check. - - //FINAL STEP: - // When both are satisfied with the coherence between the subject and its tests. The code can be commited - // and redeployed by the team-01. - // We then advised the staff team to test the new exercise invidually with their current build of the exam } diff --git a/tests/go/solutions/game23/main.go b/tests/go/solutions/game23/main.go index 797e8477..228e1934 100644 --- a/tests/go/solutions/game23/main.go +++ b/tests/go/solutions/game23/main.go @@ -5,7 +5,6 @@ func Game23(a, b int) int { return -1 } if a == b { - // fmt.Printf("%d\n", cnt) return 0 } if Game23(a*2, b) != -1 { diff --git a/tests/go/solutions/gcd/main.go b/tests/go/solutions/gcd/main.go index 9d958957..f6cd7eb3 100644 --- a/tests/go/solutions/gcd/main.go +++ b/tests/go/solutions/gcd/main.go @@ -6,26 +6,21 @@ import ( "strconv" ) -//Greatest common divisor -func gcd(num1, num2 uint) uint { +// Greatest common divisor +func gcd(num1, num2 int) int { for i := num1; i > 0; i-- { if num1%i == 0 && num2%i == 0 { return i } } - return 1 } func main() { if len(os.Args) != 3 { - fmt.Println() - os.Exit(0) + return } - v1, _ := strconv.Atoi(os.Args[1]) - v2, _ := strconv.Atoi(os.Args[2]) - - fmt.Println(gcd(uint(v1), uint(v2))) + fmt.Println(gcd(v1, v2)) } diff --git a/tests/go/solutions/gcd/test_gcd.go b/tests/go/solutions/gcd/test_gcd.go index 7ffe8ab2..e1568ff0 100644 --- a/tests/go/solutions/gcd/test_gcd.go +++ b/tests/go/solutions/gcd/test_gcd.go @@ -7,19 +7,18 @@ import ( ) func main() { - arg1 := []string{"23"} - arg2 := []string{"12", "23"} - arg3 := []string{"25", "15"} - arg4 := []string{"23043", "122"} - arg5 := []string{"11", "77"} - args := [][]string{arg1, arg2, arg3, arg4, arg5} - + args := [][]string{ + {"23"}, + {"12", "23"}, + {"25", "15"}, + {"23043", "122"}, + {"11", "77"}, + } for i := 0; i < 25; i++ { number1 := strconv.Itoa(z01.RandIntBetween(1, 100000)) number2 := strconv.Itoa(z01.RandIntBetween(1, 100)) args = append(args, []string{number1, number2}) } - for _, v := range args { z01.ChallengeMain("gcd", v...) } diff --git a/tests/go/solutions/grouping/main.go b/tests/go/solutions/grouping/main.go index 2f2f791b..9be334d7 100644 --- a/tests/go/solutions/grouping/main.go +++ b/tests/go/solutions/grouping/main.go @@ -4,49 +4,25 @@ import ( "fmt" "os" "strings" + "unicode" ) -func main() { - //brackets("al|b", "ale atg bar sim nao pro par impar") In JS it's used without brackets - if len(os.Args) == 3 { - brackets(os.Args[1], os.Args[2]) - } else { - fmt.Println() - } -} - -func brackets(regexp, text string) { - if len(text) == 0 || len(regexp) == 0 { - fmt.Println() - return - } - reArr := []rune(regexp) +func singleSearch(exp []string, text string) []string { + items := strings.Split(text, " ") + var result []string - if len(reArr) != 0 && reArr[0] == '(' && reArr[len(reArr)-1] == ')' { - reArr = reArr[1 : len(reArr)-1] - result := simpleSearch(reArr, text) - for i, results := range result { - if !isAlphaNum(results[len(results)-1]) { - results = results[:len(results)-1] - } - if !isAlphaNum(results[0]) { - results = results[1:] + for _, item := range items { + for _, word := range exp { + if strings.Contains(item, word) { + result = append(result, item) } - fmt.Printf("%d: %s\n", i+1, results) } - } else { - fmt.Println() } + return result } -func isAlphaNum(r byte) bool { - return (r >= 'a' && r <= 'z') || - (r >= 'A' && r <= 'Z') || - (r >= '0' && r <= '9') -} - -func simpleSearch(reArr []rune, text string) []string { - exp := string(reArr) +func simpleSearch(runes []rune, text string) []string { + exp := string(runes) var result []string if !(strings.ContainsRune(exp, '|')) { @@ -59,16 +35,30 @@ func simpleSearch(reArr []rune, text string) []string { return result } -func singleSearch(exp []string, text string) []string { - tArr := strings.Split(text, " ") - var result []string +func brackets(regexp, text string) { + if text == "" || regexp == "" { + return + } + runes := []rune(regexp) - for _, elem := range tArr { - for _, word := range exp { - if strings.Contains(elem, word) { - result = append(result, elem) + if runes[0] == '(' && runes[len(runes)-1] == ')' { + runes = runes[1 : len(runes)-1] + result := simpleSearch(runes, text) + for i, s := range result { + if !unicode.Is(unicode.Hex_Digit, s[len(s)-1]) { + s = s[:len(s)-1] } + if !unicode.Is(unicode.Hex_Digit, s[0]) { + s = s[1:] + } + fmt.Printf("%d: %s\n", i+1, s) } } - return result +} + +func main() { + // brackets("al|b", "ale atg bar sim nao pro par impar") In JS it's used without brackets + if len(os.Args) == 3 { + brackets(os.Args[1], os.Args[2]) + } } diff --git a/tests/go/solutions/grouping/test_grouping.go b/tests/go/solutions/grouping/test_grouping.go index cf028268..8d5d9bee 100644 --- a/tests/go/solutions/grouping/test_grouping.go +++ b/tests/go/solutions/grouping/test_grouping.go @@ -1,52 +1,14 @@ package main -import ( - "github.com/01-edu/z01" -) - -func main() { - type args struct { - first string - second string - } - - arr := []args{ - {first: "(a)", - second: "I'm heavyjumpsuit is on steady, Lighter when I'm lower, higher when I'm heavy"}, - - {first: "(e|n)", second: "I currently have 4 windows opened up… and I don’t know why."}, - {first: "(hi)", second: "He swore he just saw his sushi move."}, - {first: "(s)", second: ""}, - {first: "i", second: "Something in the air"}, - } - - for i := 0; i < 2; i++ { - helper := args{first: validRegExp(2), second: validString(60)} - arr = append(arr, helper) - } - helper := args{first: validRegExp(6), second: validString(60)} - arr = append(arr, helper) - - helper = args{first: z01.RandStr(1, "axyz"), second: z01.RandStr(10, "axyzdassbzzxxxyy cdq ")} - arr = append(arr, helper) - - for _, s := range arr { - z01.ChallengeMain("grouping", s.first, s.second) - } -} - -func validString(len int) string { - s := z01.RandStr(len, "abcdefijklmnopqrstyz ") - return s -} +import "github.com/01-edu/z01" func validRegExp(n int) string { result := "(" for i := 0; i < n; i++ { - result += string(z01.RandStr(1, "abcdefijklmnopqrstyz")) + result += z01.RandStr(1, z01.Lower) if z01.RandInt()%2 == 0 { - result += string(z01.RandStr(1, "abcdefijklmnopqrstyz")) + result += z01.RandStr(1, z01.Lower) } if i != n-1 { result += "|" @@ -56,3 +18,20 @@ func validRegExp(n int) string { result += ")" return result } + +func main() { + args := [][2]string{ + {"(a)", "I'm heavyjumpsuit is on steady, Lighter when I'm lower, higher when I'm heavy"}, + {"(e|n)", "I currently have 4 windows opened up… and I don’t know why."}, + {"(hi)", "He swore he just saw his sushi move."}, + {"(s)", ""}, + {"i", "Something in the air"}, + {validRegExp(2), z01.RandStr(60, z01.Lower+z01.Space)}, + {validRegExp(2), z01.RandStr(60, z01.Lower+z01.Space)}, + {validRegExp(6), z01.RandStr(60, z01.Lower+z01.Space)}, + {z01.RandStr(1, "axyz"), z01.RandStr(10, "axyzdassbzzxxxyy cdq ")}, + } + for _, s := range args { + z01.ChallengeMain("grouping", s[0], s[1]) + } +} diff --git a/tests/go/solutions/halfcontestprog/halfcontestprog_test.go b/tests/go/solutions/halfcontestprog/halfcontestprog_test.go index b4e6cc81..05d0f1d8 100644 --- a/tests/go/solutions/halfcontestprog/halfcontestprog_test.go +++ b/tests/go/solutions/halfcontestprog/halfcontestprog_test.go @@ -3,48 +3,30 @@ package main import ( "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) func main() { type node struct { - h1 int - m1 int - h2 int - m2 int + h1, m1 int + h2, m2 int + } + table := []node{ + {11, 44, 21, 59}, + {1, 12, 1, 14}, + {5, 50, 6, 51}, + {14, 35, 18, 55}, } - table := []node{} - // Initial filling of that array with the values I see in the examples of the subject - - table = append(table, - node{11, 44, 21, 59}, - node{1, 12, 1, 14}, - node{5, 50, 6, 51}, - node{14, 35, 18, 55}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library for i := 0; i < 20; i++ { - value := node{ + table = append(table, node{ h1: z01.RandIntBetween(0, 10), m1: z01.RandIntBetween(0, 59), h2: z01.RandIntBetween(11, 23), m2: z01.RandIntBetween(0, 59), - } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - table = append(table, value) + }) } - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - //The table with 4 specific exercises and 15 randoms is now ready to be "challenged" - //Because the exercise asks for a function we are now using the Challenge function (this function would - // be the ChallengeMainExam function) - for _, arg := range table { z01.Challenge("HalfContestProg", Halfcontest, solutions.Halfcontest, arg.h1, arg.m1, arg.h2, arg.m2) } diff --git a/tests/go/solutions/hello/test_hello.go b/tests/go/solutions/hello/test_hello.go index 34fdd6e3..0a5f6037 100644 --- a/tests/go/solutions/hello/test_hello.go +++ b/tests/go/solutions/hello/test_hello.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("hello") diff --git a/tests/go/solutions/hiddenp/main.go b/tests/go/solutions/hiddenp/main.go index a44b6bfd..e1909c6c 100644 --- a/tests/go/solutions/hiddenp/main.go +++ b/tests/go/solutions/hiddenp/main.go @@ -8,7 +8,6 @@ import ( func main() { if len(os.Args) != 3 { - z01.PrintRune('\n') return } diff --git a/tests/go/solutions/hiddenp/test_hiddenp.go b/tests/go/solutions/hiddenp/test_hiddenp.go index c03c78d2..72afb2a2 100644 --- a/tests/go/solutions/hiddenp/test_hiddenp.go +++ b/tests/go/solutions/hiddenp/test_hiddenp.go @@ -1,46 +1,22 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - arg1 := []string{"fgex.;", "tyf34gdgf;'ektufjhgdgex.;.;rtjynur6"} - arg2 := []string{"abc", "2altrb53c.sse"} - arg3 := []string{"abc", "btarc"} - arg4 := []string{"DD", "DABC"} - arg5 := []string{""} - args := [][]string{arg1, arg2, arg3, arg4, arg5} - - for i := 0; i < 10; i++ { - randomLowerLetter := z01.RandStr(1, z01.RuneRange('a', 'z')) - randomUpperLetter := z01.RandStr(1, z01.RuneRange('A', 'Z')) - extraArg := []string{randomLowerLetter, z01.RandLower()} - extraArg2 := []string{randomUpperLetter, z01.RandUpper()} - - args = append(args, extraArg) - args = append(args, extraArg2) - } - for i := 0; i < 10; i++ { - randomLowerLetter := z01.RandStr(2, z01.RuneRange('a', 'z')) - randomUpperLetter := z01.RandStr(2, z01.RuneRange('A', 'Z')) - extraArg := []string{randomLowerLetter, z01.RandLower()} - extraArg2 := []string{randomUpperLetter, z01.RandUpper()} - - args = append(args, extraArg) - args = append(args, extraArg2) + args := [][2]string{ + {"fgex.;", "tyf34gdgf;'ektufjhgdgex.;.;rtjynur6"}, + {"abc", "2altrb53c.sse"}, + {"abc", "btarc"}, + {"DD", "DABC"}, + {""}, } - for i := 0; i < 10; i++ { - randomLowerLetter := z01.RandStr(1, z01.RuneRange('a', 'z')) - randomUpperLetter := z01.RandStr(1, z01.RuneRange('A', 'Z')) - extraArg := []string{randomLowerLetter, z01.RandLower()} - extraArg2 := []string{randomUpperLetter, z01.RandUpper()} - - args = append(args, extraArg) - args = append(args, extraArg2) + for i := 0; i < 30; i++ { + args = append(args, + [2]string{z01.RandStr(1, z01.Lower), z01.RandLower()}, + [2]string{z01.RandStr(1, z01.Upper), z01.RandUpper()}, + ) } - for _, v := range args { - z01.ChallengeMain("hiddenp", v...) + z01.ChallengeMain("hiddenp", v[0], v[1]) } } diff --git a/tests/go/solutions/index.go b/tests/go/solutions/index.go index d2226be4..66e0158e 100644 --- a/tests/go/solutions/index.go +++ b/tests/go/solutions/index.go @@ -1,10 +1,7 @@ package solutions -import ( - "strings" -) +import "strings" -func Index(s string, toFind string) int { - result := strings.Index(s, toFind) - return result +func Index(s string, substr string) int { + return strings.Index(s, substr) } diff --git a/tests/go/solutions/inter/main.go b/tests/go/solutions/inter/main.go index 202ea74b..3c8c67ba 100644 --- a/tests/go/solutions/inter/main.go +++ b/tests/go/solutions/inter/main.go @@ -6,17 +6,12 @@ import ( "strings" ) -func result(str1 string, str2 string) string { - arraystr1 := []rune(str1) - arraystr2 := []rune(str2) - sizeStr1 := len(arraystr1) - sizeStr2 := len(arraystr2) +func result(s1 string, s2 string) string { var rest []rune - - for i := 0; i < sizeStr1; i++ { - for j := 0; j < sizeStr2; j++ { - if arraystr1[i] == arraystr2[j] && !strings.ContainsRune(string(rest), arraystr1[i]) { - rest = append(rest, arraystr1[i]) + for _, a := range s1 { + for _, b := range s2 { + if a == b && !strings.ContainsRune(string(rest), a) { + rest = append(rest, a) } } } @@ -26,7 +21,5 @@ func result(str1 string, str2 string) string { func main() { if len(os.Args) == 3 { fmt.Println(result(os.Args[1], os.Args[2])) - } else { - fmt.Println() } } diff --git a/tests/go/solutions/inter/test_inter.go b/tests/go/solutions/inter/test_inter.go index d60c4e7f..166ad460 100644 --- a/tests/go/solutions/inter/test_inter.go +++ b/tests/go/solutions/inter/test_inter.go @@ -7,24 +7,25 @@ import ( ) func main() { - table := append(z01.MultRandWords(), + args := append(z01.MultRandWords(), "padinton paqefwtdjetyiytjneytjoeyjnejeyj", "ddf6vewg64f twthgdwthdwfteewhrtag6h4ffdhsd", + "abcdefghij efghijlmnopq", + "123456 456789", + "1 1", + "1 2", ) - table = append(table, "abcdefghij efghijlmnopq") - table = append(table, "123456 456789") - table = append(table, "1 1") - table = append(table, "1 2") for i := 0; i < 5; i++ { - str1 := z01.RandAlnum() - str2 := strings.Join([]string{z01.RandAlnum(), str1, z01.RandAlnum()}, "") - - table = append(table, strings.Join([]string{str1, str2}, " ")) - table = append(table, strings.Join([]string{z01.RandAlnum(), z01.RandAlnum()}, " ")) + s1 := z01.RandAlnum() + s2 := z01.RandAlnum() + s1 + z01.RandAlnum() + args = append(args, + s1+" "+s2, + z01.RandAlnum()+" "+z01.RandAlnum(), + ) } - for _, s := range table { + for _, s := range args { z01.ChallengeMain("inter", strings.Fields(s)...) } } diff --git a/tests/go/solutions/interestingnumber.go b/tests/go/solutions/interestingnumber.go index ec42583c..3da9d911 100644 --- a/tests/go/solutions/interestingnumber.go +++ b/tests/go/solutions/interestingnumber.go @@ -6,18 +6,14 @@ func isInteresting(n int) bool { s += n % 10 n /= 10 } - if s%7 == 0 { - return true - } - return false + return s%7 == 0 } func InterestingNumber(n int) int { - for n > 0 { - if isInteresting(n) == true { + for { + if isInteresting(n) { return n } n++ } - return -1 } diff --git a/tests/go/solutions/interestingnumber/interestingnumber_test.go b/tests/go/solutions/interestingnumber/interestingnumber_test.go index 065234ac..4e03df4d 100644 --- a/tests/go/solutions/interestingnumber/interestingnumber_test.go +++ b/tests/go/solutions/interestingnumber/interestingnumber_test.go @@ -3,38 +3,19 @@ package main import ( "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) func main() { - type node struct { - n int - } - - table := []node{} - // Initial filling of that array with the values I see in the examples of the subject - - table = append(table, - node{20}, - node{1}, - node{9}, - node{2}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library - - for i := 0; i < 15; i++ { - value := node{ - n: z01.RandIntBetween(1, 1500), - } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - table = append(table, value) + table := []int{ + 20, + 1, + 9, + 2, } + table = append(table, z01.MultRandIntBetween(1, 1500)...) for _, arg := range table { - z01.Challenge("InterestingNumber", InterestingNumber, solutions.InterestingNumber, arg.n) + z01.Challenge("InterestingNumber", InterestingNumber, solutions.InterestingNumber, arg) } } diff --git a/tests/go/solutions/interestingnumber/main.go b/tests/go/solutions/interestingnumber/main.go index 203a56bf..c30335bb 100644 --- a/tests/go/solutions/interestingnumber/main.go +++ b/tests/go/solutions/interestingnumber/main.go @@ -6,20 +6,16 @@ func isInteresting(n int) bool { s += n % 10 n /= 10 } - if s%7 == 0 { - return true - } - return false + return s%7 == 0 } func InterestingNumber(n int) int { - for n > 0 { - if isInteresting(n) == true { + for { + if isInteresting(n) { return n } n++ } - return -1 } func main() { diff --git a/tests/go/solutions/inverttree/inverttree_test.go b/tests/go/solutions/inverttree/inverttree_test.go index c4305620..dd8364d0 100644 --- a/tests/go/solutions/inverttree/inverttree_test.go +++ b/tests/go/solutions/inverttree/inverttree_test.go @@ -1,14 +1,13 @@ package main import ( - "io" - // "os" "fmt" + "io" "math/rand" "strconv" - "testing" - // "github.com/01-edu/z01" + "github.com/01-edu/z01" + solutions "../../solutions" ) @@ -18,7 +17,8 @@ type solNode = solutions.TNode func solInsert(N *solNode, newVal int) { if N == nil { return - } else if newVal <= N.Val { + } + if newVal <= N.Val { if N.Left == nil { N.Left = &solNode{Val: newVal, Left: nil, Right: nil} } else { @@ -36,7 +36,8 @@ func solInsert(N *solNode, newVal int) { func stuInsert(N *stuNode, newVal int) { if N == nil { return - } else if newVal <= N.Val { + } + if newVal <= N.Val { if N.Left == nil { N.Left = &stuNode{Val: newVal, Left: nil, Right: nil} } else { @@ -51,21 +52,17 @@ func stuInsert(N *stuNode, newVal int) { } } -func IsIdentical(root1 *solNode, root2 *stuNode) int { +func IsIdentical(root1 *solNode, root2 *stuNode) bool { if root1 == nil && root2 == nil { - return 1 - } else if root1 == nil && root2 != nil { - return 0 - } else if root2 == nil && root1 != nil { - return 0 - } else { - if root1.Val == root2.Val && IsIdentical(root1.Left, root2.Left) == 1 && IsIdentical(root1.Right, root2.Right) == 1 { - return 1 - } else { - return 0 - } + return true + } + if root1 == nil && root2 != nil { + return false + } + if root2 == nil && root1 != nil { + return false } - return 1 + return root1.Val == root2.Val && IsIdentical(root1.Left, root2.Left) && IsIdentical(root1.Right, root2.Right) } func stuPrint(w io.Writer, node *stuNode, ns int, ch rune) { @@ -128,7 +125,7 @@ func returnSolTree(root *solNode) string { return ans } -func TestInvertTree(t *testing.T) { +func main() { root, val1, val2, val3, val4 := 0, 0, 0, 0, 0 root = rand.Intn(30) @@ -156,12 +153,11 @@ func TestInvertTree(t *testing.T) { InvertTree(TestTree) // stuPrint(os.Stdout, TestTree, 0, 'M') - ret := IsIdentical(tree, TestTree) - if ret != 1 { + if !IsIdentical(tree, TestTree) { tree1 := returnSolTree(temp) tree2 := returnStuTree(tmp) - t.Fatalf("\n\"%v\" instead of \"%v\"\n\n", tree1, tree2) - // t.Fatalf("\nError\n\n") + z01.Fatalf("\n\"%v\" instead of \"%v\"\n\n", tree1, tree2) + // z01.Fatalf("\nError\n\n") } } } diff --git a/tests/go/solutions/isalpha.go b/tests/go/solutions/isalpha.go index 18a6826c..d82180e5 100644 --- a/tests/go/solutions/isalpha.go +++ b/tests/go/solutions/isalpha.go @@ -1,8 +1,10 @@ package solutions +import "unicode" + func IsAlpha(s string) bool { for _, r := range s { - if !((r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9')) { + if !unicode.Is(unicode.Hex_Digit, r) { return false } } diff --git a/tests/go/solutions/isanagram/isanagram_test.go b/tests/go/solutions/isanagram/isanagram_test.go index a3991e18..35ab3824 100644 --- a/tests/go/solutions/isanagram/isanagram_test.go +++ b/tests/go/solutions/isanagram/isanagram_test.go @@ -3,46 +3,36 @@ package main import ( "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) func main() { - type node struct { - s string - t string + table := [][2]string{ + {"listen", "silent"}, + {"alem", "school"}, + {"neat", "a net"}, + {"anna madrigal", "a man and a girl"}, + {"abcc", "abcd"}, + {"aaaac", "caaaa"}, + {"", ""}, + {" ", ""}, + {"lyam", "meow"}, + {"golang", "lang go"}, + {"verylongword", "v e r y l o n g w o r d"}, + {"chess", "ches"}, + {"anagram", "nnagram"}, + {"chess", "board"}, + {"mmm", "m"}, + {"pulp", "fiction"}, } - - table := []node{} - - table = append(table, - node{"listen", "silent"}, - node{"alem", "school"}, - node{"neat", "a net"}, - node{"anna madrigal", "a man and a girl"}, - node{"abcc", "abcd"}, - node{"aaaac", "caaaa"}, - node{"", ""}, - node{" ", ""}, - node{"lyam", "meow"}, - node{"golang", "lang go"}, - node{"verylongword", "v e r y l o n g w o r d"}, - node{"chess", "ches"}, - node{"anagram", "nnagram"}, - node{"chess", "board"}, - node{"mmm", "m"}, - node{"pulp", "fiction"}, - ) - for i := 0; i < 15; i++ { - value := node{ - s: z01.RandStr(z01.RandIntBetween(15, 20), "qwertyuiopasdfghjklzxcvbnm "), - t: z01.RandStr(z01.RandIntBetween(15, 20), "qwertyuiopasdfghjklzxcvbnm "), - } - - table = append(table, value) + table = append(table, [2]string{ + z01.RandStr(z01.RandIntBetween(15, 20), "qwertyuiopasdfghjklzxcvbnm "), + z01.RandStr(z01.RandIntBetween(15, 20), "qwertyuiopasdfghjklzxcvbnm "), + }) } for _, arg := range table { - z01.Challenge("IsAnagram", IsAnagram, solutions.IsAnagram, arg.s, arg.t) + z01.Challenge("IsAnagram", IsAnagram, solutions.IsAnagram, arg[0], arg[1]) } } diff --git a/tests/go/solutions/islower.go b/tests/go/solutions/islower.go index 8f665fa1..7389a976 100644 --- a/tests/go/solutions/islower.go +++ b/tests/go/solutions/islower.go @@ -1,8 +1,10 @@ package solutions +import "unicode" + func IsLower(s string) bool { for _, r := range s { - if !(r >= 'a' && r <= 'z') { + if !unicode.IsLower(r) { return false } } diff --git a/tests/go/solutions/isnegative.go b/tests/go/solutions/isnegative.go index f650b3e9..87676ed9 100644 --- a/tests/go/solutions/isnegative.go +++ b/tests/go/solutions/isnegative.go @@ -1,8 +1,6 @@ package solutions -import ( - "fmt" -) +import "fmt" func IsNegative(n int) { if n < 0 { diff --git a/tests/go/solutions/isnumeric.go b/tests/go/solutions/isnumeric.go index ee3fc083..5161adaa 100644 --- a/tests/go/solutions/isnumeric.go +++ b/tests/go/solutions/isnumeric.go @@ -1,8 +1,10 @@ package solutions +import "unicode" + func IsNumeric(s string) bool { for _, r := range s { - if !(r >= '0' && r <= '9') { + if !unicode.IsDigit(r) { return false } } diff --git a/tests/go/solutions/ispowerof2/main.go b/tests/go/solutions/ispowerof2/main.go index bf47d002..d844f62a 100644 --- a/tests/go/solutions/ispowerof2/main.go +++ b/tests/go/solutions/ispowerof2/main.go @@ -6,16 +6,14 @@ import ( "strconv" ) -func main() { - if len(os.Args) > 2 || len(os.Args) < 2 { - fmt.Println() - return - } - nbr, _ := strconv.Atoi(os.Args[1]) - fmt.Println(isPowerOf2(nbr)) -} - -//& computes the logical bitwise AND of its operands. +// computes the logical bitwise AND of its operands. func isPowerOf2(n int) bool { return n != 0 && ((n & (n - 1)) == 0) } + +func main() { + if len(os.Args) == 2 { + nbr, _ := strconv.Atoi(os.Args[1]) + fmt.Println(isPowerOf2(nbr)) + } +} diff --git a/tests/go/solutions/ispowerof2/test_ispowerof2.go b/tests/go/solutions/ispowerof2/test_ispowerof2.go index 5598538c..3b19591a 100644 --- a/tests/go/solutions/ispowerof2/test_ispowerof2.go +++ b/tests/go/solutions/ispowerof2/test_ispowerof2.go @@ -2,28 +2,26 @@ package main import ( "strconv" - "strings" "github.com/01-edu/z01" ) func main() { - var args []string - for i := 1; i < 5; i++ { - args = append(args, strconv.Itoa(i)) + args := [][]string{ + {"1"}, + {"2"}, + {"3"}, + {"4"}, + {"1024"}, + {"4096"}, + {"8388608"}, + {"1", "2"}, + {}, } - for i := 0; i < 12; i++ { - args = append(args, strconv.Itoa(z01.RandIntBetween(1, 2048))) + args = append(args, []string{strconv.Itoa(z01.RandIntBetween(1, 2048))}) } - - args = append(args, "1024") - args = append(args, "") - args = append(args, "4096") - args = append(args, "8388608") - for _, v := range args { - z01.ChallengeMain("ispowerof2", strings.Fields(v)...) + z01.ChallengeMain("ispowerof2", v...) } - z01.ChallengeMain("ispowerof2", "1", "2") } diff --git a/tests/go/solutions/isprime.go b/tests/go/solutions/isprime.go index 353cd69f..67f627a4 100644 --- a/tests/go/solutions/isprime.go +++ b/tests/go/solutions/isprime.go @@ -1,8 +1,6 @@ package solutions -import ( - "math" -) +import "math" func IsPrime(value int) bool { if value < 2 { diff --git a/tests/go/solutions/isprintable.go b/tests/go/solutions/isprintable.go index 927bdf6c..350924df 100644 --- a/tests/go/solutions/isprintable.go +++ b/tests/go/solutions/isprintable.go @@ -1,8 +1,10 @@ package solutions +import "unicode" + func IsPrintable(s string) bool { for _, r := range s { - if !(r >= 32 && r <= 127) { + if !unicode.IsPrint(r) { return false } } diff --git a/tests/go/solutions/issorted.go b/tests/go/solutions/issorted.go index c1a1742e..94d8d365 100644 --- a/tests/go/solutions/issorted.go +++ b/tests/go/solutions/issorted.go @@ -1,27 +1,5 @@ package solutions -func IsSortedBy1(a, b int) int { - if a-b < 0 { - return -1 - } else if a-b > 0 { - return 1 - } - return 0 -} - -func IsSortedBy10(a, b int) int { - if a-b < 0 { - return -10 - } else if a-b > 0 { - return 10 - } - return 0 -} - -func IsSortedByDiff(a, b int) int { - return a - b -} - func IsSorted(f func(int, int) int, arr []int) bool { ascendingOrdered := true descendingOrdered := true diff --git a/tests/go/solutions/iterativepower.go b/tests/go/solutions/iterativepower.go index 1dd75609..56ee0821 100644 --- a/tests/go/solutions/iterativepower.go +++ b/tests/go/solutions/iterativepower.go @@ -1,8 +1,6 @@ package solutions -import ( - "math" -) +import "math" func IterativePower(nb int, power int) int { if power < 0 { diff --git a/tests/go/solutions/itoa.go b/tests/go/solutions/itoa.go index 9589adc5..32904a81 100644 --- a/tests/go/solutions/itoa.go +++ b/tests/go/solutions/itoa.go @@ -1,9 +1,7 @@ package solutions -import ( - "strconv" -) +import "strconv" -func Itoa(v int) string { - return strconv.Itoa(v) +func Itoa(i int) string { + return strconv.Itoa(i) } diff --git a/tests/go/solutions/itoaprog/main.go b/tests/go/solutions/itoaprog/main.go index 81e0f3b1..f55bf51b 100644 --- a/tests/go/solutions/itoaprog/main.go +++ b/tests/go/solutions/itoaprog/main.go @@ -1,8 +1,6 @@ package main -import ( - "strconv" -) +import "strconv" func Itoa(v int) string { return strconv.Itoa(v) diff --git a/tests/go/solutions/join.go b/tests/go/solutions/join.go index 5b5bd63b..7a16a1aa 100644 --- a/tests/go/solutions/join.go +++ b/tests/go/solutions/join.go @@ -1,14 +1,7 @@ package solutions -//Join the elements of the slice using the sep as glue between each element -func Join(arstr []string, sep string) string { - res := "" - n := len(arstr) - for i, a := range arstr { - res += a - if i < n-1 { - res += sep - } - } - return res +import "strings" + +func Join(elems []string, sep string) string { + return strings.Join(elems, sep) } diff --git a/tests/go/solutions/lastword/main.go b/tests/go/solutions/lastword/main.go index eba6e291..711b1340 100644 --- a/tests/go/solutions/lastword/main.go +++ b/tests/go/solutions/lastword/main.go @@ -8,13 +8,9 @@ import ( func main() { if len(os.Args) == 2 { - words := strings.Split(os.Args[1], " ") - for i := len(words) - 1; i >= 0; i-- { - if words[i] != "" { - fmt.Println(words[i]) - return - } + words := strings.Fields(os.Args[1]) + if len(words) > 0 { + fmt.Println(words[len(words)-1]) } } - fmt.Println() } diff --git a/tests/go/solutions/lastword/test_lastword.go b/tests/go/solutions/lastword/test_lastword.go index bf24fd25..f77e51fd 100644 --- a/tests/go/solutions/lastword/test_lastword.go +++ b/tests/go/solutions/lastword/test_lastword.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { args := []string{ @@ -12,9 +10,7 @@ func main() { " lorem,ipsum ", } - for i := 0; i < 5; i++ { - args = append(args, z01.RandWords()) - } + args = append(args, z01.MultRandWords()) for _, v := range args { z01.ChallengeMain("lastword", v) diff --git a/tests/go/solutions/lcm.go b/tests/go/solutions/lcm.go index bad0b0a1..0e19248c 100644 --- a/tests/go/solutions/lcm.go +++ b/tests/go/solutions/lcm.go @@ -1,12 +1,5 @@ package solutions -// This solution is the comparing file of the staff -// Because the solution is a function, -// -// 1) here the package is solutions -// 2) it does not need an empty func main(){} -// 3) its location is 1 level below the folder of the nauuo_test.go file - func gcd(first, second int) int { if second == 0 { return first diff --git a/tests/go/solutions/lcm/lcm_test.go b/tests/go/solutions/lcm/lcm_test.go index 7d4ebaa6..2f58c989 100644 --- a/tests/go/solutions/lcm/lcm_test.go +++ b/tests/go/solutions/lcm/lcm_test.go @@ -3,37 +3,26 @@ package main import ( "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) func main() { - type node struct { - first int - second int + table := [][2]int{ + {50, 43}, + {13, 13}, + {10, 9}, + {0, 9}, + {1, 1}, } - table := []node{} - - table = append(table, - node{50, 43}, - node{13, 13}, - node{10, 9}, - node{0, 9}, - node{1, 1}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library - for i := 0; i < 15; i++ { - value := node{ - first: z01.RandIntBetween(0, 1000), - second: z01.RandIntBetween(0, 1000), - } - table = append(table, value) + table = append(table, [2]int{ + z01.RandIntBetween(0, 1000), + z01.RandIntBetween(0, 1000), + }) } for _, arg := range table { - z01.Challenge("Lcm", Lcm, solutions.Lcm, arg.first, arg.second) + z01.Challenge("Lcm", Lcm, solutions.Lcm, arg[0], arg[1]) } } diff --git a/tests/go/solutions/lcm/main.go b/tests/go/solutions/lcm/main.go index 8ffae9b1..fcd43af6 100644 --- a/tests/go/solutions/lcm/main.go +++ b/tests/go/solutions/lcm/main.go @@ -2,12 +2,6 @@ package main import "fmt" -//This solution is the placeholder of the student solution -// for an exercise in the exam asking for a Function -//Remember the disclaimer!!!! -//1) here the package is main -//2) It does need an empty func main(){} - func gcd(first, second int) int { if second == 0 { return first @@ -18,6 +12,7 @@ func gcd(first, second int) int { func Lcm(first, second int) int { return first / gcd(first, second) * second } + func main() { fmt.Println(Lcm(3, 0)) fmt.Println(Lcm(4, 0)) diff --git a/tests/go/solutions/listat.go b/tests/go/solutions/listat.go index fde3386f..0070a413 100644 --- a/tests/go/solutions/listat.go +++ b/tests/go/solutions/listat.go @@ -1,6 +1,6 @@ package solutions -//returs the node in a given position +// returs the node in a given position func ListAt(l *NodeL, nbr int) *NodeL { index := 0 count := 0 diff --git a/tests/go/solutions/listclear.go b/tests/go/solutions/listclear.go index d1cb250e..fc799799 100644 --- a/tests/go/solutions/listclear.go +++ b/tests/go/solutions/listclear.go @@ -1,6 +1,5 @@ package solutions -//cleans the list func ListClear(l *List) { temp := l.Head next := l.Head diff --git a/tests/go/solutions/listforeach.go b/tests/go/solutions/listforeach.go index 785d6b4c..dd69bc78 100644 --- a/tests/go/solutions/listforeach.go +++ b/tests/go/solutions/listforeach.go @@ -1,6 +1,6 @@ package solutions -//applies a function in argument to each element of the linked list +// applies a function in argument to each element of the linked list func ListForEach(l *List, f func(*NodeL)) { it := l.Head for it != nil { diff --git a/tests/go/solutions/listlast.go b/tests/go/solutions/listlast.go index f0fde732..ea12ae04 100644 --- a/tests/go/solutions/listlast.go +++ b/tests/go/solutions/listlast.go @@ -1,6 +1,6 @@ package solutions -//gives the last element of the list +// gives the last element of the list func ListLast(l *List) interface{} { if l.Head == nil { return nil diff --git a/tests/go/solutions/listmerge.go b/tests/go/solutions/listmerge.go index 5b5df8ab..f85862d1 100644 --- a/tests/go/solutions/listmerge.go +++ b/tests/go/solutions/listmerge.go @@ -1,6 +1,6 @@ package solutions -//merges the 2 lists in one(in the end of the first list) +// merges the 2 lists in one (in the end of the first list) func ListMerge(l1 *List, l2 *List) { if l1.Head == nil { l1.Head, l1.Tail = l2.Head, l2.Tail diff --git a/tests/go/solutions/listpushfront.go b/tests/go/solutions/listpushfront.go index 2b815d20..6ae0c5c6 100644 --- a/tests/go/solutions/listpushfront.go +++ b/tests/go/solutions/listpushfront.go @@ -1,6 +1,6 @@ package solutions -//inserts node on the first position of the list +// inserts node on the first position of the list func ListPushFront(l *List, data interface{}) { n := &NodeL{Data: data} diff --git a/tests/go/solutions/listremoveif.go b/tests/go/solutions/listremoveif.go index 0087ab7c..cd464d64 100644 --- a/tests/go/solutions/listremoveif.go +++ b/tests/go/solutions/listremoveif.go @@ -1,6 +1,6 @@ package solutions -//removes all elements that are equal to the data_ref +// removes all elements that are equal to the data_ref func ListRemoveIf(l *List, data_ref interface{}) { temp := l.Head prev := l.Head diff --git a/tests/go/solutions/listremoveifprog/listremoveifprog_test.go b/tests/go/solutions/listremoveifprog/listremoveifprog_test.go index 5368186d..c0f23625 100644 --- a/tests/go/solutions/listremoveifprog/listremoveifprog_test.go +++ b/tests/go/solutions/listremoveifprog/listremoveifprog_test.go @@ -2,10 +2,10 @@ package main import ( "strconv" - "testing" - solution "../../solutions" "github.com/01-edu/z01" + + solution "../../solutions" ) type Node10 = NodeL @@ -29,22 +29,22 @@ func listToStringStu12(l *ListS10) string { return res } -func listPushBackTest10(l *ListS10, l1 *List10, data interface{}) { +func listPushBackTest10(l1 *ListS10, l2 *List10, data interface{}) { n := &Node10{Data: data} n1 := &NodeS10{Data: data} - if l.Head == nil { - l.Head = n + if l1.Head == nil { + l1.Head = n } else { - iterator := l.Head + iterator := l1.Head for iterator.Next != nil { iterator = iterator.Next } iterator.Next = n } - if l1.Head == nil { - l1.Head = n1 + if l2.Head == nil { + l2.Head = n1 } else { - iterator1 := l1.Head + iterator1 := l2.Head for iterator1.Next != nil { iterator1 = iterator1.Next } @@ -52,28 +52,25 @@ func listPushBackTest10(l *ListS10, l1 *List10, data interface{}) { } } -func comparFuncList10(l *List10, l1 *ListS10, t *testing.T, data interface{}) { - for l.Head != nil || l1.Head != nil { - if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) { - t.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n", - data, listToStringStu12(l1), solution.ListToString(l.Head), l1.Head, l.Head) - return - } else if l.Head.Data != l1.Head.Data { - t.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n", - data, listToStringStu12(l1), solution.ListToString(l.Head), l1.Head.Data, l.Head.Data) - return +func comparFuncList10(l1 *List10, l2 *ListS10, data interface{}) { + for l1.Head != nil || l2.Head != nil { + if (l1.Head == nil && l2.Head != nil) || (l1.Head != nil && l2.Head == nil) { + z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n", + data, listToStringStu12(l2), solution.ListToString(l1.Head), l2.Head, l1.Head) + } + if l1.Head.Data != l2.Head.Data { + z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n", + data, listToStringStu12(l2), solution.ListToString(l1.Head), l2.Head.Data, l1.Head.Data) } - l.Head = l.Head.Next l1.Head = l1.Head.Next + l2.Head = l2.Head.Next } } -//exercise 13 -//removes all the elements that are equal to a value -func TestListRemoveIfProg(t *testing.T) { - link := &List10{} +// removes all the elements that are equal to a value +func main() { + link1 := &List10{} link2 := &ListS10{} - var index int table := []solution.NodeTest{} table = solution.ElementsToTest(table) @@ -86,23 +83,23 @@ func TestListRemoveIfProg(t *testing.T) { for _, arg := range table { for i := 0; i < len(arg.Data); i++ { - listPushBackTest10(link2, link, arg.Data[i]) + listPushBackTest10(link2, link1, arg.Data[i]) } aux := len(arg.Data) - 1 - index = z01.RandIntBetween(0, aux) - if link.Head != nil && link2.Head != nil { + index := z01.RandIntBetween(0, aux) + if link1.Head != nil && link2.Head != nil { cho := arg.Data[index] ListRemoveIf(link2, cho) - solution.ListRemoveIf(link, cho) - comparFuncList10(link, link2, t, cho) + solution.ListRemoveIf(link1, cho) + comparFuncList10(link1, link2, cho) } else { ListRemoveIf(link2, 1) - solution.ListRemoveIf(link, 1) - comparFuncList10(link, link2, t, 1) + solution.ListRemoveIf(link1, 1) + comparFuncList10(link1, link2, 1) } - link = &List10{} + link1 = &List10{} link2 = &ListS10{} } } diff --git a/tests/go/solutions/listremoveifprog/main.go b/tests/go/solutions/listremoveifprog/main.go index fe613ae2..c26cb837 100644 --- a/tests/go/solutions/listremoveifprog/main.go +++ b/tests/go/solutions/listremoveifprog/main.go @@ -10,7 +10,7 @@ type List struct { Tail *NodeL } -//removes all elements that are equal to the data_ref +// removes all elements that are equal to the data_ref func ListRemoveIf(l *List, data_ref interface{}) { temp := l.Head prev := l.Head diff --git a/tests/go/solutions/listreverse.go b/tests/go/solutions/listreverse.go index 919ab4d8..aee535c7 100644 --- a/tests/go/solutions/listreverse.go +++ b/tests/go/solutions/listreverse.go @@ -1,6 +1,5 @@ package solutions -//reverses the list func ListReverse(l *List) { current := l.Head prev := l.Head diff --git a/tests/go/solutions/listsize.go b/tests/go/solutions/listsize.go index 4615a9de..7b1f497f 100644 --- a/tests/go/solutions/listsize.go +++ b/tests/go/solutions/listsize.go @@ -1,6 +1,5 @@ package solutions -//gives the length of the List func ListSize(l *List) int { count := 0 iterator := l.Head diff --git a/tests/go/solutions/listsizeprog/listsizeprog_test.go b/tests/go/solutions/listsizeprog/listsizeprog_test.go index 24f5a6b8..aaee2f61 100644 --- a/tests/go/solutions/listsizeprog/listsizeprog_test.go +++ b/tests/go/solutions/listsizeprog/listsizeprog_test.go @@ -1,9 +1,8 @@ package main import ( - "testing" - solution "../../solutions" + "github.com/01-edu/z01" ) type Node2 = NodeL @@ -35,8 +34,7 @@ func listPushBackTest2(l *ListS2, l1 *List2, data interface{}) { } } -//exercise 4 -func TestListSizeProg(t *testing.T) { +func main() { link := &List2{} link2 := &ListS2{} table := []solution.NodeTest{} @@ -53,7 +51,7 @@ func TestListSizeProg(t *testing.T) { aux := solution.ListSize(link) aux2 := ListSize(link2) if aux != aux2 { - t.Fatalf("ListSize(%v) == %d instead of %d\n", solution.ListToString(link.Head), aux2, aux) + z01.Fatalf("ListSize(%v) == %d instead of %d\n", solution.ListToString(link.Head), aux2, aux) } link = &List2{} link2 = &ListS2{} diff --git a/tests/go/solutions/listsizeprog/main.go b/tests/go/solutions/listsizeprog/main.go index e392f7f1..1ee72192 100644 --- a/tests/go/solutions/listsizeprog/main.go +++ b/tests/go/solutions/listsizeprog/main.go @@ -10,7 +10,6 @@ type List struct { Tail *NodeL } -//gives the length of the List func ListSize(l *List) int { count := 0 iterator := l.Head diff --git a/tests/go/solutions/listsort.go b/tests/go/solutions/listsort.go index 672b8767..abd893b2 100644 --- a/tests/go/solutions/listsort.go +++ b/tests/go/solutions/listsort.go @@ -1,16 +1,16 @@ package solutions func ListSort(l *NodeI) *NodeI { - Head := l - if Head == nil { + head := l + if head == nil { return nil } - Head.Next = ListSort(Head.Next) + head.Next = ListSort(head.Next) - if Head.Next != nil && Head.Data > Head.Next.Data { - Head = move(Head) + if head.Next != nil && head.Data > head.Next.Data { + head = move(head) } - return Head + return head } func move(l *NodeI) *NodeI { diff --git a/tests/go/solutions/max.go b/tests/go/solutions/max.go index ec089717..11c42ad3 100644 --- a/tests/go/solutions/max.go +++ b/tests/go/solutions/max.go @@ -1,10 +1,11 @@ package solutions -import ( - "sort" -) +import "sort" -func Max(arr []int) int { - sort.Sort(sort.IntSlice(arr)) - return arr[len(arr)-1] +func Max(a []int) int { + if len(a) == 0 { + return 0 + } + sort.Ints(a) + return a[len(a)-1] } diff --git a/tests/go/solutions/maxprog/main.go b/tests/go/solutions/maxprog/main.go index 9d11ae59..2b5e9b34 100644 --- a/tests/go/solutions/maxprog/main.go +++ b/tests/go/solutions/maxprog/main.go @@ -1,12 +1,13 @@ package main -import ( - "sort" -) +import "sort" -func Max(arr []int) int { - sort.Sort(sort.IntSlice(arr)) - return arr[len(arr)-1] +func Max(a []int) int { + if len(a) == 0 { + return 0 + } + sort.Ints(a) + return a[len(a)-1] } func main() { diff --git a/tests/go/solutions/merge.go b/tests/go/solutions/merge.go index 8fa487ca..89681fe1 100644 --- a/tests/go/solutions/merge.go +++ b/tests/go/solutions/merge.go @@ -13,7 +13,7 @@ func MergeTrees(t1 *TreeNodeM, t2 *TreeNodeM) *TreeNodeM { if t2 == nil { return t1 } - t1.Val = t1.Val + t2.Val + 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/solutions/merge/main.go b/tests/go/solutions/merge/main.go index 5afe35f1..64c1ca41 100644 --- a/tests/go/solutions/merge/main.go +++ b/tests/go/solutions/merge/main.go @@ -13,7 +13,7 @@ func MergeTrees(t1 *TreeNodeM, t2 *TreeNodeM) *TreeNodeM { if t2 == nil { return t1 } - t1.Val = t1.Val + t2.Val + 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/solutions/merge/merge_test.go b/tests/go/solutions/merge/merge_test.go index 20457043..91c9025e 100644 --- a/tests/go/solutions/merge/merge_test.go +++ b/tests/go/solutions/merge/merge_test.go @@ -3,10 +3,10 @@ package main import ( "math/rand" "strconv" - "testing" - solutions "../../solutions" "github.com/01-edu/z01" + + solutions "../../solutions" ) type stuTreeNode = TreeNodeM @@ -141,17 +141,17 @@ func returnStuTree(root *stuTreeNode) string { return ans } -func compareTrees(t *testing.T, stuResult *stuTreeNode, solResult, solTree1, solTree2 *solTreeNode) { +func compareTrees(stuResult *stuTreeNode, solResult, solTree1, solTree2 *solTreeNode) { if !compare(stuResult, solResult) { tree1 := returnSolTree(solTree1) tree2 := returnSolTree(solTree2) stuTree := returnStuTree(stuResult) solTree := returnSolTree(solResult) - t.Fatalf("\nMergeTrees(\"%v\", \"%v\") == \"%v\" instead of \"%v\"\n\n", tree1, tree2, stuTree, solTree) + z01.Fatalf("\nMergeTrees(\"%v\", \"%v\") == \"%v\" instead of \"%v\"\n\n", tree1, tree2, stuTree, solTree) } } -func TestMerge(t *testing.T) { +func main() { type node struct { n int k int @@ -168,6 +168,6 @@ func TestMerge(t *testing.T) { stuResult := MergeTrees(stuTree1, stuTree2) solResult := solutions.MergeTrees(solTree1, solTree2) - compareTrees(t, stuResult, solResult, cop1, cop2) + compareTrees(stuResult, solResult, cop1, cop2) } } diff --git a/tests/go/solutions/nauuo.go b/tests/go/solutions/nauuo.go index 44859576..0d94e21a 100644 --- a/tests/go/solutions/nauuo.go +++ b/tests/go/solutions/nauuo.go @@ -1,12 +1,5 @@ package solutions -//This solution is the comparing file of the staff -// Because the solution is a function, -// -//1) here the package is solutions -//2) it does not need an empty func main(){} -//3) its location is 1 level below the folder of the nauuo_test.go file - func Nauuo(plus, minus, rand int) string { if rand == 0 { if plus > minus { @@ -25,10 +18,10 @@ func Nauuo(plus, minus, rand int) string { if plus+rand < minus { return "-" } - if (plus+rand >= minus) && (plus-rand <= minus) { + if plus+rand >= minus && plus-rand <= minus { return "?" } - if (minus+rand >= plus) && (minus-rand <= plus) { + if minus+rand >= plus && minus-rand <= plus { return "?" } return "?" diff --git a/tests/go/solutions/nauuo/main.go b/tests/go/solutions/nauuo/main.go index 99253b50..38c3d7e5 100644 --- a/tests/go/solutions/nauuo/main.go +++ b/tests/go/solutions/nauuo/main.go @@ -1,11 +1,5 @@ package main -//This solution is the placeholder of the student solution -// for an exercise in the exam asking for a Function -//Remember the disclaimer!!!! -//1) here the package is main -//2) It does need an empty func main(){} - func Nauuo(plus, minus, rand int) string { if rand == 0 { if plus > minus { diff --git a/tests/go/solutions/nauuo/nauuo_test.go b/tests/go/solutions/nauuo/nauuo_test.go index 651837ec..81ad9ed1 100644 --- a/tests/go/solutions/nauuo/nauuo_test.go +++ b/tests/go/solutions/nauuo/nauuo_test.go @@ -3,79 +3,30 @@ package main import ( "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) func main() { - // Declaration of the node that is going to take the group of arguments that are going to - // inputed during each iteration of a Challenge between the student and the staff solution. - // (note: a node is not always necessary but in this case it makes the writing of the test easier) - type node struct { plus int minus int rand int } - - // Declaration of an empty array of type node{} - // note that in this case this is the easiest type of table to declare - // but a table can be of any other relevant type, (for example []string{}, []int{} if it - // were a single string tested or a single int) - - table := []node{} - // Initial filling of that array with the values I see in the examples of the subject - - table = append(table, - node{50, 43, 20}, - node{13, 13, 0}, - node{10, 9, 0}, - node{5, 9, 2}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library + table := []node{ + {50, 43, 20}, + {13, 13, 0}, + {10, 9, 0}, + {5, 9, 2}, + } for i := 0; i < 15; i++ { - value := node{ + table = append(table, node{ plus: z01.RandIntBetween(0, 10), minus: z01.RandIntBetween(0, 10), rand: z01.RandIntBetween(0, 10), - //this z01.RandIntBetween function allows the randomization of - //the int for each value in a desired range. - //Note that they are many others of those functions for other types of data - //Do not hesitate to have a look at all of them https://github.com/01-edu/z01 - } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - table = append(table, value) + }) } - - //The table with 4 specific exercises and 15 randoms is now ready to be "challenged" - //Because the exercise asks for a function we are now using the Challenge function (this function would - // be the ChallengeMainExam function) - for _, arg := range table { z01.Challenge("Nauuo", Nauuo, solutions.Nauuo, arg.plus, arg.minus, arg.rand) } - - // the z01.Challenge function is here applied to each argument of the table. It musts contains: - // 1) first, the t argument from the T structure imported from the package "testing" - // - // 2) second, the function from the student, in this case Nauuo - //(this disapears in the ChallengeMainExam function) - // 3) third, the function from the staff, in this case solutions.Nauuo - //(this disapears as well in the ChallengeMainExam function) - // 4) all the arguments to be tested, in this case it is the plus, minus and rand from each structure, - // notice that they are accessed with arg. (the arg notation comes from the way it was name in the - // range loop over the table) - - // Now that this is done. re-read the quickReadme (the test your test recap) and apply all the commands - // and intructions. We strongly advise to check that your error messages matches your subject. - // and that you ask a colleague to double check. - - //FINAL STEP: - // When both are satisfied with the coherence between the subject and its tests. The code can be commited - // and redeployed by the team-01. - // We then advised the staff team to test the new exercise invidually with their current build of the exam } diff --git a/tests/go/solutions/nenokku/main.go b/tests/go/solutions/nenokku/main.go index 6d02e68c..4f5176e2 100644 --- a/tests/go/solutions/nenokku/main.go +++ b/tests/go/solutions/nenokku/main.go @@ -6,22 +6,6 @@ import ( "strings" ) -func contains(big, small string) bool { - for i := 0; i <= len(big)-len(small); i++ { - if big[i] == small[0] { - for j := 0; j < len(small); j++ { - if big[i+j] != small[j] { - break - } - if j == len(small)-1 { - return true - } - } - } - } - return false -} - func main() { var big string args := os.Args[1:] @@ -35,10 +19,10 @@ func main() { break } if ch == "A" { - big = big + small + big += small } if ch == "?" { - if contains(big, small) == true { + if strings.Contains(big, small) { fmt.Println("YES") } else { fmt.Println("NO") diff --git a/tests/go/solutions/nenokku/test_nenokku.go b/tests/go/solutions/nenokku/test_nenokku.go index a88ff67a..f7a31d92 100644 --- a/tests/go/solutions/nenokku/test_nenokku.go +++ b/tests/go/solutions/nenokku/test_nenokku.go @@ -1,35 +1,23 @@ package main -import ( - "github.com/01-edu/z01" -) - -type node struct { - operations []string -} +import "github.com/01-edu/z01" func main() { - table := []node{} - - table = append(table, - node{ - []string{ - "? love", - "? is", - "A loveis", - "? love", - "? Who", - "A Whoareyou", - "? is", - }, - }, - ) + table := [][]string{{ + "? love", + "? is", + "A loveis", + "? love", + "? Who", + "A Whoareyou", + "? is", + }} sets := [][]string{ - []string{"An", "array", "variable", "denotes", "the", "entire", "array"}, - []string{"This", "means", "that", "when", "you", "assign", "or", "pass"}, - []string{"To", "avoid", "the", "copy", "you", "could", "pass"}, - []string{"struct", "but", "with", "indexed", "rather", "than", "named", "fields"}, + {"An", "array", "variable", "denotes", "the", "entire", "array"}, + {"This", "means", "that", "when", "you", "assign", "or", "pass"}, + {"To", "avoid", "the", "copy", "you", "could", "pass"}, + {"struct", "but", "with", "indexed", "rather", "than", "named", "fields"}, } ops := []string{ "?", "x", "A", @@ -44,10 +32,10 @@ func main() { s := z01.RandIntBetween(0, len(sets[index])-1) result = append(result, ops[k]+" "+sets[index][s]) } - table = append(table, node{result}) + table = append(table, result) } for _, arg := range table { - z01.ChallengeMain("nenokku", arg.operations...) + z01.ChallengeMain("nenokku", arg...) } } diff --git a/tests/go/solutions/onlya/main.go b/tests/go/solutions/onlya/main.go index 930abb29..9f0fad4c 100644 --- a/tests/go/solutions/onlya/main.go +++ b/tests/go/solutions/onlya/main.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.PrintRune('a') diff --git a/tests/go/solutions/onlya/test_onlya.go b/tests/go/solutions/onlya/test_onlya.go index a071e5f8..4bb17439 100644 --- a/tests/go/solutions/onlya/test_onlya.go +++ b/tests/go/solutions/onlya/test_onlya.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("onlya") diff --git a/tests/go/solutions/onlyz/main.go b/tests/go/solutions/onlyz/main.go index 3414268a..60703188 100644 --- a/tests/go/solutions/onlyz/main.go +++ b/tests/go/solutions/onlyz/main.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.PrintRune('z') diff --git a/tests/go/solutions/onlyz/test_onlyz.go b/tests/go/solutions/onlyz/test_onlyz.go index cde3d1f2..d2e52ec2 100644 --- a/tests/go/solutions/onlyz/test_onlyz.go +++ b/tests/go/solutions/onlyz/test_onlyz.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("onlyz") diff --git a/tests/go/solutions/piglatin/test_piglatin.go b/tests/go/solutions/piglatin/test_piglatin.go index 6777268d..8c015305 100644 --- a/tests/go/solutions/piglatin/test_piglatin.go +++ b/tests/go/solutions/piglatin/test_piglatin.go @@ -1,20 +1,18 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - type args struct { - first []string + args := [][]string{ + {"", "pig", "is", "crunch", "crnch"}, + {"something", "else"}, } - arr := []args{{first: []string{"", "pig", "is", "crunch", "crnch"}}, {first: []string{"something", "else"}}} for i := 0; i < 4; i++ { - arr = append(arr, args{first: z01.MultRandBasic()}) + args = append(args, z01.MultRandBasic()) } - for _, v := range arr { - z01.ChallengeMain("piglatin", v.first...) + for _, v := range args { + z01.ChallengeMain("piglatin", v...) } } diff --git a/tests/go/solutions/printalphabet/printalphabet.go b/tests/go/solutions/printalphabet/printalphabet.go index c7ce6d41..ba71b1b2 100644 --- a/tests/go/solutions/printalphabet/printalphabet.go +++ b/tests/go/solutions/printalphabet/printalphabet.go @@ -1,12 +1,10 @@ package main -import ( - "github.com/01-edu/z01" -) +import "fmt" func main() { - for i := 'a'; i <= 'z'; i++ { - z01.PrintRune(i) + for r := 'a'; r <= 'z'; r++ { + fmt.Print(r) } - z01.PrintRune('\n') + fmt.Println() } diff --git a/tests/go/solutions/printalphabetprog/main.go b/tests/go/solutions/printalphabetprog/main.go index c7ce6d41..ba71b1b2 100644 --- a/tests/go/solutions/printalphabetprog/main.go +++ b/tests/go/solutions/printalphabetprog/main.go @@ -1,12 +1,10 @@ package main -import ( - "github.com/01-edu/z01" -) +import "fmt" func main() { - for i := 'a'; i <= 'z'; i++ { - z01.PrintRune(i) + for r := 'a'; r <= 'z'; r++ { + fmt.Print(r) } - z01.PrintRune('\n') + fmt.Println() } diff --git a/tests/go/solutions/printalphabetprog/test_printalphabetprog.go b/tests/go/solutions/printalphabetprog/test_printalphabetprog.go index c3bf7a56..4c9fc243 100644 --- a/tests/go/solutions/printalphabetprog/test_printalphabetprog.go +++ b/tests/go/solutions/printalphabetprog/test_printalphabetprog.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("printalphabetprog") diff --git a/tests/go/solutions/printcomb.go b/tests/go/solutions/printcomb.go index 8c6ec9de..cfcae0a1 100644 --- a/tests/go/solutions/printcomb.go +++ b/tests/go/solutions/printcomb.go @@ -1,8 +1,6 @@ package solutions -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func PrintComb() { for i := '0'; i <= '7'; i++ { @@ -17,7 +15,6 @@ func PrintComb() { } else { z01.PrintRune(rune('\n')) } - } } } diff --git a/tests/go/solutions/printcomb2.go b/tests/go/solutions/printcomb2.go index c0265569..f047ee14 100644 --- a/tests/go/solutions/printcomb2.go +++ b/tests/go/solutions/printcomb2.go @@ -1,8 +1,6 @@ package solutions -import ( - "fmt" -) +import "fmt" func PrintComb2() { a := 0 diff --git a/tests/go/solutions/printcombn.go b/tests/go/solutions/printcombn.go index 8d5f1e0d..3f2238af 100644 --- a/tests/go/solutions/printcombn.go +++ b/tests/go/solutions/printcombn.go @@ -1,8 +1,6 @@ package solutions -import ( - "fmt" -) +import "fmt" func show(n int, table [9]int, tmax [9]int) { i := 0 diff --git a/tests/go/solutions/printcombprog/main.go b/tests/go/solutions/printcombprog/main.go index 49609ffa..52df7fe2 100644 --- a/tests/go/solutions/printcombprog/main.go +++ b/tests/go/solutions/printcombprog/main.go @@ -1,23 +1,20 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func printComb() { for i := '0'; i <= '7'; i++ { for j := i + 1; j <= '8'; j++ { for k := j + 1; k <= '9'; k++ { - z01.PrintRune(rune(i)) - z01.PrintRune(rune(j)) - z01.PrintRune(rune(k)) + z01.PrintRune(i) + z01.PrintRune(j) + z01.PrintRune(k) if i < '7' { - z01.PrintRune(rune(',')) - z01.PrintRune(rune(' ')) + z01.PrintRune(',') + z01.PrintRune(' ') } else { - z01.PrintRune(rune('\n')) + z01.PrintRune('\n') } - } } } diff --git a/tests/go/solutions/printcombprog/test_printcombprog.go b/tests/go/solutions/printcombprog/test_printcombprog.go index 4a92f53c..1493a3dc 100644 --- a/tests/go/solutions/printcombprog/test_printcombprog.go +++ b/tests/go/solutions/printcombprog/test_printcombprog.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("printcombprog") diff --git a/tests/go/solutions/printdigitsprog/test_printdigitsprog.go b/tests/go/solutions/printdigitsprog/test_printdigitsprog.go index aaba36e6..fd71b1f5 100644 --- a/tests/go/solutions/printdigitsprog/test_printdigitsprog.go +++ b/tests/go/solutions/printdigitsprog/test_printdigitsprog.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("printdigitsprog") diff --git a/tests/go/solutions/printmemory.go b/tests/go/solutions/printmemory.go index 74722cb0..6e2f3fb6 100644 --- a/tests/go/solutions/printmemory.go +++ b/tests/go/solutions/printmemory.go @@ -1,6 +1,8 @@ package solutions import ( + "unicode" + "github.com/01-edu/z01" ) @@ -32,21 +34,12 @@ func printBase(nbr int) int { return a } -func printascii(a int) { - if a > 31 && a < 127 { - z01.PrintRune(rune(a)) - } else { - z01.PrintRune('.') - } -} - -func printLine(arr [10]int, start int, max int) { - a := 0 - a = start - aux := 0 - var b int +func printLine(arr [10]int, start int) { + size := len(arr) + a := start + var aux, b int - for a < start+16 && a < max { + for a < start+16 && a < size { if a%4 == 0 && a != 0 { z01.PrintRune('\n') } @@ -69,8 +62,12 @@ func printLine(arr [10]int, start int, max int) { } z01.PrintRune('\n') c := start - for c < start+16 && c < max { - printascii(arr[c]) + for c < start+16 && c < size { + if unicode.IsPrint() { + z01.PrintRune(rune(arr[c])) + } else { + z01.PrintRune('.') + } c++ } z01.PrintRune('\n') @@ -78,9 +75,8 @@ func printLine(arr [10]int, start int, max int) { func PrintMemory(arr [10]int) { i := 0 - size := len(arr) - for i < size { - printLine(arr, i, size) + for i < len(arr) { + printLine(arr, i) i += 16 } } diff --git a/tests/go/solutions/printmemory/main.go b/tests/go/solutions/printmemory/main.go index b4e695a8..29edd66e 100644 --- a/tests/go/solutions/printmemory/main.go +++ b/tests/go/solutions/printmemory/main.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func printBase(nbr int) int { var result []rune diff --git a/tests/go/solutions/printnbr.go b/tests/go/solutions/printnbr.go index 62fff447..75a3476b 100644 --- a/tests/go/solutions/printnbr.go +++ b/tests/go/solutions/printnbr.go @@ -1,8 +1,6 @@ package solutions -import ( - "fmt" -) +import "fmt" func PrintNbr(n int) { fmt.Print(n) diff --git a/tests/go/solutions/printnbrbase.go b/tests/go/solutions/printnbrbase.go index fac8d6ee..2d06e362 100644 --- a/tests/go/solutions/printnbrbase.go +++ b/tests/go/solutions/printnbrbase.go @@ -1,8 +1,6 @@ package solutions -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func PrintNbrBase(n int, base string) { if ValidBase(base) { diff --git a/tests/go/solutions/printnbrinorder.go b/tests/go/solutions/printnbrinorder.go index 87db0e88..987b47d9 100644 --- a/tests/go/solutions/printnbrinorder.go +++ b/tests/go/solutions/printnbrinorder.go @@ -1,22 +1,11 @@ package solutions import ( + "sort" + "github.com/01-edu/z01" ) -func sorting(arr []int) []int { - for run := true; run; { - run = false - for i := 1; i < len(arr); i++ { - if arr[i] < arr[i-1] { - arr[i], arr[i-1] = arr[i-1], arr[i] - run = true - } - } - } - return arr -} - func intToDigits(n int) (digits []int) { for n > 0 { if n == 0 { @@ -34,7 +23,9 @@ func PrintNbrInOrder(n int) { z01.PrintRune('0') return } - for _, c := range sorting(intToDigits(n)) { - z01.PrintRune(rune(c) + '0') + digits := intToDigits(n) + sort.Ints(digits) + for _, i := range digits { + z01.PrintRune(rune(i) + '0') } } diff --git a/tests/go/solutions/printrevcombprog/test_printrevcombprog.go b/tests/go/solutions/printrevcombprog/test_printrevcombprog.go index 42bc0fb7..d7659615 100644 --- a/tests/go/solutions/printrevcombprog/test_printrevcombprog.go +++ b/tests/go/solutions/printrevcombprog/test_printrevcombprog.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("printrevcombprog") diff --git a/tests/go/solutions/printreversealphabet/printreversealphabet.go b/tests/go/solutions/printreversealphabet/printreversealphabet.go index 4db72f0d..3a1e62ce 100644 --- a/tests/go/solutions/printreversealphabet/printreversealphabet.go +++ b/tests/go/solutions/printreversealphabet/printreversealphabet.go @@ -1,12 +1,10 @@ package main -import ( - "github.com/01-edu/z01" -) +import "fmt" func main() { - for i := 'z'; i >= 'a'; i-- { - z01.PrintRune(i) + for r := 'z'; r >= 'a'; r-- { + fmt.Print(r) } - z01.PrintRune('\n') + fmt.Println() } diff --git a/tests/go/solutions/printreversealphabetprog/main.go b/tests/go/solutions/printreversealphabetprog/main.go index 4db72f0d..3a1e62ce 100644 --- a/tests/go/solutions/printreversealphabetprog/main.go +++ b/tests/go/solutions/printreversealphabetprog/main.go @@ -1,12 +1,10 @@ package main -import ( - "github.com/01-edu/z01" -) +import "fmt" func main() { - for i := 'z'; i >= 'a'; i-- { - z01.PrintRune(i) + for r := 'z'; r >= 'a'; r-- { + fmt.Print(r) } - z01.PrintRune('\n') + fmt.Println() } diff --git a/tests/go/solutions/printreversealphabetprog/test_printreversealphabetprog.go b/tests/go/solutions/printreversealphabetprog/test_printreversealphabetprog.go index 19ee253a..5277d8f1 100644 --- a/tests/go/solutions/printreversealphabetprog/test_printreversealphabetprog.go +++ b/tests/go/solutions/printreversealphabetprog/test_printreversealphabetprog.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("printreversealphabetprog") diff --git a/tests/go/solutions/printstr.go b/tests/go/solutions/printstr.go index 7495ac60..2ae5cff9 100644 --- a/tests/go/solutions/printstr.go +++ b/tests/go/solutions/printstr.go @@ -1,9 +1,7 @@ package solutions -import ( - "fmt" -) +import "fmt" -func PrintStr(str string) { - fmt.Print(str) +func PrintStr(s string) { + fmt.Print(s) } diff --git a/tests/go/solutions/printstrprog/test_printstrprog.go b/tests/go/solutions/printstrprog/test_printstrprog.go index 83455cd9..b6643cb5 100644 --- a/tests/go/solutions/printstrprog/test_printstrprog.go +++ b/tests/go/solutions/printstrprog/test_printstrprog.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { table := z01.MultRandASCII() diff --git a/tests/go/solutions/printwordstables.go b/tests/go/solutions/printwordstables.go index 29b85bfc..c3d77962 100644 --- a/tests/go/solutions/printwordstables.go +++ b/tests/go/solutions/printwordstables.go @@ -1,15 +1,9 @@ package solutions -import ( - "fmt" -) +import "fmt" -func PrintWordsTables(table []string) { - for _, t := range table { - fmt.Println(t) +func PrintWordsTables(a []string) { + for _, s := range a { + fmt.Println(s) } } - -func isSeparator(r rune) bool { - return r == ' ' || r == '\t' || r == '\n' -} diff --git a/tests/go/solutions/priorprime.go b/tests/go/solutions/priorprime.go index 13733644..e0724d9d 100644 --- a/tests/go/solutions/priorprime.go +++ b/tests/go/solutions/priorprime.go @@ -1,13 +1,6 @@ package solutions -//This solution is the comparing file of the staff -// Because the solution is a function, -// -//1) here the package is solutions -//2) it does not need an empty func main(){} -//3) its location is 1 level below the folder of the nauuo_test.go file - -func Priorprime(x int) int { +func PriorPrime(x int) int { ans := 0 ok := 0 for i := 2; i < x; i++ { diff --git a/tests/go/solutions/priorprime/main.go b/tests/go/solutions/priorprime/main.go index 7fd5e2b5..6a673c6d 100644 --- a/tests/go/solutions/priorprime/main.go +++ b/tests/go/solutions/priorprime/main.go @@ -1,12 +1,6 @@ package main -//This solution is the placeholder of the student solution -// for an exercise in the exam asking for a Function -//Remember the disclaimer!!!! -//1) here the package is main -//2) It does need an empty func main(){} - -func Priorprime(x int) int { +func PriorPrime(x int) int { ans := 0 ok := 0 for i := 2; i < x; i++ { diff --git a/tests/go/solutions/priorprime/priorprime_test.go b/tests/go/solutions/priorprime/priorprime_test.go index fb8eacb7..4d24c978 100644 --- a/tests/go/solutions/priorprime/priorprime_test.go +++ b/tests/go/solutions/priorprime/priorprime_test.go @@ -3,77 +3,20 @@ package main import ( "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) func main() { - // Declaration of the node that is going to take the group of arguments that are going to - // inputed during each iteration of a Challenge between the student and the staff solution. - // (note: a node is not always necessary but in this case it makes the writing of the test easier) - - type node struct { - first int + table := []int{ + 50, + 13, + 10, + 0, + 1, + 2, } - - // Declaration of an empty array of type node{} - // note that in this case this is the easiest type of table to declare - // but a table can be of any other relevant type, (for example []string{}, []int{} if it - // were a single string tested or a single int) - - table := []node{} - // Initial filling of that array with the values I see in the examples of the subject - - table = append(table, - node{50}, - node{13}, - node{10}, - node{0}, - node{1}, - node{2}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library - - for i := 0; i < 15; i++ { - value := node{ - first: z01.RandIntBetween(0, 1000), - //this z01.RandIntBetween function allows the randomization of - //the int for each value in a desired range. - //Note that they are many others of those functions for other types of data - //Do not hesitate to have a look at all of them https://github.com/01-edu/z01 - } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - table = append(table, value) - } - - //The table with 4 specific exercises and 15 randoms is now ready to be "challenged" - //Because the exercise asks for a function we are now using the Challenge function (this function would - // be the ChallengeMainExam function) - + table = append(table, z01.MultRandIntBetween(0, 1000)) for _, arg := range table { - z01.Challenge("Priorprime", Priorprime, solutions.Priorprime, arg.first) + z01.Challenge("PriorPrime", PriorPrime, solutions.PriorPrime, arg) } - - // the z01.Challenge function is here applied to each argument of the table. It musts contains: - // 1) first, the t argument from the T structure imported from the package "testing" - // - // 2) second, the function from the student, in this case Nauuo - //(this disapears in the ChallengeMainExam function) - // 3) third, the function from the staff, in this case solutions.Nauuo - //(this disapears as well in the ChallengeMainExam function) - // 4) all the arguments to be tested, in this case it is the plus, minus and rand from each structure, - // notice that they are accessed with arg. (the arg notation comes from the way it was name in the - // range loop over the table) - - // Now that this is done. re-read the quickReadme (the test your test recap) and apply all the commands - // and intructions. We strongly advise to check that your error messages matches your subject. - // and that you ask a colleague to double check. - - //FINAL STEP: - // When both are satisfied with the coherence between the subject and its tests. The code can be commited - // and redeployed by the team-01. - // We then advised the staff team to test the new exercise invidually with their current build of the exam } diff --git a/tests/go/solutions/range/main.go b/tests/go/solutions/range/main.go index 6c948766..8081bf37 100644 --- a/tests/go/solutions/range/main.go +++ b/tests/go/solutions/range/main.go @@ -6,23 +6,6 @@ import ( "strconv" ) -func main() { - if len(os.Args) == 3 { - secondArg := 0 - firstArg, err := strconv.Atoi(os.Args[1]) - if err == nil { - secondArg, err = strconv.Atoi(os.Args[2]) - } - if err != nil { - fmt.Println(err) - return - } - fmt.Println(rangeOf(firstArg, secondArg)) - } else { - fmt.Println() - } -} - func rangeOf(start, end int) []int { var ran []int if start >= end { @@ -30,10 +13,25 @@ func rangeOf(start, end int) []int { ran = append(ran, i) } return ran - } else { - for i := start; i <= end; i++ { - ran = append(ran, i) - } - return ran } + for i := start; i <= end; i++ { + ran = append(ran, i) + } + return ran +} + +func main() { + if len(os.Args) != 3 { + return + } + secondArg := 0 + firstArg, err := strconv.Atoi(os.Args[1]) + if err == nil { + secondArg, err = strconv.Atoi(os.Args[2]) + } + if err != nil { + fmt.Println(err) + return + } + fmt.Println(rangeOf(firstArg, secondArg)) } diff --git a/tests/go/solutions/reachablenumber.go b/tests/go/solutions/reachablenumber.go index 26637924..2885a1ba 100644 --- a/tests/go/solutions/reachablenumber.go +++ b/tests/go/solutions/reachablenumber.go @@ -1,6 +1,6 @@ package solutions -func Reachablenumber(n int) int { +func ReachableNumber(n int) int { cnt := 0 for n > 0 { cnt++ diff --git a/tests/go/solutions/reachablenumberprog/main.go b/tests/go/solutions/reachablenumberprog/main.go index a34e5a31..a969e7e1 100644 --- a/tests/go/solutions/reachablenumberprog/main.go +++ b/tests/go/solutions/reachablenumberprog/main.go @@ -1,6 +1,6 @@ package main -func Reachablenumber(n int) int { +func ReachableNumber(n int) int { cnt := 0 for n > 0 { cnt++ diff --git a/tests/go/solutions/reachablenumberprog/reachablenumber_test.go b/tests/go/solutions/reachablenumberprog/reachablenumber_test.go index 0a497763..d2964cfe 100644 --- a/tests/go/solutions/reachablenumberprog/reachablenumber_test.go +++ b/tests/go/solutions/reachablenumberprog/reachablenumber_test.go @@ -3,42 +3,20 @@ package main import ( "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) func main() { - type node struct { - n int + table := []int{ + 20, + 1, + 9, + 2, } - - table := []node{} - // Initial filling of that array with the values I see in the examples of the subject - - table = append(table, - node{20}, - node{1}, - node{9}, - node{2}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library - for i := 0; i < 25; i++ { - value := node{ - n: z01.RandIntBetween(1, 877), - } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - table = append(table, value) + table = append(table, z01.MultRandIntBetween(1, 877)) } - - //The table with 4 specific exercises and 15 randoms is now ready to be "challenged" - //Because the exercise asks for a function we are now using the Challenge function (this function would - // be the ChallengeMainExam function) - for _, arg := range table { - z01.Challenge("ReachableNumber", Reachablenumber, solutions.Reachablenumber, arg.n) + z01.Challenge("ReachableNumber", ReachableNumber, solutions.ReachableNumber, arg) } } diff --git a/tests/go/solutions/rectangle/main.go b/tests/go/solutions/rectangle/main.go index bf222ffa..8cf99852 100644 --- a/tests/go/solutions/rectangle/main.go +++ b/tests/go/solutions/rectangle/main.go @@ -1,8 +1,6 @@ package main -import ( - "fmt" -) +import "fmt" type point struct { x int diff --git a/tests/go/solutions/recursivepower.go b/tests/go/solutions/recursivepower.go index 0fa5fdd8..658c78c1 100644 --- a/tests/go/solutions/recursivepower.go +++ b/tests/go/solutions/recursivepower.go @@ -1,8 +1,6 @@ package solutions -import ( - "math" -) +import "math" func RecursivePower(nb, power int) int { if power < 0 { diff --git a/tests/go/solutions/reduceint/reduceint_test.go b/tests/go/solutions/reduceint/reduceint_test.go index 46d243aa..b266eaf5 100644 --- a/tests/go/solutions/reduceint/reduceint_test.go +++ b/tests/go/solutions/reduceint/reduceint_test.go @@ -1,8 +1,9 @@ package main import ( - solutions "../../solutions" "github.com/01-edu/z01" + + solutions "../../solutions" ) func main() { diff --git a/tests/go/solutions/repeatalpha/main.go b/tests/go/solutions/repeatalpha/main.go index 79da72da..42b14a28 100644 --- a/tests/go/solutions/repeatalpha/main.go +++ b/tests/go/solutions/repeatalpha/main.go @@ -2,29 +2,22 @@ package main import ( "os" + "unicode" "github.com/01-edu/z01" ) -func toLowerCase(a rune) rune { - if a >= 'A' && a <= 'Z' { - dif := 'a' - 'A' - return a + dif - } - return a -} - func main() { - if len(os.Args) > 1 { - arg := []rune(os.Args[1]) - for _, c := range arg { - z01.PrintRune(c) - rep := int(toLowerCase(c) - 'a') - for i := 0; i < rep; i++ { - z01.PrintRune(c) + if len(os.Args) == 2 { + for _, r := range os.Args[1] { + z01.PrintRune(r) + if unicode.IsLetter(r) { + rep := unicode.ToLower(r) - 'a' + for i := 0; i < int(rep); i++ { + z01.PrintRune(r) + } } } + z01.PrintRune('\n') } - - z01.PrintRune('\n') } diff --git a/tests/go/solutions/repeatalpha/test_repeatalpha.go b/tests/go/solutions/repeatalpha/test_repeatalpha.go index c0eea3c9..94d51d69 100644 --- a/tests/go/solutions/repeatalpha/test_repeatalpha.go +++ b/tests/go/solutions/repeatalpha/test_repeatalpha.go @@ -1,24 +1,25 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - args := []string{"Hello", + args := []string{ + "", + "Hello", "World", "Home", "Theorem", "Choumi is the best cat", "abracadaba 01!", "abc", - "MaTheMatiCs"} - - for i := 0; i < 5; i++ { - args = append(args, z01.RandAlnum()) + "MaTheMatiCs", } + args = append(args, z01.MultRandAlnum()...) + for _, v := range args { z01.ChallengeMain("repeatalpha", v) } + z01.ChallengeMain("repeatalpha") + z01.ChallengeMain("repeatalpha", "", "") } diff --git a/tests/go/solutions/reverse.go b/tests/go/solutions/reverse.go index f4cb8b67..6a946b00 100644 --- a/tests/go/solutions/reverse.go +++ b/tests/go/solutions/reverse.go @@ -1,12 +1,5 @@ package solutions -//This solution is the comparing file of the staff -// Because the solution is a function, -// -//1) here the package is solutions -//2) it does not need an empty func main(){} -//3) its location is 1 level below the folder of the nauuo_test.go file - func Reverse(node *NodeAddL) *NodeAddL { if node == nil { return node diff --git a/tests/go/solutions/reverse/main.go b/tests/go/solutions/reverse/main.go index 13256dd2..cb570e58 100644 --- a/tests/go/solutions/reverse/main.go +++ b/tests/go/solutions/reverse/main.go @@ -1,11 +1,5 @@ package main -//This solution is the placeholder of the student solution -// for an exercise in the exam asking for a Function -//Remember the disclaimer!!!! -//1) here the package is main -//2) It does need an empty func main(){} - type NodeAddL struct { Next *NodeAddL Num int diff --git a/tests/go/solutions/reverse/reverse_test.go b/tests/go/solutions/reverse/reverse_test.go index b84c5b04..8e758c0a 100644 --- a/tests/go/solutions/reverse/reverse_test.go +++ b/tests/go/solutions/reverse/reverse_test.go @@ -1,11 +1,9 @@ package main import ( - "testing" - "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) type stuNode = NodeAddL @@ -59,91 +57,33 @@ func solListToNum(node *solNode) int { return n } -func compareNodes(t *testing.T, stuResult *stuNode, solResult *solNode, num1 int) { +func compareNodes(stuResult *stuNode, solResult *solNode, num1 int) { if stuResult != nil && solResult != nil { stuNum := stuListToNum(stuResult) solNum := solListToNum(solResult) if stuNum != solNum { - t.Fatalf("\nReverse(%d) == %v instead of %v\n\n", + z01.Fatalf("\nReverse(%d) == %v instead of %v\n\n", num1, stuNum, solNum) } } else if stuResult != nil && solResult == nil { stuNum := stuListToNum(stuResult) - t.Fatalf("\nReverse(%d) == %v instead of %v\n\n", + z01.Fatalf("\nReverse(%d) == %v instead of %v\n\n", num1, stuNum, "") } else if stuResult == nil && solResult != nil { solNum := solListToNum(solResult) - t.Fatalf("\nReverse(%d) == %v instead of %v\n\n", + z01.Fatalf("\nReverse(%d) == %v instead of %v\n\n", num1, "", solNum) } } -func TestReverse(t *testing.T) { - // Declaration of the node that is going to take the group of arguments that are going to - // inputed during each iteration of a Challenge between the student and the staff solution. - // (note: a node is not always necessary but in this case it makes the writing of the test easier) - - type node struct { - num1 int - } - - // Declaration of an empty array of type node{} - // note that in this case this is the easiest type of table to declare - // but a table can be of any other relevant type, (for example []string{}, []int{} if it - // were a single string tested or a single int) - - table := []node{} - // Initial filling of that array with the values I see in the examples of the subject - - table = append(table, - node{123456543}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library - - for i := 0; i < 15; i++ { - value := node{ - num1: z01.RandIntBetween(0, 1000000000), - //this z01.RandIntBetween function allows the randomization of - //the int for each value in a desired range. - //Note that they are many others of those functions for other types of data - //Do not hesitate to have a look at all of them https://github.com/01-edu/z01 - } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - table = append(table, value) - } - - //The table with 4 specific exercises and 15 randoms is now ready to be "challenged" - //Because the exercise asks for a function we are now using the Challenge function (this function would - // be the ChallengeMainExam function) +func main() { + table := []int{123456543} + table = append(table, z01.MultRandIntBetween(0, 1000000000)...) for _, arg := range table { - stuResult := Reverse(stuNumToList(arg.num1)) - solResult := solutions.Reverse(solNumToList(arg.num1)) + stuResult := Reverse(stuNumToList(arg)) + solResult := solutions.Reverse(solNumToList(arg)) - compareNodes(t, stuResult, solResult, arg.num1) + compareNodes(stuResult, solResult, arg) } - - // the z01.Challenge function is here applied to each argument of the table. It musts contains: - // 1) first, the t argument from the T structure imported from the package "testing" - // - // 2) second, the function from the student, in this case Nauuo - //(this disapears in the ChallengeMainExam function) - // 3) third, the function from the staff, in this case solutions.Nauuo - //(this disapears as well in the ChallengeMainExam function) - // 4) all the arguments to be tested, in this case it is the plus, minus and rand from each structure, - // notice that they are accessed with arg. (the arg notation comes from the way it was name in the - // range loop over the table) - - // Now that this is done. re-read the quickReadme (the test your test recap) and apply all the commands - // and intructions. We strongly advise to check that your error messages matches your subject. - // and that you ask a colleague to double check. - - //FINAL STEP: - // When both are satisfied with the coherence between the subject and its tests. The code can be commited - // and redeployed by the team-01. - // We then advised the staff team to test the new exercise invidually with their current build of the exam } diff --git a/tests/go/solutions/reversebits.go b/tests/go/solutions/reversebits.go index 8dd2eff6..cc79d59f 100644 --- a/tests/go/solutions/reversebits.go +++ b/tests/go/solutions/reversebits.go @@ -1,9 +1,7 @@ package solutions -import ( - "math/bits" -) +import "math/bits" -func ReverseBits(by byte) byte { - return bits.Reverse8(uint8(by)) +func ReverseBits(octet byte) byte { + return bits.Reverse8(uint8(octet)) } diff --git a/tests/go/solutions/reversebits/main.go b/tests/go/solutions/reversebits/main.go index 6b613ce4..17c8f653 100644 --- a/tests/go/solutions/reversebits/main.go +++ b/tests/go/solutions/reversebits/main.go @@ -1,8 +1,6 @@ package main -import ( - "math/bits" -) +import "math/bits" func ReverseBits(by byte) byte { return bits.Reverse8(uint8(by)) diff --git a/tests/go/solutions/reversebits/reversebits_test.go b/tests/go/solutions/reversebits/reversebits_test.go index 2da02841..757bc69c 100644 --- a/tests/go/solutions/reversebits/reversebits_test.go +++ b/tests/go/solutions/reversebits/reversebits_test.go @@ -2,20 +2,18 @@ package main import ( "reflect" - "testing" "github.com/01-edu/z01" solutions "../../solutions" ) -func challengeBytes(t *testing.T, - fn1, fn2 interface{}, args ...interface{}) { +func challengeBytes(fn1, fn2 interface{}, args ...interface{}) { st1 := z01.Monitor(fn1, args) st2 := z01.Monitor(fn2, args) if !reflect.DeepEqual(st1.Results, st2.Results) { - t.Fatalf("%s(%08b) == %08b instead of %08b\n", - z01.NameOfFunc(fn1), + z01.Fatalf("%s(%08b) == %08b instead of %08b\n", + "ReverseBits", args[0].(byte), st1.Results[0].(byte), st2.Results[0].(byte), @@ -23,9 +21,8 @@ func challengeBytes(t *testing.T, } } -func TestReverseBits(t *testing.T) { - args := []byte{byte(0x26), byte(0x27), byte(0x28), - byte(0x29), byte(0xAA), byte(0xBB)} +func main() { + args := []byte{0x26, 0x27, 0x28, 0x29, 0xAA, 0xBB} for i := 0; i < 10; i++ { n := z01.RandIntBetween(0, 255) @@ -33,6 +30,6 @@ func TestReverseBits(t *testing.T) { } for _, v := range args { - challengeBytes(t, ReverseBits, solutions.ReverseBits, v) + challengeBytes(ReverseBits, solutions.ReverseBits, v) } } diff --git a/tests/go/solutions/reversestrcap/test_reversestrcap.go b/tests/go/solutions/reversestrcap/test_reversestrcap.go index 64712bd9..68aae038 100644 --- a/tests/go/solutions/reversestrcap/test_reversestrcap.go +++ b/tests/go/solutions/reversestrcap/test_reversestrcap.go @@ -1,13 +1,12 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - arg1 := []string{"First SMALL TesT"} - arg2 := []string{"SEconD Test IS a LItTLE EasIEr", "bEwaRe IT'S NoT HARd WhEN ", " Go a dernier 0123456789 for the road e"} - args := [][]string{arg1, arg2} + args := [][]string{ + {"First SMALL TesT"}, + {"SEconD Test IS a LItTLE EasIEr", "bEwaRe IT'S NoT HARd WhEN ", " Go a dernier 0123456789 for the road e"}, + } for i := 0; i < 15; i++ { args = append(args, z01.MultRandAlnum()) diff --git a/tests/go/solutions/revivethreenums.go b/tests/go/solutions/revivethreenums.go index 5f6dab62..d1e77a8c 100644 --- a/tests/go/solutions/revivethreenums.go +++ b/tests/go/solutions/revivethreenums.go @@ -23,7 +23,7 @@ func max(a, b, c, d int) int { return -1 } -func Revive_three_nums(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) diff --git a/tests/go/solutions/revivethreenums/main.go b/tests/go/solutions/revivethreenums/main.go index 12468b30..2ebdc823 100644 --- a/tests/go/solutions/revivethreenums/main.go +++ b/tests/go/solutions/revivethreenums/main.go @@ -23,7 +23,7 @@ func max(a, b, c, d int) int { return -1 } -func Revive_three_nums(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) diff --git a/tests/go/solutions/revivethreenums/revivethreenums_test.go b/tests/go/solutions/revivethreenums/revivethreenums_test.go index 9d8dd216..3cd76983 100644 --- a/tests/go/solutions/revivethreenums/revivethreenums_test.go +++ b/tests/go/solutions/revivethreenums/revivethreenums_test.go @@ -3,49 +3,28 @@ package main import ( "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) func main() { - type node struct { - a int - b int - c int - d int + table := [][4]int{ + {3, 6, 5, 4}, + {40, 40, 40, 60}, + {201, 101, 101, 200}, } - table := []node{} - // Initial filling of that array with the values I see in the examples of the subject - - table = append(table, - node{3, 6, 5, 4}, - node{40, 40, 40, 60}, - node{201, 101, 101, 200}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library for i := 0; i < 25; i++ { first := z01.RandIntBetween(0, 877) second := z01.RandIntBetween(0, 877) third := z01.RandIntBetween(0, 877) - value := node{ - a: first + second, - b: second + third, - c: first + third, - d: first + second + third, - } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - table = append(table, value) + table = append(table, [4]int{ + first + second, + second + third, + first + third, + first + second + third, + }) } - - //The table with 4 specific exercises and 15 randoms is now ready to be "challenged" - //Because the exercise asks for a function we are now using the Challenge function (this function would - // be the ChallengeMainExam function) - for _, arg := range table { - z01.Challenge("Revivethreenums", Revive_three_nums, solutions.Revive_three_nums, arg.a, arg.b, arg.c, arg.d) + z01.Challenge("Revivethreenums", ReviveThreeNums, solutions.ReviveThreeNums, arg[0], arg[1], arg[2], arg[3]) } } diff --git a/tests/go/solutions/revwstr/test_revwstr.go b/tests/go/solutions/revwstr/test_revwstr.go index 24a313e8..b5509d73 100644 --- a/tests/go/solutions/revwstr/test_revwstr.go +++ b/tests/go/solutions/revwstr/test_revwstr.go @@ -1,27 +1,24 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - table := []string{} - - table = append(table, + table := []string{ "", "abcdefghijklm", "the time of contempt precedes that of indifference", "he stared at the mountain", - "qw qw e qwsa d") + "qw qw e qwsa d", + } - //3 valid random sentences with no spaces at the beginning nor the end and only one space for separator. + // 3 valid random sentences with no spaces at the beginning nor the end and only one space for separator. for i := 0; i < 3; i++ { numberOfWords := z01.RandIntBetween(1, 6) sentence := z01.RandAlnum() for j := 0; j < numberOfWords; j++ { - sentence = sentence + " " + z01.RandAlnum() + sentence += " " + z01.RandAlnum() } - sentence = sentence + z01.RandAlnum() + sentence += z01.RandAlnum() table = append(table, sentence) } diff --git a/tests/go/solutions/robottoorigin/main.go b/tests/go/solutions/robottoorigin/main.go index 07ee2f4c..a0749dbc 100644 --- a/tests/go/solutions/robottoorigin/main.go +++ b/tests/go/solutions/robottoorigin/main.go @@ -1,48 +1,28 @@ package main -import ( - "os" +import "fmt" - "github.com/01-edu/z01" -) - -func solve(str string) bool { +func solve(s string) bool { x := 0 y := 0 - for _, c := range str { - if c == 'L' { + for _, r := range s { + switch r { + case 'L': x-- - } else if c == 'R' { + case 'R': x++ - } else if c == 'U' { + case 'U': y++ - } else if c == 'D' { + case 'D': y-- } } - if x == 0 && y == 0 { - return true - } - return false -} - -func print(str string) { - for _, v := range str { - z01.PrintRune(v) - } + return x == 0 && y == 0 } func main() { - args := os.Args[1:] - if len(args) != 1 { - z01.PrintRune('\n') - return - } - result := solve(args[0]) - if result { - print("true\n") - } else { - print("false\n") + if len(args) == 2 { + fmt.Println(solve(args[1])) } } diff --git a/tests/go/solutions/robottoorigin/test_robottoorigin.go b/tests/go/solutions/robottoorigin/test_robottoorigin.go index 908de959..20f62a98 100644 --- a/tests/go/solutions/robottoorigin/test_robottoorigin.go +++ b/tests/go/solutions/robottoorigin/test_robottoorigin.go @@ -1,20 +1,15 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - table := []string{} - - table = append(table, + table := []string{ "UD", "LL", - ) + } for i := 0; i < 15; i++ { - value := z01.RandStr(z01.RandIntBetween(5, 1000), "UDLR") - table = append(table, value) + table = append(table, z01.RandStr(z01.RandIntBetween(5, 1000), "UDLR")) } for _, arg := range table { diff --git a/tests/go/solutions/rostring/test_rostring.go b/tests/go/solutions/rostring/test_rostring.go index 58b9355a..6557842f 100644 --- a/tests/go/solutions/rostring/test_rostring.go +++ b/tests/go/solutions/rostring/test_rostring.go @@ -1,29 +1,20 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - corrArgs := []string{"abc ", + args := []string{ + "abc ", "Let there be light", " AkjhZ zLKIJz , 23y", "", } + args = append(args, z01.MultRandWords()...) - // some random valid parameter - for i := 0; i < 5; i++ { - corrArgs = append(corrArgs, z01.RandWords()) + for _, arg := range args { + z01.ChallengeMain("rostring", arg) } - - for _, v := range corrArgs { - z01.ChallengeMain("rostring", v) - } - - //without parameter z01.ChallengeMain("rostring") - - //with more than one parameter z01.ChallengeMain("rostring", "this", "is") z01.ChallengeMain("rostring", "not", "good", "for you") } diff --git a/tests/go/solutions/rot13/main.go b/tests/go/solutions/rot13/main.go index 09d4e2ff..8609493f 100644 --- a/tests/go/solutions/rot13/main.go +++ b/tests/go/solutions/rot13/main.go @@ -7,26 +7,22 @@ import ( ) func main() { - if len(os.Args) != 2 { - z01.PrintRune('\n') - } else { - arrayRune := []byte(os.Args[1]) - - for i := 0; i < len(arrayRune); i++ { - if arrayRune[i] >= 'a' && arrayRune[i] <= 'z' { - if arrayRune[i] >= ('a' + 13) { - arrayRune[i] = arrayRune[i] - 13 + if len(os.Args) == 2 { + for _, r := range os.Args[1] { + if r >= 'a' && r <= 'z' { + if r >= 'a'+13 { + r -= 13 } else { - arrayRune[i] = arrayRune[i] + 13 + r += 13 } - } else if arrayRune[i] >= 'A' && arrayRune[i] <= 'Z' { - if arrayRune[i] >= ('A' + 13) { - arrayRune[i] = arrayRune[i] - 13 + } else if r >= 'A' && r <= 'Z' { + if r >= 'A'+13 { + r -= 13 } else { - arrayRune[i] = arrayRune[i] + 13 + r += 13 } } - z01.PrintRune(rune(arrayRune[i])) + z01.PrintRune(r) } z01.PrintRune('\n') } diff --git a/tests/go/solutions/rot13/test_rot13.go b/tests/go/solutions/rot13/test_rot13.go index 18faaaeb..59d6ea34 100644 --- a/tests/go/solutions/rot13/test_rot13.go +++ b/tests/go/solutions/rot13/test_rot13.go @@ -1,14 +1,13 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - table := append(z01.MultRandWords(), " ") - table = append(table, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRSTUVWXYZ") - table = append(table, "a b c d e f g h ijklmnopqrstuvwxyz A B C D E FGHIJKLMNOPRSTUVWXYZ") - + table := append(z01.MultRandWords(), + " ", + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRSTUVWXYZ", + "a b c d e f g h ijklmnopqrstuvwxyz A B C D E FGHIJKLMNOPRSTUVWXYZ", + ) for _, s := range table { z01.ChallengeMain("rot13", s) } diff --git a/tests/go/solutions/rot14.go b/tests/go/solutions/rot14.go index 9e31f166..37204dd6 100644 --- a/tests/go/solutions/rot14.go +++ b/tests/go/solutions/rot14.go @@ -1,24 +1,21 @@ package solutions -func Rot14(str string) string { - arrayRune := []rune(str) - var result string - - for i := 0; i < len(arrayRune); i++ { - if arrayRune[i] >= 'a' && arrayRune[i] <= 'z' { - if arrayRune[i] >= 'm' { - arrayRune[i] = arrayRune[i] - 12 +func Rot14(s string) (result string) { + for _, r := range s { + if r >= 'a' && r <= 'z' { + if r >= 'm' { + r -= 12 } else { - arrayRune[i] = arrayRune[i] + 14 + r += 14 } - } else if arrayRune[i] >= 'A' && arrayRune[i] <= 'Z' { - if arrayRune[i] >= 'M' { - arrayRune[i] = arrayRune[i] - 12 + } else if r >= 'A' && r <= 'Z' { + if r >= 'M' { + r -= 12 } else { - arrayRune[i] = arrayRune[i] + 14 + r += 14 } } - result += string(arrayRune[i]) + result += string(r) } return result } diff --git a/tests/go/solutions/rot14prog/main.go b/tests/go/solutions/rot14prog/main.go index 2a1d55ba..22dd40e7 100644 --- a/tests/go/solutions/rot14prog/main.go +++ b/tests/go/solutions/rot14prog/main.go @@ -6,29 +6,27 @@ import ( ) func main() { - if len(os.Args) < 2 || len(os.Args) > 2 { - fmt.Println() + if len(os.Args) != 2 { return } - arrayRune := []rune(os.Args[1]) var result string - for i := 0; i < len(arrayRune); i++ { - if arrayRune[i] >= 'a' && arrayRune[i] <= 'z' { - if arrayRune[i] >= 'm' { - arrayRune[i] = arrayRune[i] - 12 + for _, r := range os.Args[1] { + if r >= 'a' && r <= 'z' { + if r >= 'm' { + r -= 12 } else { - arrayRune[i] = arrayRune[i] + 14 + r += 14 } - } else if arrayRune[i] >= 'A' && arrayRune[i] <= 'Z' { - if arrayRune[i] >= 'M' { - arrayRune[i] = arrayRune[i] - 12 + } else if r >= 'A' && r <= 'Z' { + if r >= 'M' { + r -= 12 } else { - arrayRune[i] = arrayRune[i] + 14 + r += 14 } } - result += string(arrayRune[i]) + result += string(r) } fmt.Println(result) } diff --git a/tests/go/solutions/rot14prog/test_rot14prog.go b/tests/go/solutions/rot14prog/test_rot14prog.go index 1b4ff38d..ec8cf862 100644 --- a/tests/go/solutions/rot14prog/test_rot14prog.go +++ b/tests/go/solutions/rot14prog/test_rot14prog.go @@ -1,26 +1,14 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - type nodeTest struct { - data []string - } - - table := []nodeTest{} - for i := 0; i < 2; i++ { - val := nodeTest{ - data: z01.MultRandWords(), - } - table = append(table, val) - } + table := append(z01.MultRandWords(), + z01.MultRandWords()..., + ) for _, arg := range table { - for _, s := range arg.data { - z01.ChallengeMain("rot14prog", s) - } + z01.ChallengeMain("rot14prog", arg) } z01.ChallengeMain("rot14prog", "", "something", "something1") } diff --git a/tests/go/solutions/rpncalc/test_rpncalc.go b/tests/go/solutions/rpncalc/test_rpncalc.go index a12be7ab..860fb3fe 100644 --- a/tests/go/solutions/rpncalc/test_rpncalc.go +++ b/tests/go/solutions/rpncalc/test_rpncalc.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { args := []string{ diff --git a/tests/go/solutions/sametree.go b/tests/go/solutions/sametree.go index 901af31f..5d049031 100644 --- a/tests/go/solutions/sametree.go +++ b/tests/go/solutions/sametree.go @@ -10,10 +10,7 @@ func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool { if p == nil && q == nil { return true } - if checkIfEq(p, q) == true { - return true - } - return false + return checkIfEq(p, q) } func checkIfEq(t1 *TreeNodeL, t2 *TreeNodeL) bool { diff --git a/tests/go/solutions/sametree/main.go b/tests/go/solutions/sametree/main.go index f4a1ae2c..69671e2c 100644 --- a/tests/go/solutions/sametree/main.go +++ b/tests/go/solutions/sametree/main.go @@ -10,10 +10,7 @@ func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool { if p == nil && q == nil { return true } - if checkIfEq(p, q) == true { - return true - } - return false + return checkIfEq(p, q) } func checkIfEq(t1 *TreeNodeL, t2 *TreeNodeL) bool { diff --git a/tests/go/solutions/sametree/sametree_test.go b/tests/go/solutions/sametree/sametree_test.go index cf87323e..42d5f6d8 100644 --- a/tests/go/solutions/sametree/sametree_test.go +++ b/tests/go/solutions/sametree/sametree_test.go @@ -3,10 +3,10 @@ package main import ( "math/rand" "strconv" - "testing" - solutions "../../solutions" "github.com/01-edu/z01" + + solutions "../../solutions" ) type stuTreeNode = TreeNodeL @@ -82,15 +82,15 @@ func returnStuTree(root *stuTreeNode) string { return ans } -func compareResults(t *testing.T, stuResult, solResult bool, solTree1, solTree2 *solTreeNode) { +func compareResults(stuResult, solResult bool, solTree1, solTree2 *solTreeNode) { if stuResult != solResult { tree1 := returnSolTree(solTree1) tree2 := returnSolTree(solTree2) - t.Fatalf("\nIsSameTree(\"%v\", \"%v\") == \"%v\" instead of \"%v\"\n\n", tree1, tree2, stuResult, solResult) + z01.Fatalf("\nIsSameTree(\"%v\", \"%v\") == \"%v\" instead of \"%v\"\n\n", tree1, tree2, stuResult, solResult) } } -func TestMerge(t *testing.T) { +func main() { type node struct { n int k int @@ -109,7 +109,7 @@ func TestMerge(t *testing.T) { stuResult := IsSameTree(stuTree1, stuTree2) solResult := solutions.IsSameTree(solTree1, solTree2) - compareResults(t, stuResult, solResult, cop1, cop2) + compareResults(stuResult, solResult, cop1, cop2) } // Check for same trees @@ -118,6 +118,6 @@ func TestMerge(t *testing.T) { stuResult := IsSameTree(stuTree1, stuTree1) solResult := solutions.IsSameTree(solTree1, solTree1) - compareResults(t, stuResult, solResult, cop1, cop1) + compareResults(stuResult, solResult, cop1, cop1) } } diff --git a/tests/go/solutions/searchreplace/main.go b/tests/go/solutions/searchreplace/main.go index 0c325790..41f2b2d8 100644 --- a/tests/go/solutions/searchreplace/main.go +++ b/tests/go/solutions/searchreplace/main.go @@ -1,25 +1,18 @@ package main import ( + "fmt" "os" - - "github.com/01-edu/z01" + "strings" ) func main() { - if len(os.Args) <= 1 || len(os.Args) > 4 { - z01.PrintRune('\n') - } else if len(os.Args) == 4 { - array := []rune(os.Args[1]) - search := []rune(os.Args[2]) - replace := []rune(os.Args[3]) - for _, val := range array { - if val == search[0] { - z01.PrintRune(replace[0]) - } else { - z01.PrintRune(val) + if len(os.Args) == 4 { + fmt.Println(strings.Map(func(r rune) rune { + if r == []rune(os.Args[2])[0] { + return []rune(os.Args[3])[0] } - } - z01.PrintRune('\n') + return r + }, os.Args[1])) } } diff --git a/tests/go/solutions/searchreplace/test_searchreplace.go b/tests/go/solutions/searchreplace/test_searchreplace.go index 46323094..87390c82 100644 --- a/tests/go/solutions/searchreplace/test_searchreplace.go +++ b/tests/go/solutions/searchreplace/test_searchreplace.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { type nodeTest struct { diff --git a/tests/go/solutions/slice.go b/tests/go/solutions/slice.go index d296436f..3aca3b23 100644 --- a/tests/go/solutions/slice.go +++ b/tests/go/solutions/slice.go @@ -1,43 +1,42 @@ package solutions -func Slice(arr []string, nbr ...int) []string { +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 arr + return a } first := nbr[0] if len(nbr) == 1 { if first < 0 { - first = len(arr) + first + first = len(a) + first if first < 0 { - return arr + return a } } - return arr[first:] - } else { - second := nbr[1] - - first = ifNegative(arr, first) - second = ifNegative(arr, second) - - if first > second { - return []string{} - } - - return arr[first:second] + return a[first:] } -} + second := nbr[1] -func ifNegative(arr []string, n int) int { - if n < 0 { - n = len(arr) + n - } + first = ifNegative(a, first) + second = ifNegative(a, second) - if n < 0 { - n = 0 - } else if n > len(arr) { - n = len(arr) + if first > second { + return nil } - return n + return a[first:second] } diff --git a/tests/go/solutions/sliceprog/main.go b/tests/go/solutions/sliceprog/main.go index c328d3a1..66cdf796 100644 --- a/tests/go/solutions/sliceprog/main.go +++ b/tests/go/solutions/sliceprog/main.go @@ -1,46 +1,45 @@ package main -func main() { +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(arr []string, nbr ...int) []string { +func Slice(a []string, nbr ...int) []string { if len(nbr) == 0 { - return arr + return a } first := nbr[0] if len(nbr) == 1 { if first < 0 { - first = len(arr) + first + first = len(a) + first if first < 0 { - return arr + return a } } - return arr[first:] - } else { - second := nbr[1] - - first = ifNegative(arr, first) - second = ifNegative(arr, second) - - if first > second { - return []string{} - } - - return arr[first:second] + return a[first:] } -} + second := nbr[1] -func ifNegative(arr []string, n int) int { - if n < 0 { - n = len(arr) + n - } + first = ifNegative(a, first) + second = ifNegative(a, second) - if n < 0 { - n = 0 - } else if n > len(arr) { - n = len(arr) + if first > second { + return nil } - return n + return a[first:second] +} + +func main() { } diff --git a/tests/go/solutions/sortintegertable.go b/tests/go/solutions/sortintegertable.go index 4020d486..d4e8076b 100644 --- a/tests/go/solutions/sortintegertable.go +++ b/tests/go/solutions/sortintegertable.go @@ -1,9 +1,7 @@ package solutions -import ( - "sort" -) +import "sort" -func SortIntegerTable(table []int) { - sort.Ints(table) +func SortIntegerTable(a []int) { + sort.Ints(a) } diff --git a/tests/go/solutions/sortlistinsert.go b/tests/go/solutions/sortlistinsert.go index d5afcbe4..1342a7ed 100644 --- a/tests/go/solutions/sortlistinsert.go +++ b/tests/go/solutions/sortlistinsert.go @@ -1,6 +1,6 @@ package solutions -//structures for the linked lists +// structures for the linked lists type NodeI struct { Data int Next *NodeI diff --git a/tests/go/solutions/sortll.go b/tests/go/solutions/sortll.go index 5319ad86..090a0bff 100644 --- a/tests/go/solutions/sortll.go +++ b/tests/go/solutions/sortll.go @@ -1,12 +1,5 @@ package solutions -//This solution is the comparing file of the staff -// Because the solution is a function, -// -//1) here the package is solutions -//2) it does not need an empty func main(){} -//3) its location is 1 level below the folder of the nauuo_test.go file - func Sortll(node *NodeAddL) *NodeAddL { if node == nil { return node diff --git a/tests/go/solutions/sortll/main.go b/tests/go/solutions/sortll/main.go index 58cd1105..bac6ae9e 100644 --- a/tests/go/solutions/sortll/main.go +++ b/tests/go/solutions/sortll/main.go @@ -1,11 +1,5 @@ package main -//This solution is the placeholder of the student solution -// for an exercise in the exam asking for a Function -//Remember the disclaimer!!!! -//1) here the package is main -//2) It does need an empty func main(){} - type NodeAddL struct { Next *NodeAddL Num int @@ -41,5 +35,6 @@ func Sortll(node *NodeAddL) *NodeAddL { } return node } + func main() { } diff --git a/tests/go/solutions/sortll/sortll_test.go b/tests/go/solutions/sortll/sortll_test.go index a13caa29..a8ac4f2a 100644 --- a/tests/go/solutions/sortll/sortll_test.go +++ b/tests/go/solutions/sortll/sortll_test.go @@ -1,11 +1,9 @@ package main import ( - "testing" - "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) type stuNode = NodeAddL @@ -59,92 +57,35 @@ func solListToNum(node *solNode) int { return n } -func compareNodes(t *testing.T, stuResult *stuNode, solResult *solNode, num1 int) { +func compareNodes(stuResult *stuNode, solResult *solNode, num1 int) { if stuResult == nil && solResult == nil { - } else if stuResult != nil && solResult == nil { + return + } + if stuResult != nil && solResult == nil { stuNum := stuListToNum(stuResult) - t.Fatalf("\nSortll(%d) == %v instead of %v\n\n", + z01.Fatalf("\nSortll(%d) == %v instead of %v\n\n", num1, stuNum, "") - } else if stuResult == nil && solResult != nil { + } + if stuResult == nil && solResult != nil { solNum := solListToNum(solResult) - t.Fatalf("\nSortll(%d) == %v instead of %v\n\n", + z01.Fatalf("\nSortll(%d) == %v instead of %v\n\n", num1, "", solNum) - } else { - stuNum := stuListToNum(stuResult) - solNum := solListToNum(solResult) - if stuNum != solNum { - t.Fatalf("\nSortll(%d) == %v instead of %v\n\n", - num1, stuNum, solNum) - } } -} - -func TestSortll(t *testing.T) { - // Declaration of the node that is going to take the group of arguments that are going to - // inputed during each iteration of a Challenge between the student and the staff solution. - // (note: a node is not always necessary but in this case it makes the writing of the test easier) - - type node struct { - num1 int - } - - // Declaration of an empty array of type node{} - // note that in this case this is the easiest type of table to declare - // but a table can be of any other relevant type, (for example []string{}, []int{} if it - // were a single string tested or a single int) - - table := []node{} - // Initial filling of that array with the values I see in the examples of the subject - - table = append(table, - node{123456}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library - - for i := 0; i < 15; i++ { - value := node{ - num1: z01.RandIntBetween(0, 1000000000), - //this z01.RandIntBetween function allows the randomization of - //the int for each value in a desired range. - //Note that they are many others of those functions for other types of data - //Do not hesitate to have a look at all of them https://github.com/01-edu/z01 - } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - table = append(table, value) + stuNum := stuListToNum(stuResult) + solNum := solListToNum(solResult) + if stuNum != solNum { + z01.Fatalf("\nSortll(%d) == %v instead of %v\n\n", + num1, stuNum, solNum) } +} - //The table with 4 specific exercises and 15 randoms is now ready to be "challenged" - //Because the exercise asks for a function we are now using the Challenge function (this function would - // be the ChallengeMainExam function) - +func main() { + table := []int{123456} + table = append(table, z01.MultRandIntBetween(0, 1000000000)...) for _, arg := range table { - stuResult := Sortll(stuNumToList(arg.num1)) - solResult := solutions.Sortll(solNumToList(arg.num1)) + stuResult := Sortll(stuNumToList(arg)) + solResult := solutions.Sortll(solNumToList(arg)) - compareNodes(t, stuResult, solResult, arg.num1) + compareNodes(stuResult, solResult, arg) } - - // the z01.Challenge function is here applied to each argument of the table. It musts contains: - // 1) first, the t argument from the T structure imported from the package "testing" - // - // 2) second, the function from the student, in this case Nauuo - //(this disapears in the ChallengeMainExam function) - // 3) third, the function from the staff, in this case solutions.Nauuo - //(this disapears as well in the ChallengeMainExam function) - // 4) all the arguments to be tested, in this case it is the plus, minus and rand from each structure, - // notice that they are accessed with arg. (the arg notation comes from the way it was name in the - // range loop over the table) - - // Now that this is done. re-read the quickReadme (the test your test recap) and apply all the commands - // and intructions. We strongly advise to check that your error messages matches your subject. - // and that you ask a colleague to double check. - - //FINAL STEP: - // When both are satisfied with the coherence between the subject and its tests. The code can be commited - // and redeployed by the team-01. - // We then advised the staff team to test the new exercise invidually with their current build of the exam } diff --git a/tests/go/solutions/sortparams/sortparams.go b/tests/go/solutions/sortparams/sortparams.go index 7f805b5f..8f6fed34 100644 --- a/tests/go/solutions/sortparams/sortparams.go +++ b/tests/go/solutions/sortparams/sortparams.go @@ -8,7 +8,7 @@ import ( func main() { args := os.Args[1:] - sort.Sort(sort.StringSlice(args)) + sort.Strings(args) for _, v := range args { fmt.Println(v) } diff --git a/tests/go/solutions/sortwordarr.go b/tests/go/solutions/sortwordarr.go index 2414c181..30420909 100644 --- a/tests/go/solutions/sortwordarr.go +++ b/tests/go/solutions/sortwordarr.go @@ -1,9 +1,7 @@ package solutions -import ( - "sort" -) +import "sort" -func SortWordArr(array []string) { - sort.Sort(sort.StringSlice(array)) +func SortWordArr(a []string) { + sort.Strings(a) } diff --git a/tests/go/solutions/sortwordarrprog/main.go b/tests/go/solutions/sortwordarrprog/main.go index 756d1f1f..bb7fb236 100644 --- a/tests/go/solutions/sortwordarrprog/main.go +++ b/tests/go/solutions/sortwordarrprog/main.go @@ -1,11 +1,9 @@ package main -import ( - "sort" -) +import "sort" -func SortWordArr(array []string) { - sort.Sort(sort.StringSlice(array)) +func SortWordArr(a []string) { + sort.Strings(a) } func main() { diff --git a/tests/go/solutions/sortwordarrprog/sortwordarrprog_test.go b/tests/go/solutions/sortwordarrprog/sortwordarrprog_test.go index 51634beb..e7bde16d 100644 --- a/tests/go/solutions/sortwordarrprog/sortwordarrprog_test.go +++ b/tests/go/solutions/sortwordarrprog/sortwordarrprog_test.go @@ -2,26 +2,23 @@ package main import ( "reflect" - "testing" "github.com/01-edu/z01" solutions "../../solutions" ) -func TestSortWordArrProg(t *testing.T) { - var table [][]string - - table = append(table, []string{"a", "A", "1", "b", "B", "2", "c", "C", "3"}) +func main() { + table := [][]string{{"a", "A", "1", "b", "B", "2", "c", "C", "3"}} for i := 0; i < 15; i++ { table = append(table, z01.MultRandWords()) } for _, org := range table { - //copy for using the solution function + // copy for using the solution function cp_sol := make([]string, len(org)) - //copy for using the student function + // copy for using the student function cp_stu := make([]string, len(org)) copy(cp_sol, org) @@ -31,7 +28,7 @@ func TestSortWordArrProg(t *testing.T) { SortWordArr(cp_stu) if !reflect.DeepEqual(cp_stu, cp_sol) { - t.Fatalf("%s(%v) == %v instead of %v\n", + z01.Fatalf("%s(%v) == %v instead of %v\n", "SortWordArr", org, cp_stu, diff --git a/tests/go/solutions/split.go b/tests/go/solutions/split.go index cf354b5e..f98fe2f3 100644 --- a/tests/go/solutions/split.go +++ b/tests/go/solutions/split.go @@ -1,9 +1,7 @@ package solutions -import ( - "strings" -) +import "strings" -func Split(str, charset string) []string { - return strings.Split(str, charset) +func Split(s, sep string) []string { + return strings.Split(s, sep) } diff --git a/tests/go/solutions/splitprog/main.go b/tests/go/solutions/splitprog/main.go index 1304b863..1ed9c093 100644 --- a/tests/go/solutions/splitprog/main.go +++ b/tests/go/solutions/splitprog/main.go @@ -1,11 +1,9 @@ package main -import ( - "strings" -) +import "strings" -func Split(str, charset string) []string { - return strings.Split(str, charset) +func Split(s, sep string) []string { + return strings.Split(s, sep) } func main() { diff --git a/tests/go/solutions/splitprog/splitprog_test.go b/tests/go/solutions/splitprog/splitprog_test.go index a7bbb5ad..1993401e 100644 --- a/tests/go/solutions/splitprog/splitprog_test.go +++ b/tests/go/solutions/splitprog/splitprog_test.go @@ -10,21 +10,23 @@ import ( ) func main() { - separators := []string{"!=HA=!", + separators := []string{ + "!=HA=!", "!==!", " ", "|=choumi=|", "|<=>|", z01.RandStr(3, z01.RuneRange('A', 'Z')), "<<==123==>>", - "[<>abc<>]"} + "[<>abc<>]", + } type node struct { str string sep string } table := []node{} - //15 random slice of strings + // 15 random slice of strings for i := 0; i < 15; i++ { separator := separators[rand.Intn(len(separators))] diff --git a/tests/go/solutions/splitwhitespaces.go b/tests/go/solutions/splitwhitespaces.go index 1c765aee..f2b1728d 100644 --- a/tests/go/solutions/splitwhitespaces.go +++ b/tests/go/solutions/splitwhitespaces.go @@ -1,20 +1,7 @@ package solutions -func SplitWhiteSpaces(str string) []string { - answer := []string{} - word := "" - for _, r := range str { - if isSeparator(r) { - if word != "" { - answer = append(answer, word) - word = "" - } - } else { - word = word + string(r) - } - } - if word != "" { - answer = append(answer, word) - } - return answer +import "strings" + +func SplitWhiteSpaces(s string) []string { + return strings.Fields(s) } diff --git a/tests/go/solutions/sqrt.go b/tests/go/solutions/sqrt.go index b229bef1..615e5b6d 100644 --- a/tests/go/solutions/sqrt.go +++ b/tests/go/solutions/sqrt.go @@ -1,8 +1,6 @@ package solutions -import ( - "math" -) +import "math" func Sqrt(value int) int { sr := math.Sqrt(float64(value)) diff --git a/tests/go/solutions/strlenprog/strlenprog_test.go b/tests/go/solutions/strlenprog/strlenprog_test.go index c7f76aff..07d366a8 100644 --- a/tests/go/solutions/strlenprog/strlenprog_test.go +++ b/tests/go/solutions/strlenprog/strlenprog_test.go @@ -1,8 +1,9 @@ package main import ( - solutions "../../solutions" "github.com/01-edu/z01" + + solutions "../../solutions" ) func main() { diff --git a/tests/go/solutions/strrevprog/test_strrevprog.go b/tests/go/solutions/strrevprog/test_strrevprog.go index 19c9fe5e..fde5fa92 100644 --- a/tests/go/solutions/strrevprog/test_strrevprog.go +++ b/tests/go/solutions/strrevprog/test_strrevprog.go @@ -1,12 +1,9 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - table := append( - z01.MultRandASCII(), + table := append(z01.MultRandASCII(), "Hello!", "Bonjour!", "Hola!", diff --git a/tests/go/solutions/swap.go b/tests/go/solutions/swap.go index 46355761..00bda0ce 100644 --- a/tests/go/solutions/swap.go +++ b/tests/go/solutions/swap.go @@ -1,7 +1,5 @@ package solutions func Swap(a, b *int) { - temp := *a - *a = *b - *b = temp + *a, *b = *b, *a } diff --git a/tests/go/solutions/swapbits/swapbits_test.go b/tests/go/solutions/swapbits/swapbits_test.go index a41655e9..3fe248e4 100644 --- a/tests/go/solutions/swapbits/swapbits_test.go +++ b/tests/go/solutions/swapbits/swapbits_test.go @@ -2,19 +2,18 @@ package main import ( "reflect" - "testing" "github.com/01-edu/z01" solutions "../../solutions" ) -func challengeBytes(t *testing.T, fn1, fn2 interface{}, args ...interface{}) { +func challengeBytes(fn1, fn2 interface{}, args ...interface{}) { st1 := z01.Monitor(fn1, args) st2 := z01.Monitor(fn2, args) if !reflect.DeepEqual(st1.Results, st2.Results) { - t.Fatalf("%s(%08b) == %08b instead of %08b\n", - z01.NameOfFunc(fn1), + z01.Fatalf("%s(%08b) == %08b instead of %08b\n", + "SwapBits", args[0].(byte), st1.Results[0].(byte), st2.Results[0].(byte), @@ -22,7 +21,7 @@ func challengeBytes(t *testing.T, fn1, fn2 interface{}, args ...interface{}) { } } -func TestSwapBits(t *testing.T) { +func main() { args := []byte{0x24, 0x14, 0x11, 0x22, 0xd2, 0x15, 0xff, 0x0, 0x35, 0x58, 0x43} for i := 0; i < 10; i++ { @@ -31,6 +30,6 @@ func TestSwapBits(t *testing.T) { } for _, v := range args { - challengeBytes(t, SwapBits, solutions.SwapBits, v) + challengeBytes(SwapBits, solutions.SwapBits, v) } } diff --git a/tests/go/solutions/swapprog/swapprog_test.go b/tests/go/solutions/swapprog/swapprog_test.go index 477256e8..c3751e47 100644 --- a/tests/go/solutions/swapprog/swapprog_test.go +++ b/tests/go/solutions/swapprog/swapprog_test.go @@ -1,12 +1,8 @@ package main -import ( - "testing" +import "github.com/01-edu/z01" - "github.com/01-edu/z01" -) - -func TestSwapProg(t *testing.T) { +func main() { i := 0 for i < 30 { a := z01.RandInt() @@ -15,10 +11,10 @@ func TestSwapProg(t *testing.T) { bCopy := b Swap(&a, &b) if a != bCopy { - t.Fatalf("Swap(%d, %d), a == %d instead of %d", aCopy, bCopy, a, bCopy) + z01.Fatalf("Swap(%d, %d), a == %d instead of %d", aCopy, bCopy, a, bCopy) } if b != aCopy { - t.Fatalf("Swap(%d, %d), b == %d instead of %d", aCopy, bCopy, b, aCopy) + z01.Fatalf("Swap(%d, %d), b == %d instead of %d", aCopy, bCopy, b, aCopy) } i++ } diff --git a/tests/go/solutions/sweetproblem/sweetproblem_test.go b/tests/go/solutions/sweetproblem/sweetproblem_test.go index 089ee7ed..5a3b7076 100644 --- a/tests/go/solutions/sweetproblem/sweetproblem_test.go +++ b/tests/go/solutions/sweetproblem/sweetproblem_test.go @@ -3,7 +3,7 @@ package main import ( "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) func main() { @@ -14,7 +14,6 @@ func main() { } table := []node{} - // Initial filling of that array with the values I see in the examples of the subject table = append(table, node{50, 43, 20}, @@ -32,25 +31,14 @@ func main() { node{5, 9, 2}, ) - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library - for i := 0; i < 15; i++ { value := node{ red: z01.RandIntBetween(0, 30), green: z01.RandIntBetween(0, 30), blue: z01.RandIntBetween(0, 30), } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. table = append(table, value) } - - //The table with 4 specific exercises and 15 randoms is now ready to be "challenged" - //Because the exercise asks for a function we are now using the Challenge function (this function would - // be the ChallengeMainExam function) - for _, arg := range table { z01.Challenge("SweetProblem", Sweetproblem, solutions.Sweetproblem, arg.red, arg.green, arg.blue) } diff --git a/tests/go/solutions/switchcase/main.go b/tests/go/solutions/switchcase/main.go index 991de3cc..f425f0d9 100644 --- a/tests/go/solutions/switchcase/main.go +++ b/tests/go/solutions/switchcase/main.go @@ -3,27 +3,19 @@ package main import ( "fmt" "os" - - "github.com/01-edu/z01" + "unicode" ) func main() { - if len(os.Args) != 2 { - fmt.Println() - } else { - array := []byte(os.Args[1]) - - for i := 0; i < len(array); i++ { - if array[i] >= 'A' && array[i] <= 'Z' { - array[i] += 32 - z01.PrintRune(rune(array[i])) - } else if array[i] >= 'a' && array[i] <= 'z' { - array[i] -= 32 - z01.PrintRune(rune(array[i])) - } else { - z01.PrintRune(rune(array[i])) + if len(os.Args) == 2 { + s := os.Args[1] + for i, r := range s { + if unicode.IsLower(r) { + s[i] = unicode.ToUpper(r) + } else if unicode.IsUpper(r) { + s[i] = unicode.ToLower(r) } } - z01.PrintRune('\n') + fmt.Println(s) } } diff --git a/tests/go/solutions/switchcase/test_switchcase.go b/tests/go/solutions/switchcase/test_switchcase.go index 1377f254..03a8041b 100644 --- a/tests/go/solutions/switchcase/test_switchcase.go +++ b/tests/go/solutions/switchcase/test_switchcase.go @@ -1,14 +1,13 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - table := append(z01.MultRandWords(), " ") - table = append(table, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") - table = append(table, "abcdefghi jklmnop qrstuvwxyz ABCDEFGHI JKLMNOPQR STUVWXYZ ! ") - + table := append(z01.MultRandWords(), + " ", + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + "abcdefghi jklmnop qrstuvwxyz ABCDEFGHI JKLMNOPQR STUVWXYZ ! ", + ) for _, s := range table { z01.ChallengeMain("switchcase", s) } diff --git a/tests/go/solutions/tetrisoptimizer/solver.go b/tests/go/solutions/tetrisoptimizer/solver.go index 8d02cb3b..cee3404d 100644 --- a/tests/go/solutions/tetrisoptimizer/solver.go +++ b/tests/go/solutions/tetrisoptimizer/solver.go @@ -1,33 +1,33 @@ package main -func recursion(b board, array []tetrimino, idx int) bool { - if idx == len(array) { +func recursion(b board, a []tetrimino, idx int) bool { + if idx == len(a) { return true } for i := range b { for j := range b[i] { - if !b.check(i, j, array[idx]) { + if !b.check(i, j, a[idx]) { continue } - b.put(i, j, idx, array[idx]) - if recursion(b, array, idx+1) { + b.put(i, j, idx, a[idx]) + if recursion(b, a, idx+1) { return true } - b.remove(i, j, array[idx]) + b.remove(i, j, a[idx]) } } return false } -func solve(array []tetrimino) board { +func solve(a []tetrimino) board { square := 2 - for square*square < len(array)*4 { + for square*square < len(a)*4 { square++ } for { b := makeBoard(square) square++ - if !recursion(b, array, 0) { + if !recursion(b, a, 0) { continue } return b diff --git a/tests/go/solutions/tolower.go b/tests/go/solutions/tolower.go index f0ea8728..c447f826 100644 --- a/tests/go/solutions/tolower.go +++ b/tests/go/solutions/tolower.go @@ -1,10 +1,7 @@ package solutions -import ( - "strings" -) +import "strings" func ToLower(s string) string { - s = strings.ToLower(s) - return s + return strings.ToLower(s) } diff --git a/tests/go/solutions/toupper.go b/tests/go/solutions/toupper.go index 51c23add..7f0de7d3 100644 --- a/tests/go/solutions/toupper.go +++ b/tests/go/solutions/toupper.go @@ -1,10 +1,7 @@ package solutions -import ( - "strings" -) +import "strings" func ToUpper(s string) string { - s = strings.ToUpper(s) - return s + return strings.ToUpper(s) } diff --git a/tests/go/solutions/twosum/twosum_test.go b/tests/go/solutions/twosum/twosum_test.go index 80fa1eb5..98e1a1bb 100644 --- a/tests/go/solutions/twosum/twosum_test.go +++ b/tests/go/solutions/twosum/twosum_test.go @@ -3,8 +3,9 @@ package main import ( "math/rand" - solutions "../../solutions" "github.com/01-edu/z01" + + solutions "../../solutions" ) func main() { diff --git a/tests/go/solutions/uniqueoccurences/test_uniqueoccurences.go b/tests/go/solutions/uniqueoccurences/test_uniqueoccurences.go index 685edf20..e20de06c 100644 --- a/tests/go/solutions/uniqueoccurences/test_uniqueoccurences.go +++ b/tests/go/solutions/uniqueoccurences/test_uniqueoccurences.go @@ -1,22 +1,17 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - table := []string{} - - table = append(table, + table := []string{ "abbaac", "ab", "abcacccazb", "", - ) + } for i := 0; i < 15; i++ { - value := z01.RandStr(z01.RandIntBetween(5, 10), "qwertyuiopasdfghjklzxcvbnm") - table = append(table, value) + table = append(table, z01.RandStr(z01.RandIntBetween(5, 10), z01.Lower)) } for _, arg := range table { diff --git a/tests/go/solutions/unmatch.go b/tests/go/solutions/unmatch.go index 04877f67..14a4fc85 100644 --- a/tests/go/solutions/unmatch.go +++ b/tests/go/solutions/unmatch.go @@ -1,8 +1,8 @@ package solutions -//Returns the element of the slice that doesn't have a correspondant pair +// Returns the element of the slice that doesn't have a correspondant pair func Unmatch(arr []int) int { - //count the number of repetitions of each value + // count the number of repetitions of each value var quant int for _, el := range arr { quant = 0 @@ -11,7 +11,7 @@ func Unmatch(arr []int) int { quant++ } } - //if the number of repetitions is odd return that element + // if the number of repetitions is odd return that element if quant%2 != 0 { return el } diff --git a/tests/go/solutions/volumechanger/volumechanger_test.go b/tests/go/solutions/volumechanger/volumechanger_test.go index 72645da4..42d09a12 100644 --- a/tests/go/solutions/volumechanger/volumechanger_test.go +++ b/tests/go/solutions/volumechanger/volumechanger_test.go @@ -3,43 +3,23 @@ package main import ( "github.com/01-edu/z01" - solutions "../../solutions" // This line is not necessary when testing an exercise with a program + solutions "../../solutions" ) func main() { - type node struct { - init int - fin int + table := [][2]int{ + {50, 43}, + {13, 13}, + {10, 9}, + {5, 9}, } - table := []node{} - // Initial filling of that array with the values I see in the examples of the subject - - table = append(table, - node{50, 43}, - node{13, 13}, - node{10, 9}, - node{5, 9}, - ) - - // If we were to leave the table as it is, a student could just do a program with 4 ifs and get - // "around" the goal of the exercise. We are now going to add 15 random tests using the z01 testing library - for i := 0; i < 15; i++ { - value := node{ - init: z01.RandIntBetween(0, 30), - fin: z01.RandIntBetween(0, 100), - } - - //Once the random node created, this iteration is added to the earlier declared table - //along with the 4 specific examples taken from the examples of the readme. - table = append(table, value) + table = append(table, [2]int{ + z01.RandIntBetween(0, 30), + z01.RandIntBetween(0, 100), + }) } - - //The table with 4 specific exercises and 15 randoms is now ready to be "challenged" - //Because the exercise asks for a function we are now using the Challenge function (this function would - // be the ChallengeMainExam function) - for _, arg := range table { - z01.Challenge("Volumechanger", Volumechanger, solutions.Volumechanger, arg.init, arg.fin) + z01.Challenge("Volumechanger", Volumechanger, solutions.Volumechanger, arg[0], arg[1]) } } diff --git a/tests/go/solutions/ztail/main.go b/tests/go/solutions/ztail/main.go index 9a830083..58163174 100644 --- a/tests/go/solutions/ztail/main.go +++ b/tests/go/solutions/ztail/main.go @@ -60,7 +60,7 @@ func main() { printName := len(files) > 1 - //open files for reading only + // open files for reading only for j, f := range files { fi, err := os.Open(f) if err != nil { diff --git a/tests/go/sortedlistmerge_test.go b/tests/go/sortedlistmerge_test.go index 06978f3d..2d501647 100644 --- a/tests/go/sortedlistmerge_test.go +++ b/tests/go/sortedlistmerge_test.go @@ -1,8 +1,7 @@ -package student_test +package main import ( "strconv" - "testing" solution "./solutions" student "./student" @@ -49,63 +48,61 @@ func nodePushBackListInt13(l *NodeI13, l1 *NodeIS13, data int) { } } -func TestSortedListMerge(t *testing.T) { - var link *NodeI13 +func main() { + var link1 *NodeI13 var link2 *NodeI13 - var linkTest *NodeIS13 + var linkTest1 *NodeIS13 var linkTest2 *NodeIS13 type nodeTest struct { - data []int + data1 []int data2 []int } - table := []nodeTest{} + table := []nodeTest{{ + data1: []int{}, + }} - table = append(table, - nodeTest{ - data: []int{}, - }) for i := 0; i < 3; i++ { val := nodeTest{ - data: z01.MultRandInt(), + data1: z01.MultRandInt(), data2: z01.MultRandInt(), } table = append(table, val) } table = append(table, nodeTest{ - data: []int{3, 5, 7}, + data1: []int{3, 5, 7}, data2: []int{1, -2, 4, 6}, }, ) for _, arg := range table { - for i := 0; i < len(arg.data); i++ { - nodePushBackListInt13(link, linkTest, arg.data[i]) + for i := 0; i < len(arg.data1); i++ { + nodePushBackListInt13(link1, linkTest1, arg.data1[i]) } for i := 0; i < len(arg.data2); i++ { nodePushBackListInt13(link2, linkTest2, arg.data2[i]) } - link = student.ListSort(link) + link1 = student.ListSort(link1) link2 = student.ListSort(link2) - linkTest = solution.ListSort(linkTest) + linkTest1 = solution.ListSort(linkTest1) linkTest2 = solution.ListSort(linkTest2) - aux := student.SortedListMerge(link, link2) - aux2 := solution.SortedListMerge(linkTest, linkTest2) + aux1 := student.SortedListMerge(link1, link2) + aux2 := solution.SortedListMerge(linkTest1, linkTest2) - if aux == nil && aux2 == nil { - } else if aux != nil && aux2 == nil { - t.Fatalf("\nstudent merged lists:%s\nmerged lists:%s\n\nSortListMerge() == %v instead of %v\n\n", - printListStudent1(aux), solution.PrintList(aux2), aux, aux2) - } else if aux.Data != aux2.Data { - t.Fatalf("\nstudent merged lists:%s\nmerged lists:%s\n\nSortListMerge() == %v instead of %v\n\n", - printListStudent1(aux), solution.PrintList(aux2), aux, aux2) + if aux1 == nil && aux2 == nil { + } else if aux1 != nil && aux2 == nil { + z01.Fatalf("\nstudent merged lists:%s\nmerged lists:%s\n\nSortListMerge() == %v instead of %v\n\n", + printListStudent1(aux1), solution.PrintList(aux2), aux1, aux2) + } else if aux1.Data != aux2.Data { + z01.Fatalf("\nstudent merged lists:%s\nmerged lists:%s\n\nSortListMerge() == %v instead of %v\n\n", + printListStudent1(aux1), solution.PrintList(aux2), aux1, aux2) } - link = &NodeI13{} + link1 = &NodeI13{} link2 = &NodeI13{} - linkTest = &NodeIS13{} + linkTest1 = &NodeIS13{} linkTest2 = &NodeIS13{} } } diff --git a/tests/go/sortintegertable_test.go b/tests/go/sortintegertable_test.go index 6a3730f6..53bef5e2 100644 --- a/tests/go/sortintegertable_test.go +++ b/tests/go/sortintegertable_test.go @@ -1,8 +1,7 @@ -package student_test +package main import ( "reflect" - "testing" "github.com/01-edu/z01" @@ -10,21 +9,21 @@ import ( student "./student" ) -func TestSortIntegerTable(t *testing.T) { +func main() { i := 0 for i < z01.SliceLen { - table := z01.MultRandIntBetween(-100, 100) + table1 := z01.MultRandIntBetween(-100, 100) - tableCopyBefore := make([]int, len(table)) - copy(tableCopyBefore, table) + tableCopyBefore := make([]int, len(table1)) + copy(tableCopyBefore, table1) - table2 := make([]int, len(table)) - copy(table2, table) + table2 := make([]int, len(table1)) + copy(table2, table1) - student.SortIntegerTable(table) + student.SortIntegerTable(table1) solutions.SortIntegerTable(table2) - if !reflect.DeepEqual(table, table2) { - t.Fatalf("SortIntegerTable(%v), table == %v instead of %v ", tableCopyBefore, table, table2) + if !reflect.DeepEqual(table1, table2) { + z01.Fatalf("SortIntegerTable(%v), table1 == %v instead of %v ", tableCopyBefore, table1, table2) } i++ } diff --git a/tests/go/sortlist_test.go b/tests/go/sortlist_test.go index 70a683ea..a88695aa 100644 --- a/tests/go/sortlist_test.go +++ b/tests/go/sortlist_test.go @@ -1,34 +1,32 @@ -package student_test +package main import ( "strconv" - "testing" + + "github.com/01-edu/z01" solution "./solutions" student "./student" - "github.com/01-edu/z01" ) -func listToString4(n *solution.Nodelist) string { - var res string +func listToString4(n *solution.Nodelist) (res string) { it := n for it != nil { res += strconv.Itoa(it.Data) + "-> " it = it.Next } res += "" - return res + return } -func listToStringStu4(n *student.Nodelist) string { - var res string +func listToStringStu4(n *student.Nodelist) (res string) { it := n for it != nil { res += strconv.Itoa(it.Data) + "-> " it = it.Next } res += "" - return res + return } func ascending(a, b int) bool { @@ -69,21 +67,21 @@ func insertNodeListStudent(l1 *student.Nodelist, data int) *student.Nodelist { return it } -func compare(t *testing.T, l *solution.Nodelist, l1 *student.Nodelist, f func(a, b int) bool) { +func compare(l2 *solution.Nodelist, l1 *student.Nodelist, f func(a, b int) bool) { cmp := solution.GetName(f) - for l1 != nil && l != nil { - if l1.Data != l.Data { - t.Fatalf("\nstudent list:%s\nlist:%s\nfunction cmp:%s\n\nSortListInsert() == %v instead of %v\n\n", - listToStringStu4(l1), listToString4(l), cmp, l1.Data, l.Data) + for l1 != nil && l2 != nil { + if l1.Data != l2.Data { + z01.Fatalf("\nstudent list:%s\nlist:%s\nfunction cmp:%s\n\nSortListInsert() == %v instead of %v\n\n", + listToStringStu4(l1), listToString4(l2), cmp, l1.Data, l2.Data) return } l1 = l1.Next - l = l.Next + l2 = l2.Next } } -func TestSortList(t *testing.T) { +func main() { var linkSolutions *solution.Nodelist var linkStudent *student.Nodelist @@ -95,11 +93,10 @@ func TestSortList(t *testing.T) { table := []nodeTest{} for i := 0; i < 4; i++ { - val := nodeTest{ + table = append(table, nodeTest{ data: z01.MultRandIntBetween(1, 1234), functions: []func(a, b int) bool{ascending, descending}, - } - table = append(table, val) + }) } table = append(table, @@ -109,16 +106,15 @@ func TestSortList(t *testing.T) { }) for _, arg := range table { - for i := 0; i < len(arg.data); i++ { - linkStudent = insertNodeListStudent(linkStudent, arg.data[i]) - linkSolutions = insertNodeListSolution(linkSolutions, arg.data[i]) + for _, item := range arg.data { + linkStudent = insertNodeListStudent(linkStudent, item) + linkSolutions = insertNodeListSolution(linkSolutions, item) } - for i := 0; i < len(arg.functions); i++ { - studentResult := student.SortList(linkStudent, arg.functions[i]) - solutionResult := solution.SortList(linkSolutions, arg.functions[i]) - - compare(t, solutionResult, studentResult, arg.functions[i]) + for _, fn := range arg.functions { + studentResult := student.SortList(linkStudent, fn) + solutionResult := solution.SortList(linkSolutions, fn) + compare(solutionResult, studentResult, fn) } linkSolutions = &solution.Nodelist{} linkStudent = &student.Nodelist{} diff --git a/tests/go/sortlistinsert_test.go b/tests/go/sortlistinsert_test.go index dc5c6106..6b737612 100644 --- a/tests/go/sortlistinsert_test.go +++ b/tests/go/sortlistinsert_test.go @@ -1,17 +1,16 @@ -package student_test +package main import ( "strconv" - "testing" - solution "./solutions" + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) type NodeI14 = student.NodeI -type NodeIS14 = solution.NodeI +type NodeIS14 = solutions.NodeI func listToStringStu3(n *NodeI14) string { var res string @@ -52,44 +51,66 @@ func nodepushback2(l *NodeIS14, data int) *NodeIS14 { return l } -func comparFuncNodeInt14(l *NodeI14, l1 *NodeIS14, t *testing.T, data []int) { - for l != nil || l1 != nil { - if (l == nil && l1 != nil) || (l != nil && l1 == nil) { - t.Fatalf("\ndata used to insert: %d\nstudent list:%s\nlist:%s\n\nSortListInsert() == %v instead of %v\n\n", - data, listToStringStu3(l), solution.PrintList(l1), l, l1) - return - } else if l.Data != l1.Data { - t.Fatalf("\ndata used to insert: %d\nstudent list:%s\nlist:%s\n\nSortListInsert() == %v instead of %v\n\n", - data, listToStringStu3(l), solution.PrintList(l1), l.Data, l1.Data) - return +func comparFuncNodeInt14(l1 *NodeI14, l2 *NodeIS14, data []int) { + for l1 != nil || l2 != nil { + if (l1 == nil && l2 != nil) || (l1 != nil && l2 == nil) { + z01.Fatalf("\ndata used to insert: %d\nstudent list:%s\nlist:%s\n\nSortListInsert() == %v instead of %v\n\n", + data, listToStringStu3(l1), solutions.PrintList(l2), l1, l2) + } + if l1.Data != l2.Data { + z01.Fatalf("\ndata used to insert: %d\nstudent list:%s\nlist:%s\n\nSortListInsert() == %v instead of %v\n\n", + data, listToStringStu3(l1), solutions.PrintList(l2), l1.Data, l2.Data) } - l = l.Next l1 = l1.Next + l2 = l2.Next + } +} + +func move(l *NodeI14) *NodeI14 { + p := l + n := l.Next + ret := n + + for n != nil && l.Data > n.Data { + p = n + n = n.Next } + p.Next = l + l.Next = n + return ret } -// exercise 16 -func TestSortListInsert(t *testing.T) { - var link *NodeI14 +func sortStudentsList(l *NodeI14) *NodeI14 { + head := l + if head == nil { + return nil + } + head.Next = sortStudentsList(head.Next) + + if head.Next != nil && head.Data > head.Next.Data { + head = move(head) + } + return head +} + +func main() { + var link1 *NodeI14 var link2 *NodeIS14 type nodeTest struct { data []int data_ref []int } - table := []nodeTest{} + table := []nodeTest{{ + data: []int{}, + data_ref: []int{}, + }} - table = append(table, - nodeTest{ - data: []int{}, - data_ref: []int{}, - }) for i := 0; i < 2; i++ { - val := nodeTest{ + table = append(table, nodeTest{ data: z01.MultRandInt(), data_ref: z01.MultRandInt(), - } - table = append(table, val) + }) } table = append(table, nodeTest{ @@ -98,48 +119,21 @@ func TestSortListInsert(t *testing.T) { }, ) for _, arg := range table { - for i := 0; i < len(arg.data); i++ { - link2 = nodepushback2(link2, arg.data[i]) - link = nodepushback1(link, arg.data[i]) + for _, item := range arg.data { + link2 = nodepushback2(link2, item) + link1 = nodepushback1(link1, item) } link2 = solutions.ListSort(link2) - link = sortStudentsList(link) + link1 = sortStudentsList(link1) - for i := 0; i < len(arg.data_ref); i++ { - link2 = solution.SortListInsert(link2, arg.data_ref[i]) - link = student.SortListInsert(link, arg.data_ref[i]) + for _, item := range arg.data_ref { + link2 = solutions.SortListInsert(link2, item) + link1 = student.SortListInsert(link1, item) } - comparFuncNodeInt14(link, link2, t, arg.data_ref) - link = &NodeI14{} + comparFuncNodeInt14(link1, link2, arg.data_ref) + link1 = &NodeI14{} link2 = &NodeIS14{} } } - -func sortStudentsList(l *NodeI14) *NodeI14 { - Head := l - if Head == nil { - return nil - } - Head.Next = sortStudentsList(Head.Next) - - if Head.Next != nil && Head.Data > Head.Next.Data { - Head = move(Head) - } - return Head -} - -func move(l *NodeI14) *NodeI14 { - p := l - n := l.Next - ret := n - - for n != nil && l.Data > n.Data { - p = n - n = n.Next - } - p.Next = l - l.Next = n - return ret -} diff --git a/tests/go/sortwordarr_test.go b/tests/go/sortwordarr_test.go index eeee4dc9..72d3be3c 100644 --- a/tests/go/sortwordarr_test.go +++ b/tests/go/sortwordarr_test.go @@ -1,8 +1,7 @@ -package student_test +package main import ( "reflect" - "testing" "github.com/01-edu/z01" @@ -10,19 +9,17 @@ import ( student "./student" ) -func TestSortWordArr(t *testing.T) { - var table [][]string +func main() { + table := [][]string{{"a", "A", "1", "b", "B", "2", "c", "C", "3"}} for i := 0; i < 15; i++ { table = append(table, z01.MultRandWords()) } - table = append(table, []string{"a", "A", "1", "b", "B", "2", "c", "C", "3"}) - for _, org := range table { - //copy for using the solution function + // copy for using the solution function cp_sol := make([]string, len(org)) - //copy for using the student function + // copy for using the student function cp_stu := make([]string, len(org)) copy(cp_sol, org) @@ -32,7 +29,7 @@ func TestSortWordArr(t *testing.T) { student.SortWordArr(cp_stu) if !reflect.DeepEqual(cp_stu, cp_sol) { - t.Fatalf("%s(%v) == %v instead of %v\n", + z01.Fatalf("%s(%v) == %v instead of %v\n", "SortWordArr", org, cp_stu, diff --git a/tests/go/split_test.go b/tests/go/split_test.go index 5a039b8e..4cad1b17 100644 --- a/tests/go/split_test.go +++ b/tests/go/split_test.go @@ -25,7 +25,7 @@ func main() { sep string } table := []node{} - //15 random slice of strings + // 15 random slice of strings for i := 0; i < 15; i++ { separator := separators[rand.Intn(len(separators))] diff --git a/tests/go/splitwhitespaces_test.go b/tests/go/splitwhitespaces_test.go index d10fefa7..2b185d68 100644 --- a/tests/go/splitwhitespaces_test.go +++ b/tests/go/splitwhitespaces_test.go @@ -11,7 +11,7 @@ import ( func main() { table := []string{} - //30 random slice of strings + // 30 random slice of strings for i := 0; i < 30; i++ { val := strings.Join(z01.MultRandASCII(), " ") diff --git a/tests/go/strlen_test.go b/tests/go/strlen_test.go index 675ef725..0199a4a1 100644 --- a/tests/go/strlen_test.go +++ b/tests/go/strlen_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { diff --git a/tests/go/swap_test.go b/tests/go/swap_test.go index 7f2dfb45..928320e9 100644 --- a/tests/go/swap_test.go +++ b/tests/go/swap_test.go @@ -1,14 +1,12 @@ -package student_test +package main import ( - "testing" - "github.com/01-edu/z01" student "./student" ) -func TestSwap(t *testing.T) { +func main() { i := 0 for i < 30 { a := z01.RandInt() @@ -17,10 +15,10 @@ func TestSwap(t *testing.T) { bCopy := b student.Swap(&a, &b) if a != bCopy { - t.Fatalf("Swap(%d, %d), a == %d instead of %d", aCopy, bCopy, a, bCopy) + z01.Fatalf("Swap(%d, %d), a == %d instead of %d", aCopy, bCopy, a, bCopy) } if b != aCopy { - t.Fatalf("Swap(%d, %d), b == %d instead of %d", aCopy, bCopy, b, aCopy) + z01.Fatalf("Swap(%d, %d), b == %d instead of %d", aCopy, bCopy, b, aCopy) } i++ } diff --git a/tests/go/swapbits_test.go b/tests/go/swapbits_test.go index 73ea392a..c5784850 100644 --- a/tests/go/swapbits_test.go +++ b/tests/go/swapbits_test.go @@ -1,8 +1,7 @@ -package student_test +package main import ( "reflect" - "testing" "github.com/01-edu/z01" @@ -10,12 +9,12 @@ import ( student "./student" ) -func challengeBytes(t *testing.T, fn1, fn2 interface{}, args ...interface{}) { +func challengeBytes(fn1, fn2 interface{}, args ...interface{}) { st1 := z01.Monitor(fn1, args) st2 := z01.Monitor(fn2, args) if !reflect.DeepEqual(st1.Results, st2.Results) { - t.Fatalf("%s(%08b) == %08b instead of %08b\n", - z01.NameOfFunc(fn1), + z01.Fatalf("%s(%08b) == %08b instead of %08b\n", + "SwapBits", args[0].(byte), st1.Results[0].(byte), st2.Results[0].(byte), @@ -23,7 +22,7 @@ func challengeBytes(t *testing.T, fn1, fn2 interface{}, args ...interface{}) { } } -func TestSwapBits(t *testing.T) { +func main() { args := []byte{0x24, 0x14, 0x11, 0x22, 0xd2, 0x15, 0xff, 0x0, 0x35, 0x58, 0x43} for i := 0; i < 10; i++ { @@ -32,6 +31,6 @@ func TestSwapBits(t *testing.T) { } for _, v := range args { - challengeBytes(t, student.SwapBits, solutions.SwapBits, v) + challengeBytes(student.SwapBits, solutions.SwapBits, v) } } diff --git a/tests/go/test_atoibaseprog.go b/tests/go/test_atoibaseprog.go index 0741d89c..2bd43622 100644 --- a/tests/go/test_atoibaseprog.go +++ b/tests/go/test_atoibaseprog.go @@ -1,54 +1,11 @@ package main import ( - "math/rand" + "./base" "github.com/01-edu/z01" ) -//randomValidBase function is used to create the tests (input VALID bases here) -func randomValidBase() string { - validBases := []string{ - "01", - "CHOUMIisDAcat!", - "choumi", - "0123456789", - "abc", "Zone01", - "0123456789ABCDEF", - "WhoAmI?", - } - index := rand.Intn(len(validBases)) - return validBases[index] -} - -//randomInvalidBase function is used to create the tests (input INVALID bases here) -func randomInvalidBase() string { - invalidBases := []string{ - "0", - "1", - "CHOUMIisdacat!", - "choumiChoumi", - "01234567890", - "abca", - "Zone01Zone01", - "0123456789ABCDEF0", - "WhoAmI?IamWhoIam", - } - index := z01.RandIntBetween(0, len(invalidBases)-1) - return invalidBases[index] -} - -//randomStringFromBase function is used to create the random STRING number from VALID BASES -func randomStringFromBase(base string) string { - letters := []rune(base) - size := z01.RandIntBetween(1, 10) - r := make([]rune, size) - for i := range r { - r[i] = letters[rand.Intn(len(letters))] - } - return string(r) -} - // this is the function that creates the TESTS func main() { type node struct { @@ -60,16 +17,16 @@ func main() { // 5 random pairs of string numbers with valid bases for i := 0; i < 5; i++ { - validBaseToInput := randomValidBase() + validBaseToInput := base.Valid() val := node{ - s: randomStringFromBase(validBaseToInput), + s: base.StringFrom(validBaseToInput), base: validBaseToInput, } table = append(table, val) } // 5 random pairs of string numbers with invalid bases for i := 0; i < 5; i++ { - invalidBaseToInput := randomInvalidBase() + invalidBaseToInput := base.Invalid() val := node{ s: "thisinputshouldnotmatter", base: invalidBaseToInput, @@ -89,3 +46,5 @@ func main() { z01.ChallengeMain("atoibaseprog") z01.ChallengeMain("atoibaseprog", "125", "0123456789", "something") } + +// TODO: fix base exercises diff --git a/tests/go/test_cat.go b/tests/go/test_cat.go index ed1a7f16..cfb2ac45 100644 --- a/tests/go/test_cat.go +++ b/tests/go/test_cat.go @@ -1,55 +1,38 @@ -package student_test +package main import ( - "errors" "io/ioutil" - "log" "os" "os/exec" "strings" - "testing" - - solutions "./solutions" "github.com/01-edu/z01" ) -//executes commands -func execC(name string, args ...string) (string, error) { - out, err := exec.Command(name, args...).Output() +func main() { + pathFileName1 := "./student/cat/quest8.txt" + pathFileName2 := "./student/cat/quest8T.txt" - output := string(out) - if err == nil { - return output, nil + if _, err := os.Stat(pathFileName1); err != nil { + z01.Fatalln(err) } - if output == "" { - return "", z01.Wrap(err, "Command failed") + if _, err := os.Stat(pathFileName2); err != nil { + z01.Fatalln(err) } - return "", errors.New(output) -} - -func TestCat(t *testing.T) { - var table []string - pathFileName := "./student/cat/quest8.txt" - pathFileName2 := "./student/cat/quest8T.txt" - - solutions.CheckFile(t, pathFileName) - solutions.CheckFile(t, pathFileName2) - - table = append(table, pathFileName, pathFileName+" "+pathFileName2, "asd") + table := []string{pathFileName1, pathFileName1 + " " + pathFileName2, "asd"} for _, s := range table { - z01.ChallengeMain(t, strings.Fields(s)...) + z01.ChallengeMain("cat", strings.Fields(s)...) } - _, err := execC("go", "build", "-o", "cat_student", "./student/cat/main.go") - _, err = execC("go", "build", "-o", "cat_solution", "./solutions/cat/main.go") - if err != nil { - log.Fatal(err.Error()) + if _, err := exec.Command("go", "build", "-o", "cat_student", "./student/cat/main.go").Output(); err != nil { + z01.Fatal(string(err.(*exec.ExitError).Stderr)) + } + if _, err := exec.Command("go", "build", "-o", "cat_solution", "./solutions/cat/main.go").Output(); err != nil { + z01.Fatal(string(err.(*exec.ExitError).Stderr)) } pwd, err := os.Getwd() - if err != nil { - t.Fatalf(err) + z01.Fatalln(err) } for i := 0; i < 2; i++ { @@ -60,33 +43,34 @@ func TestCat(t *testing.T) { studentResult := execStdin(cmdS, randStdin) if solutionResult != studentResult { - t.Fatalf("./cat prints %s instead of %s\n", studentResult, solutionResult) + z01.Fatalf("./cat prints %s instead of %s\n", studentResult, solutionResult) } } - execC("rm", "cat_student", "cat_solution") } func execStdin(cmd *exec.Cmd, randomStdin string) string { stdin, err := cmd.StdinPipe() if err != nil { - log.Fatal(err) + z01.Fatalln(err) } stdout, err := cmd.StdoutPipe() if err != nil { - log.Fatal(err) + z01.Fatalln(err) } if err := cmd.Start(); err != nil { - log.Fatal(err) + z01.Fatalln(err) } _, err = stdin.Write([]byte(randomStdin)) if err != nil { - log.Fatal(err) + z01.Fatalln(err) } stdin.Close() out, _ := ioutil.ReadAll(stdout) if err := cmd.Wait(); err != nil { - log.Fatal(err) + z01.Fatalln(err) } return string(out) } + +// TODO: handle stdin in ChallengeMain diff --git a/tests/go/test_displayfile.go b/tests/go/test_displayfile.go index 24e405b5..ef8757ea 100644 --- a/tests/go/test_displayfile.go +++ b/tests/go/test_displayfile.go @@ -11,7 +11,7 @@ func main() { pathFileName := "./student/displayfile/quest8.txt" _, err := os.Stat(pathFileName) if err != nil { - t.Fatal(err) + z01.Fatal(err) } table := []string{"", pathFileName, "quest8.txt asdsada"} for _, s := range table { diff --git a/tests/go/test_fixthemain.go b/tests/go/test_fixthemain.go index 395b2288..2b4804ef 100644 --- a/tests/go/test_fixthemain.go +++ b/tests/go/test_fixthemain.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("fixthemain") diff --git a/tests/go/test_flags.go b/tests/go/test_flags.go index 86016ab8..855b62d2 100644 --- a/tests/go/test_flags.go +++ b/tests/go/test_flags.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" type node struct { flags []string diff --git a/tests/go/test_nbrconvertalpha.go b/tests/go/test_nbrconvertalpha.go index ef32ea9c..337a655b 100644 --- a/tests/go/test_nbrconvertalpha.go +++ b/tests/go/test_nbrconvertalpha.go @@ -8,38 +8,24 @@ import ( ) func main() { - type node struct { - array []string - } - - table := []node{} + table := []string{{ + "--upper 8 5 25", + "8 5 12 12 15", + "12 5 7 5 14 56 4 1 18 25", + "12 5 7 5 14 56 4 1 18 25 32 86 h", + "32 86 h", + "", + }} for i := 0; i < 5; i++ { m := z01.MultRandIntBetween(1, 46) s := "" - str := []string{} for _, j := range m { s += strconv.Itoa(j) + " " } - str = append(str, s) - v := node{ - array: str, - } - table = append(table, v) + table = append(table, s) } - table = append(table, node{ - array: []string{ - "--upper 8 5 25", - "8 5 12 12 15", - "12 5 7 5 14 56 4 1 18 25", - "12 5 7 5 14 56 4 1 18 25 32 86 h", - "32 86 h", - ""}, - }) - - for _, i := range table { - for _, a := range i.array { - z01.ChallengeMain("nbrconvertalpha", strings.Fields((a))...) - } + for _, args := range table { + z01.ChallengeMain("nbrconvertalpha", strings.Fields(args)...) } } diff --git a/tests/go/test_pilot.go b/tests/go/test_pilot.go index 6dbec04e..f55096cd 100644 --- a/tests/go/test_pilot.go +++ b/tests/go/test_pilot.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("pilot") diff --git a/tests/go/test_point.go b/tests/go/test_point.go index 9571c848..5de153cb 100644 --- a/tests/go/test_point.go +++ b/tests/go/test_point.go @@ -1,9 +1,7 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - z01.ChallengeMain("point", "") + z01.ChallengeMain("point") } diff --git a/tests/go/test_printalphabet.go b/tests/go/test_printalphabet.go index 62a9e7bf..c4b3cbec 100644 --- a/tests/go/test_printalphabet.go +++ b/tests/go/test_printalphabet.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("printalphabet") diff --git a/tests/go/test_printdigits.go b/tests/go/test_printdigits.go index 41f4c0c5..825920d7 100644 --- a/tests/go/test_printdigits.go +++ b/tests/go/test_printdigits.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("printdigits") diff --git a/tests/go/test_printreversealphabet.go b/tests/go/test_printreversealphabet.go index 62577c09..5dc095cf 100644 --- a/tests/go/test_printreversealphabet.go +++ b/tests/go/test_printreversealphabet.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("printreversealphabet") diff --git a/tests/go/test_raid2.go b/tests/go/test_raid2.go index b99e9155..2fee0967 100644 --- a/tests/go/test_raid2.go +++ b/tests/go/test_raid2.go @@ -1,211 +1,296 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - // Valid sudokus - arg1 := []string{".96.4...1", "1...6...4", "5.481.39.", - "..795..43", ".3..8....", "4.5.23.18", - ".1.63..59", ".59.7.83.", "..359...7", - } - /* - "3 9 6 2 4 5 7 8 1", - "1 7 8 3 6 9 5 2 4", - "5 2 4 8 1 7 3 9 6", - "2 8 7 9 5 1 6 4 3", - "9 3 1 4 8 6 2 7 5", - "4 6 5 7 2 3 9 1 8", - "7 1 2 6 3 8 4 5 9", - "6 5 9 1 7 4 8 3 2", - "8 4 3 5 9 2 1 6 7" - */ - arg2 := []string{"1.58.2...", ".9..764.5", "2..4..819", - ".19..73.6", "762.83.9.", "....61.5.", - "..76...3.", "43..2.5.1", "6..3.89..", - } - /* - 1 4 5 8 9 2 6 7 3 - 8 9 3 1 7 6 4 2 5 - 2 7 6 4 3 5 8 1 9 - 5 1 9 2 4 7 3 8 6 - 7 6 2 5 8 3 1 9 4 - 3 8 4 9 6 1 7 5 2 - 9 5 7 6 1 4 2 3 8 - 4 3 8 7 2 9 5 6 1 - 6 2 1 3 5 8 9 4 7 - */ - arg3 := []string{"..5.3..81", "9.285..6.", "6....4.5.", - "..74.283.", "34976...5", "..83..49.", - "15..87..2", ".9....6..", ".26.495.3", - } - /* - 4 7 5 9 3 6 2 8 1 - 9 3 2 8 5 1 7 6 4 - 6 8 1 2 7 4 3 5 9 - 5 1 7 4 9 2 8 3 6 - 3 4 9 7 6 8 1 2 5 - 2 6 8 3 1 5 4 9 7 - 1 5 3 6 8 7 9 4 2 - 7 9 4 5 2 3 6 1 8 - 8 2 6 1 4 9 5 7 3 - */ - arg4 := []string{"34.91..2.", ".96.8..41", "..8.2..7.", - ".6..57.39", "1.2.6.7..", "97..3..64", - "45.2.8..6", ".8..9..5.", "6.3..189.", - } - /* - 3 4 7 9 1 5 6 2 8 - 2 9 6 7 8 3 5 4 1 - 5 1 8 6 2 4 9 7 3 - 8 6 4 1 5 7 2 3 9 - 1 3 2 4 6 9 7 8 5 - 9 7 5 8 3 2 1 6 4 - 4 5 9 2 7 8 3 1 6 - 7 8 1 3 9 6 4 5 2 - 6 2 3 5 4 1 8 9 7 - */ - arg5 := []string{"..73..4.5", "....2.9..", "253.6487.", - ".9.74.36.", "....3..8.", "8362.9.47", - "1..8.26.3", "6......18", ".8261...4", - } - /*"..73..4.5","....2.9..","253.6487.",".9.74.36.","....3..8.","8362.9.47","1..8.26.3","6......18",".8261...4", - 9 6 7 3 8 1 4 2 5 - 4 1 8 5 2 7 9 3 6 - 2 5 3 9 6 4 8 7 1 - 5 9 1 7 4 8 3 6 2 - 7 2 4 1 3 6 5 8 9 - 8 3 6 2 5 9 1 4 7 - 1 4 9 8 7 2 6 5 3 - 6 7 5 4 9 3 2 1 8 - 3 8 2 6 1 5 7 9 4 - - */ - arg6 := []string{"935..7..8", "...3.8.7.", "6..5..49.", - ".73..4...", "4..175.8.", ".618..247", - ".187.....", "..6.8.75.", "75.4.3862", - } - /* - 9 3 5 6 4 7 1 2 8 - 1 2 4 3 9 8 6 7 5 - 6 8 7 5 2 1 4 9 3 - 8 7 3 2 6 4 5 1 9 - 4 9 2 1 7 5 3 8 6 - 5 6 1 8 3 9 2 4 7 - 2 1 8 7 5 6 9 3 4 - 3 4 6 9 8 2 7 5 1 - 7 5 9 4 1 3 8 6 2 - */ - arg7 := []string{"..5.2...1", ".8735..46", "4...6.5..", - ".5.9.....", ".7..3541.", "69314.857", - "7415..6.8", "...284..5", "5.....3.4", - } - /* - 3 6 5 4 2 9 7 8 1 - 2 8 7 3 5 1 9 4 6 - 4 1 9 8 6 7 5 3 2 - 1 5 4 9 7 8 2 6 3 - 8 7 2 6 3 5 4 1 9 - 6 9 3 1 4 2 8 5 7 - 7 4 1 5 9 3 6 2 8 - 9 3 6 2 8 4 1 7 5 - 5 2 8 7 1 6 3 9 4 - */ - arg8 := []string{"..75...3.", "8..23...9", ".3479.86.", - "..3..4198", ".4815...3", "..6.23..7", - "351.6.78.", "4..31...6", ".7...5..2", - } - /* - 9 6 7 5 4 8 2 3 1 - 8 1 5 2 3 6 4 7 9 - 2 3 4 7 9 1 8 6 5 - 5 2 3 6 7 4 1 9 8 - 7 4 8 1 5 9 6 2 3 - 1 9 6 8 2 3 5 4 7 - 3 5 1 9 6 2 7 8 4 - 4 8 2 3 1 7 9 5 6 - 6 7 9 4 8 5 3 1 2 - */ - arg9 := []string{".58..4.21", ".6.853..7", ".39.2...5", - "8....1..6", "..37..21.", "1.6.825..", - "67.2..18.", "9..4...5.", ".8.9167.2", - } + valid := [][]string{ + // 3 9 6 2 4 5 7 8 1 + // 1 7 8 3 6 9 5 2 4 + // 5 2 4 8 1 7 3 9 6 + // 2 8 7 9 5 1 6 4 3 + // 9 3 1 4 8 6 2 7 5 + // 4 6 5 7 2 3 9 1 8 + // 7 1 2 6 3 8 4 5 9 + // 6 5 9 1 7 4 8 3 2 + // 8 4 3 5 9 2 1 6 7 + { + ".96.4...1", + "1...6...4", + "5.481.39.", + "..795..43", + ".3..8....", + "4.5.23.18", + ".1.63..59", + ".59.7.83.", + "..359...7", + }, - /* - 7 5 8 6 9 4 3 2 1 - 2 6 1 8 5 3 4 9 7 - 4 3 9 1 2 7 8 6 5 - 8 2 7 5 4 1 9 3 6 - 5 4 3 7 6 9 2 1 8 - 1 9 6 3 8 2 5 7 4 - 6 7 4 2 3 5 1 8 9 - 9 1 2 4 7 8 6 5 3 - 3 8 5 9 1 6 7 4 2 - */ - arg10 := []string{".2.1....6", "53..8294.", "8..34...5", - "3542761..", "..6.3...4", "9....162.", - ".9...3.78", "7438.9...", "..5..43.1", - } - /* - 4 2 7 1 9 5 8 3 6 - 5 3 1 6 8 2 9 4 7 - 8 6 9 3 4 7 2 1 5 - 3 5 4 2 7 6 1 8 9 - 2 1 6 9 3 8 7 5 4 - 9 7 8 4 5 1 6 2 3 - 1 9 2 5 6 3 4 7 8 - 7 4 3 8 1 9 5 6 2 - 6 8 5 7 2 4 3 9 1 - */ - valid := [][]string{arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10} - - // Invalid sudokus - - argin1 := []string{".932..8.", "27.3.85..", ".8.73.254", - "9758...31", "....74.6.", "6.45.38.7", - "7....2.48", "32.4...7.", "..8.579..", - } - argin2 := []string{".867.2..4", ".2.5..8..", "154.9.237", - ".7.9.5..1", ".29..4.18", "51.6...42", - "2.5.7..83", "...153...", "39...8.75", - } + // 1 4 5 8 9 2 6 7 3 + // 8 9 3 1 7 6 4 2 5 + // 2 7 6 4 3 5 8 1 9 + // 5 1 9 2 4 7 3 8 6 + // 7 6 2 5 8 3 1 9 4 + // 3 8 4 9 6 1 7 5 2 + // 9 5 7 6 1 4 2 3 8 + // 4 3 8 7 2 9 5 6 1 + // 6 2 1 3 5 8 9 4 7 + { + "1.58.2...", + ".9..764.5", + "2..4..819", + ".19..73.6", + "762.83.9.", + "....61.5.", + "..76...3.", + "43..2.5.1", + "6..3.89..", + }, - /* - . . 7 3 . . 4 . 5 - . . . . 2 . 9 . . - 2 5 3 . 6 4 8 7 . - . 9 . 7 4 . 3 6 . - . . . . 3 . . 8 . - 8 3 6 2 . 9 . 4 7 - 1 . . 8 . 2 6 . 3 - 6 . . . . . . 1 8 - . 8 2 6 1 . . . 4 - */ - argin3 := []string{".7....28.", ".2...6.57", "8654729..", - "..925..64", ".4..19.7.", "7.8..4..9", - "3..7..698", "..79.1...", "59..28.39", - } - argin4 := []string{"..213.748", "8.4.....2", ".178.26..", - ".68.9.27.", ".932....4", "5..46.3..", - "..9.24.23", "..63..19.", "385..1.2.", + // 4 7 5 9 3 6 2 8 1 + // 9 3 2 8 5 1 7 6 4 + // 6 8 1 2 7 4 3 5 9 + // 5 1 7 4 9 2 8 3 6 + // 3 4 9 7 6 8 1 2 5 + // 2 6 8 3 1 5 4 9 7 + // 1 5 3 6 8 7 9 4 2 + // 7 9 4 5 2 3 6 1 8 + // 8 2 6 1 4 9 5 7 3 + { + "..5.3..81", + "9.285..6.", + "6....4.5.", + "..74.283.", + "34976...5", + "..83..49.", + "15..87..2", + ".9....6..", + ".26.495.3", + }, + + // 3 4 7 9 1 5 6 2 8 + // 2 9 6 7 8 3 5 4 1 + // 5 1 8 6 2 4 9 7 3 + // 8 6 4 1 5 7 2 3 9 + // 1 3 2 4 6 9 7 8 5 + // 9 7 5 8 3 2 1 6 4 + // 4 5 9 2 7 8 3 1 6 + // 7 8 1 3 9 6 4 5 2 + // 6 2 3 5 4 1 8 9 7 + { + "34.91..2.", + ".96.8..41", + "..8.2..7.", + ".6..57.39", + "1.2.6.7..", + "97..3..64", + "45.2.8..6", + ".8..9..5.", + "6.3..189.", + }, + + // 9 6 7 3 8 1 4 2 5 + // 4 1 8 5 2 7 9 3 6 + // 2 5 3 9 6 4 8 7 1 + // 5 9 1 7 4 8 3 6 2 + // 7 2 4 1 3 6 5 8 9 + // 8 3 6 2 5 9 1 4 7 + // 1 4 9 8 7 2 6 5 3 + // 6 7 5 4 9 3 2 1 8 + // 3 8 2 6 1 5 7 9 4 + { + "..73..4.5", + "....2.9..", + "253.6487.", + ".9.74.36.", + "....3..8.", + "8362.9.47", + "1..8.26.3", + "6......18", + ".8261...4", + }, + + // 9 3 5 6 4 7 1 2 8 + // 1 2 4 3 9 8 6 7 5 + // 6 8 7 5 2 1 4 9 3 + // 8 7 3 2 6 4 5 1 9 + // 4 9 2 1 7 5 3 8 6 + // 5 6 1 8 3 9 2 4 7 + // 2 1 8 7 5 6 9 3 4 + // 3 4 6 9 8 2 7 5 1 + // 7 5 9 4 1 3 8 6 2 + { + "935..7..8", + "...3.8.7.", + "6..5..49.", + ".73..4...", + "4..175.8.", + ".618..247", + ".187.....", + "..6.8.75.", + "75.4.3862", + }, + + // 3 6 5 4 2 9 7 8 1 + // 2 8 7 3 5 1 9 4 6 + // 4 1 9 8 6 7 5 3 2 + // 1 5 4 9 7 8 2 6 3 + // 8 7 2 6 3 5 4 1 9 + // 6 9 3 1 4 2 8 5 7 + // 7 4 1 5 9 3 6 2 8 + // 9 3 6 2 8 4 1 7 5 + // 5 2 8 7 1 6 3 9 4 + { + "..5.2...1", + ".8735..46", + "4...6.5..", + ".5.9.....", + ".7..3541.", + "69314.857", + "7415..6.8", + "...284..5", + "5.....3.4", + }, + + // 9 6 7 5 4 8 2 3 1 + // 8 1 5 2 3 6 4 7 9 + // 2 3 4 7 9 1 8 6 5 + // 5 2 3 6 7 4 1 9 8 + // 7 4 8 1 5 9 6 2 3 + // 1 9 6 8 2 3 5 4 7 + // 3 5 1 9 6 2 7 8 4 + // 4 8 2 3 1 7 9 5 6 + // 6 7 9 4 8 5 3 1 2 + { + "..75...3.", + "8..23...9", + ".3479.86.", + "..3..4198", + ".4815...3", + "..6.23..7", + "351.6.78.", + "4..31...6", + ".7...5..2", + }, + + // 7 5 8 6 9 4 3 2 1 + // 2 6 1 8 5 3 4 9 7 + // 4 3 9 1 2 7 8 6 5 + // 8 2 7 5 4 1 9 3 6 + // 5 4 3 7 6 9 2 1 8 + // 1 9 6 3 8 2 5 7 4 + // 6 7 4 2 3 5 1 8 9 + // 9 1 2 4 7 8 6 5 3 + // 3 8 5 9 1 6 7 4 2 + { + ".58..4.21", + ".6.853..7", + ".39.2...5", + "8....1..6", + "..37..21.", + "1.6.825..", + "67.2..18.", + "9..4...5.", + ".8.9167.2", + }, + + // 4 2 7 1 9 5 8 3 6 + // 5 3 1 6 8 2 9 4 7 + // 8 6 9 3 4 7 2 1 5 + // 3 5 4 2 7 6 1 8 9 + // 2 1 6 9 3 8 7 5 4 + // 9 7 8 4 5 1 6 2 3 + // 1 9 2 5 6 3 4 7 8 + // 7 4 3 8 1 9 5 6 2 + // 6 8 5 7 2 4 3 9 1 + { + ".2.1....6", + "53..8294.", + "8..34...5", + "3542761..", + "..6.3...4", + "9....162.", + ".9...3.78", + "7438.9...", + "..5..43.1", + }, } - argin5 := []string{"9.46.3..1", "37.1..2.6", "..6..93.4", - "..13..9.5", "56..91...", "82...461.", - "..79...4.", "425.167..", "1.2..75.8", + + invalid := [][]string{ + { + ".932..8.", + "27.3.85..", + ".8.73.254", + "9758...31", + "....74.6.", + "6.45.38.7", + "7....2.48", + "32.4...7.", + "..8.579..", + }, + { + ".867.2..4", + ".2.5..8..", + "154.9.237", + ".7.9.5..1", + ".29..4.18", + "51.6...42", + "2.5.7..83", + "...153...", + "39...8.75", + }, + + // . . 7 3 . . 4 . 5 + // . . . . 2 . 9 . . + // 2 5 3 . 6 4 8 7 . + // . 9 . 7 4 . 3 6 . + // . . . . 3 . . 8 . + // 8 3 6 2 . 9 . 4 7 + // 1 . . 8 . 2 6 . 3 + // 6 . . . . . . 1 8 + // . 8 2 6 1 . . . 4 + { + ".7....28.", + ".2...6.57", + "8654729..", + "..925..64", + ".4..19.7.", + "7.8..4..9", + "3..7..698", + "..79.1...", + "59..28.39", + }, + { + "..213.748", + "8.4.....2", + ".178.26..", + ".68.9.27.", + ".932....4", + "5..46.3..", + "..9.24.23", + "..63..19.", + "385..1.2.", + }, + { + "9.46.3..1", + "37.1..2.6", + "..6..93.4", + "..13..9.5", + "56..91...", + "82...461.", + "..79...4.", + "425.167..", + "1.2..75.8", + }, } - invalid := [][]string{argin1, argin2, argin3, argin4, argin5} for _, v := range valid { z01.ChallengeMain("raid2", v...) } - for _, i := range invalid { - z01.ChallengeMain("raid2", i...) + for _, v := range invalid { + z01.ChallengeMain("raid2", v...) } - // No arguments z01.ChallengeMain("raid2") - // Wrong number of arguments z01.ChallengeMain("raid2", "not", "a", "sudoku") } diff --git a/tests/go/test_rectangle.go b/tests/go/test_rectangle.go index 720843b6..45ee27ba 100644 --- a/tests/go/test_rectangle.go +++ b/tests/go/test_rectangle.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { z01.ChallengeMain("rectangle") diff --git a/tests/go/test_revparams.go b/tests/go/test_revparams.go index bf9e1096..8aa5dee4 100644 --- a/tests/go/test_revparams.go +++ b/tests/go/test_revparams.go @@ -1,10 +1,8 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - args := []string{"choumi", "is", "the", "best", "cat"} - z01.ChallengeMain("revparams", args...) + z01.ChallengeMain("revparams", "choumi", "is", "the", "best", "cat") + z01.ChallengeMain("revparams", z01.MultRandWords()...) } diff --git a/tests/go/test_sortparams.go b/tests/go/test_sortparams.go index e1dd3a61..f25ad361 100644 --- a/tests/go/test_sortparams.go +++ b/tests/go/test_sortparams.go @@ -1,10 +1,7 @@ package main -import ( - "github.com/01-edu/z01" -) +import "github.com/01-edu/z01" func main() { - args := []string{"1", "a", "2", "A", "3", "b", "4", "C"} - z01.ChallengeMain("sortparams", args...) + z01.ChallengeMain("sortparams", z01.MultRandWords()...) } diff --git a/tests/go/tetrisoptimizer_test.go b/tests/go/tetrisoptimizer_test.go index 178da33c..e2b3524b 100644 --- a/tests/go/tetrisoptimizer_test.go +++ b/tests/go/tetrisoptimizer_test.go @@ -1,4 +1,4 @@ -package student_test +package main import ( "context" @@ -10,8 +10,9 @@ import ( "sort" "strconv" "strings" - "testing" "time" + + "github.com/01-edu/z01" ) type ( @@ -39,14 +40,15 @@ type ( // `, // 'X', // ) == tetromino{{-2, 1}, {-1, 1}, {0, 1}} + func read(s string, r rune) (t tetromino) { var origin vect i := 0 first := true lines := strings.Split(s, "\n") for y, line := range lines { - for x := range line { - if []rune(line)[x] == r { + for x, rr := range line { + if rr == r { if first { first = false origin = vect{x, y} @@ -63,7 +65,7 @@ func read(s string, r rune) (t tetromino) { return } -func TestTetrisOptimizer(t *testing.T) { +func main() { var ( timeout = 30 * time.Second samples = "./solutions/tetrisoptimizer/samples" @@ -73,12 +75,12 @@ func TestTetrisOptimizer(t *testing.T) { // load samples f, err := os.Open(samples) if err != nil { - t.Fatal("Cannot open directory", err) + z01.Fatal("Cannot open directory", err) } defer f.Close() filenames, err := f.Readdirnames(0) if err != nil { - t.Fatal("Cannot read directory", err) + z01.Fatal("Cannot read directory", err) } // separate samples into good (valid) and bad (invalid) files @@ -97,7 +99,7 @@ func TestTetrisOptimizer(t *testing.T) { cmd := exec.Command("go", "build", "-o", exe, "-trimpath", "-ldflags", "-s -w", student) cmd.Env = append(os.Environ(), "CGO_ENABLED=0", "GOARCH=amd64") if out, err := cmd.CombinedOutput(); err != nil { - t.Fatal("Cannot compile :", string(out)) + z01.Fatal("Cannot compile :", string(out)) } ctx, cancel := context.WithTimeout(context.Background(), timeout) @@ -107,7 +109,7 @@ func TestTetrisOptimizer(t *testing.T) { for _, badFile := range badFiles { b, _ := exec.CommandContext(ctx, exe, badFile).CombinedOutput() if string(b) != "ERROR\n" { - t.Fatal(`Failed to handle bad format, should output : "ERROR\n"`) + z01.Fatal(`Failed to handle bad format, should output : "ERROR\n"`) } } @@ -123,35 +125,35 @@ func TestTetrisOptimizer(t *testing.T) { return } if err != nil { - t.Fatal("Failed to process a valid map : execution failed") + z01.Fatal("Failed to process a valid map : execution failed") } s := string(b) lines := strings.Split(s, "\n") if lines[len(lines)-1] != "" { - t.Fatal(`Failed to process a valid map : missing final '\n'`) + z01.Fatal(`Failed to process a valid map : missing final '\n'`) } lines = lines[:len(lines)-1] for _, line := range lines { if len(line) != len(lines) { - t.Fatal("Failed to process a valid map : invalid square, it is expected as many lines as characters") + z01.Fatal("Failed to process a valid map : invalid square, it is expected as many lines as characters") } } if len(lines) < size { - t.Fatal("Failed to process a valid map : the square cannot be that small") + z01.Fatal("Failed to process a valid map : the square cannot be that small") } b, err = ioutil.ReadFile(goodFile) if err != nil { - t.Fatal("Failed to read a valid map") + z01.Fatal("Failed to read a valid map") } pieces := strings.Split(string(b), "\n\n") surface := len(lines) * len(lines) if strings.Count(s, ".") != surface-len(pieces)*4 { - t.Fatal("Failed to process a valid map : the number of holes (character '.') is not correct") + z01.Fatal("Failed to process a valid map : the number of holes (character '.') is not correct") } letter := 'A' for _, piece := range pieces { if read(s, letter) != read(piece, '#') { - t.Fatal("Failed to process a valid map : a tetromino is missing") + z01.Fatal("Failed to process a valid map : a tetromino is missing") } letter += 1 } @@ -160,6 +162,6 @@ func TestTetrisOptimizer(t *testing.T) { } // TODO: -// Ajouter des cas d'erreurs : -// mauvais arguments -// mauvais types de fichiers (liens, dossiers) +// Add error cases : +// wrong arguments +// bad file types (links, folders) diff --git a/tests/go/trimatoi_test.go b/tests/go/trimatoi_test.go index 6ea40cdc..6d7c5186 100644 --- a/tests/go/trimatoi_test.go +++ b/tests/go/trimatoi_test.go @@ -1,13 +1,31 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) +func stringsToTrimAtoi(a []string) []string { + alpha := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789012345678901234567890123456789" + + for index := 0; index < 4; index++ { + s := "" + s += z01.RandStr(z01.RandIntBetween(0, 2), alpha) + x := z01.RandIntBetween(0, 14) + if x <= 4 { + s += "-" + } + s += z01.RandStr(z01.RandIntBetween(0, 10), alpha) + a = append(a, s) + } + return a +} + func main() { - array := []string{"", + a := []string{ + "", "12345", "str123ing45", "012 345", @@ -15,25 +33,10 @@ func main() { "sd+x1fa2W3s4", "sd-x1fa2W3s4", "sdx1-fa2W3s4", - z01.RandAlnum()} - array = stringsToTrimAtoi(array) - for i := range array { - z01.Challenge("TrimAtoi", student.TrimAtoi, solutions.TrimAtoi, array[i]) + z01.RandAlnum(), } -} - -func stringsToTrimAtoi(arr []string) []string { - alpha := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789012345678901234567890123456789" - - for index := 0; index < 4; index++ { - str := "" - str += z01.RandStr(z01.RandIntBetween(0, 2), alpha) - x := z01.RandIntBetween(0, 14) - if x <= 4 { - str += "-" - } - str += z01.RandStr(z01.RandIntBetween(0, 10), alpha) - arr = append(arr, str) + a = stringsToTrimAtoi(a) + for _, elem := range a { + z01.Challenge("TrimAtoi", student.TrimAtoi, solutions.TrimAtoi, elem) } - return arr } diff --git a/tests/go/ultimatedivmod_test.go b/tests/go/ultimatedivmod_test.go index 458de721..285379e3 100644 --- a/tests/go/ultimatedivmod_test.go +++ b/tests/go/ultimatedivmod_test.go @@ -1,13 +1,11 @@ -package student_test +package main import ( - "testing" - student "./student" "github.com/01-edu/z01" ) -func TestUltimateDivMod(t *testing.T) { +func main() { i := 0 for i < z01.SliceLen { a := z01.RandInt() @@ -18,10 +16,10 @@ func TestUltimateDivMod(t *testing.T) { mod := a % b student.UltimateDivMod(&a, &b) if a != div { - t.Fatalf("DivMod(%d, %d), a == %d instead of %d", aCopy, bCopy, a, div) + z01.Fatalf("DivMod(%d, %d), a == %d instead of %d", aCopy, bCopy, a, div) } if b != mod { - t.Fatalf("DivMod(%d, %d), b == %d instead of %d", aCopy, bCopy, b, mod) + z01.Fatalf("DivMod(%d, %d), b == %d instead of %d", aCopy, bCopy, b, mod) } i++ } diff --git a/tests/go/ultimatepointone_test.go b/tests/go/ultimatepointone_test.go index 250c1f04..5dc4c1ec 100644 --- a/tests/go/ultimatepointone_test.go +++ b/tests/go/ultimatepointone_test.go @@ -1,17 +1,16 @@ -package student_test +package main import ( - "testing" - student "./student" + "github.com/01-edu/z01" ) -func TestUltimatePointOne(t *testing.T) { +func main() { a := 0 b := &a n := &b student.UltimatePointOne(&n) if a != 1 { - t.Fatalf("UltimatePointOne(&n), a == %d instead of 1", a) + z01.Fatalf("UltimatePointOne(&n), a == %d instead of 1", a) } } diff --git a/tests/go/unmatch_test.go b/tests/go/unmatch_test.go index 1254ccbb..e41889bd 100644 --- a/tests/go/unmatch_test.go +++ b/tests/go/unmatch_test.go @@ -1,9 +1,10 @@ package main import ( + "github.com/01-edu/z01" + solutions "./solutions" student "./student" - "github.com/01-edu/z01" ) func main() { diff --git a/tests/go/ztail_test.go b/tests/go/ztail_test.go index 53fba308..3d7fd048 100644 --- a/tests/go/ztail_test.go +++ b/tests/go/ztail_test.go @@ -1,41 +1,34 @@ -package student_test - -import ( - "strings" - "testing" - - "github.com/01-edu/z01" -) - -//Compares only the stdout of each program -//As long as the program executes like tail for the stdout -//and the error messages are send to stderr -//the program passes the test -func TestZTail(t *testing.T) { - exercise := strings.ToLower( - strings.TrimPrefix(t.Name(), "Test")) - - arg1 := []string{"-c", "23", "./student/" + exercise + "/main.go"} - arg2 := []string{"./student/" + exercise + "/main.go", "-c", "23"} - arg3 := []string{"-c", "jfdka", "23"} - arg4 := []string{"-c", "23", "./student/" + exercise + "/README.md", "fjksdsf"} - arg5 := []string{"-c", "23", "../../README.md", "fjksdsf", "-c", "43"} - - argArr := [][]string{arg1, arg2, arg3, arg4, arg5} +package main +// Compares only the stdout of each program +// As long as the program executes like tail for the stdout +// and the error messages are send to stderr +// the program passes the test +func main() { + argArr := [][]string{ + {"-c", "23", "student/ztail/main.go"}, + {"-c", "23", "student/ztail/README.md", "fjksdsf"}, + {"-c", "23", "../../README.md", "fjksdsf", "-c", "43"}, + {"student/ztail/main.go", "-c", "23"}, + {"-c", "jfdka", "23"}, + } for _, args := range argArr { - correct, errC := z01.ExecOut("tail", args...) - out, err := z01.MainOut("./student/"+exercise, args...) - if out != correct { - t.Errorf("./%s \"%s\" prints %q instead of %q\n", - exercise, strings.Join(args, " "), out, correct) - } - if errC != nil && err == nil { - t.Errorf("./%s \"%s\" prints %q instead of %q\n", exercise, strings.Join(args, " "), "", errC) - } - if err != nil && errC != nil && err.Error() != errC.Error() { - t.Errorf("./%s %s prints %q instead of %q\n", exercise, strings.Join(args, " "), err, errC) - } - + _ = args + // b, errC := exec.Command("tail", args...).CombinedOutput() + // correct := string(b) + // b, err := exec.Command + // out, err := z01.MainOut("student/ztail", args...) + // if out != correct { + // z01.Fatalf("./ztail \"%s\" prints %q instead of %q\n", + // strings.Join(args, " "), out, correct) + // } + // if errC != nil && err == nil { + // z01.Fatalf("./ztail \"%s\" prints %q instead of %q\n", strings.Join(args, " "), "", errC) + // } + // if err != nil && errC != nil && err != errC.Error() { + // z01.Fatalf("./ztail %s prints %q instead of %q\n", strings.Join(args, " "), err, errC) + // } } } + +// TODO: never use programs we didn't wrote (do not run the true cat but instead code our own solution)