From f8f51c7edf286014e7fea89863b95bb6b140df8d Mon Sep 17 00:00:00 2001 From: hamza Date: Thu, 7 Jul 2022 14:15:08 +0100 Subject: [PATCH 01/56] fix format paramrange_test --- tests/paramrange_test/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/paramrange_test/main.go b/tests/paramrange_test/main.go index 6f7ab683..79b26a46 100644 --- a/tests/paramrange_test/main.go +++ b/tests/paramrange_test/main.go @@ -13,8 +13,8 @@ func main() { {""}, {"-10", "10", "20", "30", "40", "50"}, {"Hello world"}, - {"10","20","-1"}, - {"1","-2","3"} + {"10", "20", "-1"}, + {"1", "-2", "3"}, } for _, v := range args { challenge.Program("paramrange", v...) From 0e1fa9038b243a28e902fe086354fa7d2f247b29 Mon Sep 17 00:00:00 2001 From: miguel Date: Tue, 12 Jul 2022 14:47:01 +0100 Subject: [PATCH 02/56] fixing the solution of rotatevowels --- solutions/rotatevowels/main.go | 48 ++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/solutions/rotatevowels/main.go b/solutions/rotatevowels/main.go index 979d777e..40656ed1 100644 --- a/solutions/rotatevowels/main.go +++ b/solutions/rotatevowels/main.go @@ -1,37 +1,45 @@ package main import ( - "fmt" "os" - "strings" + + "github.com/01-edu/z01" ) func main() { - var a1, a2, rev []rune - for _, arg := range os.Args[1:] { - for _, k := range arg { - if strings.ContainsRune("aeiouAEIOU", k) { - a1 = append(a1, k) + var vowels []rune + + arguments := os.Args[1:] + + for _, i := range arguments { + for j := 0; j < len(i); j++ { + if IsVowel(i[j]) { + vowels = append(vowels, rune(i[j])) } } } - for i := len(a1) - 1; i >= 0; i-- { - rev = append(rev, a1[i]) - } - m := 0 - for i, arg := range os.Args[1:] { - for _, j := range arg { - if strings.ContainsRune("aeiouAEIOU", j) { - a2 = append(a2, rev[m]) - m++ + counter := len(vowels) - 1 + + for s, i := range arguments { + for j := 0; j < len(i); j++ { + if IsVowel(i[j]) { + z01.PrintRune(rune(vowels[counter])) + counter-- } else { - a2 = append(a2, j) + z01.PrintRune(rune(i[j])) } } - if i != len(os.Args)-1 { - a2 = append(a2, ' ') + if s != len(arguments)-1 { + z01.PrintRune(' ') } } - fmt.Println(string(a2)) + z01.PrintRune('\n') +} + +func IsVowel(s byte) bool { + if s == 65 || s == 69 || s == 73 || s == 79 || s == 85 || s == 97 || s == 101 || s == 105 || s == 111 || s == 117 { + return true + } + return false } From 827834ab8392c261a8fb5e91e0b3112c9f23ef2c Mon Sep 17 00:00:00 2001 From: hamza Date: Wed, 13 Jul 2022 13:26:58 +0100 Subject: [PATCH 03/56] Fix format --- solutions/alphaposition.go | 2 +- solutions/argrotn/main.go | 2 +- solutions/paramrange/main.go | 2 +- tests/alphaposition_test/main.go | 1 - tests/argrotn_test/main.go | 14 +++++++------- tests/betweenus_test/main.go | 16 ++++++++-------- tests/binaryaddition_test/main.go | 4 ++-- tests/countnegative_test/main.go | 8 ++++---- tests/divisors_test/main.go | 2 +- tests/getarea_test/main.go | 12 ++++++------ 10 files changed, 31 insertions(+), 32 deletions(-) diff --git a/solutions/alphaposition.go b/solutions/alphaposition.go index 53672adf..8dd35a02 100644 --- a/solutions/alphaposition.go +++ b/solutions/alphaposition.go @@ -1,6 +1,6 @@ package solutions -func AlphaPosition(c rune) int{ +func AlphaPosition(c rune) int { if c >= 'a' && c <= 'z' { return int(c - 'a' + 1) } else if c >= 'A' && c <= 'Z' { diff --git a/solutions/argrotn/main.go b/solutions/argrotn/main.go index 969e2672..3356d6f8 100644 --- a/solutions/argrotn/main.go +++ b/solutions/argrotn/main.go @@ -20,7 +20,7 @@ func main() { for i := 0; i < len(args); i++ { fmt.Print(string(args[(i+n)%len(args)])) - if i < len(args)-1 { + if i < len(args)-1 { fmt.Print(" ") } } diff --git a/solutions/paramrange/main.go b/solutions/paramrange/main.go index 4853a76b..b66480ab 100644 --- a/solutions/paramrange/main.go +++ b/solutions/paramrange/main.go @@ -30,4 +30,4 @@ func main() { } } fmt.Println(min, max) -} \ No newline at end of file +} diff --git a/tests/alphaposition_test/main.go b/tests/alphaposition_test/main.go index 16f35966..506dd2ac 100644 --- a/tests/alphaposition_test/main.go +++ b/tests/alphaposition_test/main.go @@ -1,4 +1,3 @@ - package main import ( diff --git a/tests/argrotn_test/main.go b/tests/argrotn_test/main.go index eee2636e..d80293ba 100644 --- a/tests/argrotn_test/main.go +++ b/tests/argrotn_test/main.go @@ -7,13 +7,13 @@ import ( func main() { args := [][]string{ {""}, - {"1","One", "ring!"}, - {"2","testing spaces and #!*"}, - {"3","more", "than", "three", "arguments"}, - {"10","Upper anD LoWer cAsE"}, - {"0","Hello", "World","everyOne"}, - {"-1","Hello", "World","everyOne"}, - {"4","Hello", "World","everyOne"}, + {"1", "One", "ring!"}, + {"2", "testing spaces and #!*"}, + {"3", "more", "than", "three", "arguments"}, + {"10", "Upper anD LoWer cAsE"}, + {"0", "Hello", "World", "everyOne"}, + {"-1", "Hello", "World", "everyOne"}, + {"4", "Hello", "World", "everyOne"}, } for _, v := range args { diff --git a/tests/betweenus_test/main.go b/tests/betweenus_test/main.go index 238aa029..452a9602 100644 --- a/tests/betweenus_test/main.go +++ b/tests/betweenus_test/main.go @@ -10,15 +10,15 @@ import ( func main() { args := [][]int{ {1, 2, 3}, - {1,1,2}, - {10,20,30}, - {20,10,30}, - {200,100,300}, - {-1,0,1}, + {1, 1, 2}, + {10, 20, 30}, + {20, 10, 30}, + {200, 100, 300}, + {-1, 0, 1}, // make sure that the function works with negative numbers - {-1,-1,0}, - {-1,-20,0}, - {-1,-20,-10}, + {-1, -1, 0}, + {-1, -20, 0}, + {-1, -20, -10}, } for _, arg := range args { diff --git a/tests/binaryaddition_test/main.go b/tests/binaryaddition_test/main.go index b3bb09df..3eedddfd 100644 --- a/tests/binaryaddition_test/main.go +++ b/tests/binaryaddition_test/main.go @@ -10,7 +10,7 @@ import ( func main() { table := [][]int{ {1, 1}, - {0,0}, + {0, 0}, {4, 2}, {7, 3}, {2, -1}, @@ -18,7 +18,7 @@ func main() { {3, 4}, {-1, -1}, {100, 303}, - {2147483647,-2147483648}, + {2147483647, -2147483648}, } for _, arg := range table { challenge.Function("BinaryAddition", student.BinaryAddition, solutions.BinaryAddition, arg) diff --git a/tests/countnegative_test/main.go b/tests/countnegative_test/main.go index f8cd3104..b7f94fff 100644 --- a/tests/countnegative_test/main.go +++ b/tests/countnegative_test/main.go @@ -9,10 +9,10 @@ import ( func main() { table := [][]int{ - {10, 10,3,1,2,3,5,3,63}, - {-10, -10,03,1,2,3,5,3,63}, - {0, 0,0,0,0,0,0,0,0}, - {1, 3,-100,39,4,10,-29,-49,92}, + {10, 10, 3, 1, 2, 3, 5, 3, 63}, + {-10, -10, 03, 1, 2, 3, 5, 3, 63}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {1, 3, -100, 39, 4, 10, -29, -49, 92}, {-1}, {23}, {3, -1, -2, -3}, diff --git a/tests/divisors_test/main.go b/tests/divisors_test/main.go index 0e0438e7..5954d948 100644 --- a/tests/divisors_test/main.go +++ b/tests/divisors_test/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - table := []int{1, 2, 3, 4, 9285, 74584, 0, -5585, 75418,99999, -1,526,36} + table := []int{1, 2, 3, 4, 9285, 74584, 0, -5585, 75418, 99999, -1, 526, 36} for _, n := range table { challenge.Function("Divisors", student.Divisors, solutions.Divisors, n) } diff --git a/tests/getarea_test/main.go b/tests/getarea_test/main.go index 7f0fe33f..80d7b2e9 100644 --- a/tests/getarea_test/main.go +++ b/tests/getarea_test/main.go @@ -7,12 +7,12 @@ import ( ) func main() { - table := []string { - "1","2","3","4","5","6","7","8","9","10", - "11","12","13","14","15","16","17","18","19","20", - "01" ,"-1","-2","-3","-4","-5","-6","-7","-8","-9","-10", - "120","1201","1202","1203","1204","1205","1206","1207","1208","1209","1210", - "hello","world"," ","hello world hello","hello world ", + table := []string{ + "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", + "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", + "01", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-10", + "120", "1201", "1202", "1203", "1204", "1205", "1206", "1207", "1208", "1209", "1210", + "hello", "world", " ", "hello world hello", "hello world ", } for _, s := range table { challenge.Program("getarea", strings.Fields(s)...) From a2957901af159a5f269931e415dc20e348d1f0e5 Mon Sep 17 00:00:00 2001 From: hamza Date: Mon, 13 Jun 2022 12:24:00 +0100 Subject: [PATCH 04/56] add(test):arg-rot1 --- solutions/argrot1/main.go | 23 +++++++++++++++++++++++ tests/argrot1_test/main.go | 25 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 solutions/argrot1/main.go create mode 100644 tests/argrot1_test/main.go diff --git a/solutions/argrot1/main.go b/solutions/argrot1/main.go new file mode 100644 index 00000000..d6f07688 --- /dev/null +++ b/solutions/argrot1/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + if len(os.Args) < 3 { + fmt.Println() + return + } + // rot1 alls the args from the second arg to the end + for i := 1; i < len(os.Args); i++ { + if i != len(os.Args)-1 { + fmt.Print(os.Args[i+1]) + fmt.Print(" ") + } else { + fmt.Print(os.Args[1]) + } + } + fmt.Println() +} diff --git a/tests/argrot1_test/main.go b/tests/argrot1_test/main.go new file mode 100644 index 00000000..fc423bbd --- /dev/null +++ b/tests/argrot1_test/main.go @@ -0,0 +1,25 @@ +package main + +import ( + + "github.com/01-edu/go-tests/lib/challenge" +) + +func main() { + args := [][]string{ + {"Hello"}, + {""}, + {"Hello World", "world"}, + {"Hello World", "world", "Hello World"}, + {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}, + {"30", "20", "10", "40", "50", "60", "70", "80", "90", "100"}, + {"A B C D E"},{"4 3 2 1 0"},{"13 233 4 23"}, + {"4 3 2 1 0"},{"A B C D E"}, + {"13 233 4 23"}, + {"1"},{"2"},{"3"},{"4"},{"5"},{"6"},{"7"},{"8"},{"9"},{"10"}, + } + for _, s := range args { + challenge.Program("argrot1", s...) + } + challenge.Program("argrot1", "1", "z", "2") +} From a32e87b985a4194a01dc4b82fc19d729bdc22a03 Mon Sep 17 00:00:00 2001 From: Hamza elkhatri <40549481+Hamzaelkhatri@users.noreply.github.com> Date: Wed, 6 Jul 2022 10:03:35 +0100 Subject: [PATCH 05/56] Update main.go --- tests/argrot1_test/main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/argrot1_test/main.go b/tests/argrot1_test/main.go index fc423bbd..4629b9ce 100644 --- a/tests/argrot1_test/main.go +++ b/tests/argrot1_test/main.go @@ -21,5 +21,4 @@ func main() { for _, s := range args { challenge.Program("argrot1", s...) } - challenge.Program("argrot1", "1", "z", "2") } From e51ae79d9bd026dc27d1ffe3463fc7333c763d92 Mon Sep 17 00:00:00 2001 From: hamza Date: Wed, 6 Jul 2022 14:08:12 +0100 Subject: [PATCH 06/56] fix format --- solutions/argrot1/main.go | 1 - tests/argrot1_test/main.go | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/solutions/argrot1/main.go b/solutions/argrot1/main.go index d6f07688..4bc2c156 100644 --- a/solutions/argrot1/main.go +++ b/solutions/argrot1/main.go @@ -10,7 +10,6 @@ func main() { fmt.Println() return } - // rot1 alls the args from the second arg to the end for i := 1; i < len(os.Args); i++ { if i != len(os.Args)-1 { fmt.Print(os.Args[i+1]) diff --git a/tests/argrot1_test/main.go b/tests/argrot1_test/main.go index 4629b9ce..edf86245 100644 --- a/tests/argrot1_test/main.go +++ b/tests/argrot1_test/main.go @@ -1,7 +1,6 @@ package main import ( - "github.com/01-edu/go-tests/lib/challenge" ) @@ -13,10 +12,10 @@ func main() { {"Hello World", "world", "Hello World"}, {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}, {"30", "20", "10", "40", "50", "60", "70", "80", "90", "100"}, - {"A B C D E"},{"4 3 2 1 0"},{"13 233 4 23"}, - {"4 3 2 1 0"},{"A B C D E"}, + {"A B C D E"}, {"4 3 2 1 0"}, {"13 233 4 23"}, + {"4 3 2 1 0"}, {"A B C D E"}, {"13 233 4 23"}, - {"1"},{"2"},{"3"},{"4"},{"5"},{"6"},{"7"},{"8"},{"9"},{"10"}, + {"1"}, {"2"}, {"3"}, {"4"}, {"5"}, {"6"}, {"7"}, {"8"}, {"9"}, {"10"}, } for _, s := range args { challenge.Program("argrot1", s...) From 786fbb2c4069a298dd0211a4ad07e6a2d48beaa8 Mon Sep 17 00:00:00 2001 From: estlop Date: Thu, 23 Jun 2022 12:05:33 +0100 Subject: [PATCH 07/56] feat: Add solution for oddlength --- solutions/oddlength.go | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 solutions/oddlength.go diff --git a/solutions/oddlength.go b/solutions/oddlength.go new file mode 100644 index 00000000..6b0ef97b --- /dev/null +++ b/solutions/oddlength.go @@ -0,0 +1,11 @@ +package solutions + +func Oddlength(strings []string) []string { + var newSlice []string + for _, str := range strings { + if len(str)%2 == 1 { + newSlice = append(newSlice, str) + } + } + return newSlice +} From d1a7bb04ddedc10af77fe2cc74543de61d426567 Mon Sep 17 00:00:00 2001 From: estlop Date: Thu, 23 Jun 2022 12:07:28 +0100 Subject: [PATCH 08/56] test: Add test for oddlength --- tests/oddlength_test/main.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/oddlength_test/main.go diff --git a/tests/oddlength_test/main.go b/tests/oddlength_test/main.go new file mode 100644 index 00000000..0fceff16 --- /dev/null +++ b/tests/oddlength_test/main.go @@ -0,0 +1,28 @@ +package main + +import ( + student "student" + + "github.com/01-edu/go-tests/lib/challenge" + "github.com/01-edu/go-tests/solutions" +) + +func main() { + args := [][]string{ + {}, + {"A", "b", "C", "d"}, + {"HA", "HI", "UH"}, + {"A", "BE", "c", "DE"}, + {"two", "words", "or", "three"}, + {"café", "fête", "naïve", "façade"}, + { + "Lorem ipsum dolor sit amet,", + " consectetur adipiscing elit,", + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", + }, + } + + for _, arg := range args { + challenge.Function("Oddlength", student.Oddlength, solutions.Oddlength, arg) + } +} From fdb00ec94527c082e41e3ca0636751b2d8b4d034 Mon Sep 17 00:00:00 2001 From: zainabdnaya Date: Thu, 7 Jul 2022 20:28:03 +0100 Subject: [PATCH 09/56] correct format --- tests/oddlength_test/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/oddlength_test/main.go b/tests/oddlength_test/main.go index 0fceff16..b7424e57 100644 --- a/tests/oddlength_test/main.go +++ b/tests/oddlength_test/main.go @@ -16,8 +16,8 @@ func main() { {"two", "words", "or", "three"}, {"café", "fête", "naïve", "façade"}, { - "Lorem ipsum dolor sit amet,", - " consectetur adipiscing elit,", + "Lorem ipsum dolor sit amet,", + " consectetur adipiscing elit,", "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", }, } From 1a60bababc3398bdb524d8010942266d2d835a11 Mon Sep 17 00:00:00 2001 From: estlop Date: Wed, 29 Jun 2022 12:57:29 +0100 Subject: [PATCH 10/56] feat: add solution for prinevenarguments subject --- solutions/printevenarguments/main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solutions/printevenarguments/main.go diff --git a/solutions/printevenarguments/main.go b/solutions/printevenarguments/main.go new file mode 100644 index 00000000..c38cc884 --- /dev/null +++ b/solutions/printevenarguments/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + if len(os.Args) < 2 { + fmt.Println() + return + } + for i, arg := range os.Args[1:] { + if i%2 != 0 { + fmt.Println(arg) + } + } +} From e23ac5d97ed53622b09cc0b59f88e2b0f30c507e Mon Sep 17 00:00:00 2001 From: estlop Date: Wed, 29 Jun 2022 12:57:49 +0100 Subject: [PATCH 11/56] test: add test for printevenarguments subject --- tests/printevenarguments_test/main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/printevenarguments_test/main.go diff --git a/tests/printevenarguments_test/main.go b/tests/printevenarguments_test/main.go new file mode 100644 index 00000000..93194ec4 --- /dev/null +++ b/tests/printevenarguments_test/main.go @@ -0,0 +1,18 @@ +package main + +import "github.com/01-edu/go-tests/lib/challenge" + +func main() { + table := [][]string{ + {}, + {"", "a", "b", "c"}, + {"a", "b", "c", "d"}, + {"Hello", "World", "!"}, + {"Hello", "World", "!"}, + {"Hello", ""}, + {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, + } + for _, arg := range table { + challenge.Program("concatenate", arg...) + } +} From bc559416277c21f2d2112e6aa77cc9e1260c4a17 Mon Sep 17 00:00:00 2001 From: estlop Date: Wed, 29 Jun 2022 13:09:39 +0100 Subject: [PATCH 12/56] Correct wrong program name --- tests/printevenarguments_test/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/printevenarguments_test/main.go b/tests/printevenarguments_test/main.go index 93194ec4..d8955a7a 100644 --- a/tests/printevenarguments_test/main.go +++ b/tests/printevenarguments_test/main.go @@ -13,6 +13,6 @@ func main() { {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, } for _, arg := range table { - challenge.Program("concatenate", arg...) + challenge.Program("printevenarguments", arg...) } } From 766b00e1787354a471f8aa016a3909ec398c5111 Mon Sep 17 00:00:00 2001 From: estlop Date: Mon, 11 Jul 2022 18:54:13 +0100 Subject: [PATCH 13/56] fix: Fix solution as per review --- solutions/printevenarguments/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/printevenarguments/main.go b/solutions/printevenarguments/main.go index c38cc884..d5efd2d7 100644 --- a/solutions/printevenarguments/main.go +++ b/solutions/printevenarguments/main.go @@ -6,7 +6,7 @@ import ( ) func main() { - if len(os.Args) < 2 { + if len(os.Args) <= 2 { fmt.Println() return } From 3c394c3bf3dccae9f071cb22e4772f6423b3a105 Mon Sep 17 00:00:00 2001 From: estlop Date: Mon, 11 Jul 2022 18:56:09 +0100 Subject: [PATCH 14/56] test: Add test case suggested in review --- tests/printevenarguments_test/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/printevenarguments_test/main.go b/tests/printevenarguments_test/main.go index d8955a7a..2531fce9 100644 --- a/tests/printevenarguments_test/main.go +++ b/tests/printevenarguments_test/main.go @@ -5,6 +5,7 @@ import "github.com/01-edu/go-tests/lib/challenge" func main() { table := [][]string{ {}, + {"a"}, {"", "a", "b", "c"}, {"a", "b", "c", "d"}, {"Hello", "World", "!"}, From 08e4316175563e0500f844e24b9db8226692ab5f Mon Sep 17 00:00:00 2001 From: hamza Date: Mon, 13 Jun 2022 10:21:58 +0100 Subject: [PATCH 15/56] add(Test): add solution and test for rev args --- solutions/revargs/main.go | 20 ++++++++++++++++++++ tests/revargs_test/main.go | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 solutions/revargs/main.go create mode 100644 tests/revargs_test/main.go diff --git a/solutions/revargs/main.go b/solutions/revargs/main.go new file mode 100644 index 00000000..e4012dc7 --- /dev/null +++ b/solutions/revargs/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + if len(os.Args) < 2 { + fmt.Println() + return + } + for i := len(os.Args) - 1; i >= 1; i-- { + fmt.Print(os.Args[i]) + if i != 1 { + fmt.Print(" ") + } + } + fmt.Println() +} \ No newline at end of file diff --git a/tests/revargs_test/main.go b/tests/revargs_test/main.go new file mode 100644 index 00000000..9764b59f --- /dev/null +++ b/tests/revargs_test/main.go @@ -0,0 +1,24 @@ +package main + +import ( + + "github.com/01-edu/go-tests/lib/challenge" +) + +func main() { + args := [][]string{ + {"Hello"}, + {""}, + {"Hello World", "world"}, + {"Hello World", "world", "Hello World"}, + {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}, + {"30", "20", "10", "40", "50", "60", "70", "80", "90", "100"}, + {"A B C D E"}, + {"4 3 2 1 0"}, + {"13 233 4 23"}, + } + for _, s := range args { + challenge.Program("revarg", s...) + } + challenge.Program("revarg", "1", "z") +} From 26b1ed8377b6d08c765821607cd1dba0259c5b82 Mon Sep 17 00:00:00 2001 From: Hamza elkhatri <40549481+Hamzaelkhatri@users.noreply.github.com> Date: Wed, 22 Jun 2022 12:42:48 +0100 Subject: [PATCH 16/56] Update main.go --- solutions/revargs/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/revargs/main.go b/solutions/revargs/main.go index e4012dc7..5c349ee6 100644 --- a/solutions/revargs/main.go +++ b/solutions/revargs/main.go @@ -17,4 +17,4 @@ func main() { } } fmt.Println() -} \ No newline at end of file +} From c46e63f46a1aa04f7448d1240581f90b2e90ec39 Mon Sep 17 00:00:00 2001 From: Hamza elkhatri <40549481+Hamzaelkhatri@users.noreply.github.com> Date: Wed, 22 Jun 2022 12:43:16 +0100 Subject: [PATCH 17/56] Update main.go --- tests/revargs_test/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/revargs_test/main.go b/tests/revargs_test/main.go index 9764b59f..d53a9ad0 100644 --- a/tests/revargs_test/main.go +++ b/tests/revargs_test/main.go @@ -18,7 +18,7 @@ func main() { {"13 233 4 23"}, } for _, s := range args { - challenge.Program("revarg", s...) + challenge.Program("revargs", s...) } - challenge.Program("revarg", "1", "z") + challenge.Program("revargs", "1", "z") } From c5ec42f21fdcfa23fbb06bb658a93efe12252963 Mon Sep 17 00:00:00 2001 From: Hamza elkhatri <40549481+Hamzaelkhatri@users.noreply.github.com> Date: Tue, 28 Jun 2022 16:40:52 +0100 Subject: [PATCH 18/56] Update main.go --- tests/revargs_test/main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/revargs_test/main.go b/tests/revargs_test/main.go index d53a9ad0..db3dafeb 100644 --- a/tests/revargs_test/main.go +++ b/tests/revargs_test/main.go @@ -20,5 +20,4 @@ func main() { for _, s := range args { challenge.Program("revargs", s...) } - challenge.Program("revargs", "1", "z") } From a181bc53add02906794bff3bb20c114b4ee8abe4 Mon Sep 17 00:00:00 2001 From: MSilva95 <53977751+MSilva95@users.noreply.github.com> Date: Fri, 8 Jul 2022 12:27:28 +0100 Subject: [PATCH 19/56] add empty --- tests/revargs_test/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/revargs_test/main.go b/tests/revargs_test/main.go index db3dafeb..1f6620ab 100644 --- a/tests/revargs_test/main.go +++ b/tests/revargs_test/main.go @@ -9,6 +9,7 @@ func main() { args := [][]string{ {"Hello"}, {""}, + {}, {"Hello World", "world"}, {"Hello World", "world", "Hello World"}, {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}, From 24bc64162cdb8103fe1542699158ba648b23f255 Mon Sep 17 00:00:00 2001 From: hamza Date: Mon, 13 Jun 2022 10:36:59 +0100 Subject: [PATCH 20/56] add(test): printmiddle --- solutions/printmiddle/main.go | 20 ++++++++++++++++++++ tests/printmiddle_test/main.go | 25 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 solutions/printmiddle/main.go create mode 100644 tests/printmiddle_test/main.go diff --git a/solutions/printmiddle/main.go b/solutions/printmiddle/main.go new file mode 100644 index 00000000..723cd7c3 --- /dev/null +++ b/solutions/printmiddle/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + if len(os.Args) < 2 { + fmt.Println() + return + } + args := os.Args[1:] + + if len(args) % 2 == 0 { + fmt.Println(args[len(args)/2-1] + " " + args[len(args)/2]) + } else { + fmt.Println(args[len(args)/2]) + } +} \ No newline at end of file diff --git a/tests/printmiddle_test/main.go b/tests/printmiddle_test/main.go new file mode 100644 index 00000000..08bd3c33 --- /dev/null +++ b/tests/printmiddle_test/main.go @@ -0,0 +1,25 @@ +package main + +import ( + + "github.com/01-edu/go-tests/lib/challenge" +) + +func main() { + args := [][]string{ + {"Hello"}, + {""}, + {"Hello World", "world"}, + {"Hello World", "world", "Hello World"}, + {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}, + {"30", "20", "10", "40", "50", "60", "70", "80", "90", "100"}, + {"A B C D E"},{"4 3 2 1 0"},{"13 233 4 23"}, + {"4 3 2 1 0"},{"A B C D E"}, + {"13 233 4 23"}, + {"1"}, + } + for _, s := range args { + challenge.Program("printmiddle", s...) + } + challenge.Program("printmiddle", "1", "z", "1") +} From 004f0f827e0a2b944ba8f52378d6f57d46d2a815 Mon Sep 17 00:00:00 2001 From: Hamza elkhatri <40549481+Hamzaelkhatri@users.noreply.github.com> Date: Thu, 23 Jun 2022 14:33:42 +0100 Subject: [PATCH 21/56] Update main.go --- solutions/printmiddle/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/printmiddle/main.go b/solutions/printmiddle/main.go index 723cd7c3..f46ebc3a 100644 --- a/solutions/printmiddle/main.go +++ b/solutions/printmiddle/main.go @@ -17,4 +17,4 @@ func main() { } else { fmt.Println(args[len(args)/2]) } -} \ No newline at end of file +} From 815a83c1c6d7a830953271507bfccbd17cb83898 Mon Sep 17 00:00:00 2001 From: Hamza elkhatri <40549481+Hamzaelkhatri@users.noreply.github.com> Date: Fri, 24 Jun 2022 11:07:42 +0100 Subject: [PATCH 22/56] Update main.go --- tests/printmiddle_test/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/printmiddle_test/main.go b/tests/printmiddle_test/main.go index 08bd3c33..7a68ae38 100644 --- a/tests/printmiddle_test/main.go +++ b/tests/printmiddle_test/main.go @@ -17,9 +17,9 @@ func main() { {"4 3 2 1 0"},{"A B C D E"}, {"13 233 4 23"}, {"1"}, + {"1", "z", "1"}, } for _, s := range args { challenge.Program("printmiddle", s...) } - challenge.Program("printmiddle", "1", "z", "1") } From 39f6b81ff208103c0cd918ea0f5eaffbd5db19dd Mon Sep 17 00:00:00 2001 From: hamza Date: Thu, 7 Jul 2022 17:54:00 +0100 Subject: [PATCH 23/56] fix format --- solutions/printmiddle/main.go | 20 ++++++++++---------- tests/printmiddle_test/main.go | 5 ++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/solutions/printmiddle/main.go b/solutions/printmiddle/main.go index f46ebc3a..83621dae 100644 --- a/solutions/printmiddle/main.go +++ b/solutions/printmiddle/main.go @@ -1,20 +1,20 @@ package main import ( - "fmt" - "os" + "fmt" + "os" ) func main() { if len(os.Args) < 2 { fmt.Println() - return - } + return + } args := os.Args[1:] - - if len(args) % 2 == 0 { - fmt.Println(args[len(args)/2-1] + " " + args[len(args)/2]) - } else { - fmt.Println(args[len(args)/2]) - } + + if len(args)%2 == 0 { + fmt.Println(args[len(args)/2-1] + " " + args[len(args)/2]) + } else { + fmt.Println(args[len(args)/2]) + } } diff --git a/tests/printmiddle_test/main.go b/tests/printmiddle_test/main.go index 7a68ae38..eb8d6fdd 100644 --- a/tests/printmiddle_test/main.go +++ b/tests/printmiddle_test/main.go @@ -1,7 +1,6 @@ package main import ( - "github.com/01-edu/go-tests/lib/challenge" ) @@ -13,8 +12,8 @@ func main() { {"Hello World", "world", "Hello World"}, {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}, {"30", "20", "10", "40", "50", "60", "70", "80", "90", "100"}, - {"A B C D E"},{"4 3 2 1 0"},{"13 233 4 23"}, - {"4 3 2 1 0"},{"A B C D E"}, + {"A B C D E"}, {"4 3 2 1 0"}, {"13 233 4 23"}, + {"4 3 2 1 0"}, {"A B C D E"}, {"13 233 4 23"}, {"1"}, {"1", "z", "1"}, From 4ceeb0bd04d03f31abb8c65d972260a2d30cec1a Mon Sep 17 00:00:00 2001 From: MSilva95 <53977751+MSilva95@users.noreply.github.com> Date: Fri, 8 Jul 2022 10:35:02 +0100 Subject: [PATCH 24/56] add empty case --- tests/printmiddle_test/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/printmiddle_test/main.go b/tests/printmiddle_test/main.go index eb8d6fdd..e2e09091 100644 --- a/tests/printmiddle_test/main.go +++ b/tests/printmiddle_test/main.go @@ -7,6 +7,7 @@ import ( func main() { args := [][]string{ {"Hello"}, + {}, {""}, {"Hello World", "world"}, {"Hello World", "world", "Hello World"}, From 84845247ace41d9146e97454d3dd0cf8264199aa Mon Sep 17 00:00:00 2001 From: estlop Date: Fri, 24 Jun 2022 10:22:13 +0100 Subject: [PATCH 25/56] feat: Add solution for popint subject --- solutions/popint.go | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 solutions/popint.go diff --git a/solutions/popint.go b/solutions/popint.go new file mode 100644 index 00000000..3b998c40 --- /dev/null +++ b/solutions/popint.go @@ -0,0 +1,8 @@ +package solutions + +func PopInt(ints []int) []int { + if len(ints) == 0 { + return ints + } + return ints[:len(ints)-1] +} From 1c0e9ba798f3e251c20a7853fe2e70d43a01ef43 Mon Sep 17 00:00:00 2001 From: estlop Date: Fri, 24 Jun 2022 10:27:11 +0100 Subject: [PATCH 26/56] test: Add test for popint subject --- tests/popint_test/main.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/popint_test/main.go diff --git a/tests/popint_test/main.go b/tests/popint_test/main.go new file mode 100644 index 00000000..fb091ae0 --- /dev/null +++ b/tests/popint_test/main.go @@ -0,0 +1,22 @@ +package main + +import ( + student "student" + + "github.com/01-edu/go-tests/lib/challenge" + "github.com/01-edu/go-tests/solutions" +) + +func main() { + + args := [][]int{ + {1, 3, 5}, + {-1, -2, 3}, + {}, + {22134, 2345345, 575672, 2567567, 2456456, 2345345}, + } + + for _, arg := range args { + challenge.Function("PopInt", student.PopInt, solutions.PopInt, arg) + } +} From 0b5cfdfff8fff24780b0870b148a39c6d2a6595d Mon Sep 17 00:00:00 2001 From: hamza Date: Wed, 8 Jun 2022 23:15:24 +0100 Subject: [PATCH 27/56] add(test):add test & solution --- tests/printrange_test/main.go | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/printrange_test/main.go diff --git a/tests/printrange_test/main.go b/tests/printrange_test/main.go new file mode 100644 index 00000000..f371ac02 --- /dev/null +++ b/tests/printrange_test/main.go @@ -0,0 +1,36 @@ +package main + +import ( + student "student" + + "github.com/01-edu/go-tests/lib/challenge" + // "github.com/01-edu/go-tests/lib/random" +) + +func solutions(n int, n2 int) string { + solutions := map[[2]int]string{ + [2]int{1, 10}: "1 2 3 4 5 6 7 8 9 9\n", + [2]int{10, 1}: "10 9 8 7 6 5 4 3 2 1\n", + [2]int{1, 1}: "1\n", + [2]int{10, 10}: "\n", + [2]int{0, 9}: "0 1 2 3 4 5 6 7 8 9\n", + [2]int{-1, -10}: "\n", + [2]int{-10, -1}: "\n", + [2]int{-1, 9}: "0 1 2 3 4 5 6 7 8 9\n", + } + return solutions[[2]int{n, n2}] +} + +func main() { + args := [][]int{ + {1, 10}, + {10, 1}, + {1, 1}, + {10, 10}, + {0, 9}, + {-1, -10}, + {-10, -1}, + {-1, 9}, + } + challenge.Function("printRange", student.printRange,solutions, args) +} From 631befe9cb8ea09a00a3228c1cd57780a4dacd69 Mon Sep 17 00:00:00 2001 From: hamza Date: Thu, 9 Jun 2022 13:22:33 +0100 Subject: [PATCH 28/56] fix(test):fix func name & test --- solutions/printrange.go | 36 ++++++++++++++++++++ tests/printrange_test/main.go | 62 ++++++++++++++++++++++++++++------- 2 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 solutions/printrange.go diff --git a/solutions/printrange.go b/solutions/printrange.go new file mode 100644 index 00000000..f59cebc7 --- /dev/null +++ b/solutions/printrange.go @@ -0,0 +1,36 @@ +package solutions + +import "github.com/01-edu/z01" + +func printRange(n, m int) { + if n < 0 && m < 0 || n > 9 && m > 9 { + z01.PrintRune('\n') + return + } + if n < 0 { + n = 0 + } else if n > 9 { + n = 9 + } + if m < 0 { + m = 0 + } else if m > 9 { + m = 9 + } + if n > m { + for i := n; i >= m; i-- { + z01.PrintRune(rune(i) + '0') + if i != m { + z01.PrintRune(' ') + } + } + } else { + for i := n; i <= m; i++ { + z01.PrintRune(rune(i) + '0') + if i != m { + z01.PrintRune(' ') + } + } + } + z01.PrintRune('\n') +} \ No newline at end of file diff --git a/tests/printrange_test/main.go b/tests/printrange_test/main.go index f371ac02..ea8b0d5a 100644 --- a/tests/printrange_test/main.go +++ b/tests/printrange_test/main.go @@ -4,23 +4,59 @@ import ( student "student" "github.com/01-edu/go-tests/lib/challenge" + "github.com/01-edu/z01" // "github.com/01-edu/go-tests/lib/random" ) -func solutions(n int, n2 int) string { - solutions := map[[2]int]string{ - [2]int{1, 10}: "1 2 3 4 5 6 7 8 9 9\n", - [2]int{10, 1}: "10 9 8 7 6 5 4 3 2 1\n", - [2]int{1, 1}: "1\n", - [2]int{10, 10}: "\n", - [2]int{0, 9}: "0 1 2 3 4 5 6 7 8 9\n", - [2]int{-1, -10}: "\n", - [2]int{-10, -1}: "\n", - [2]int{-1, 9}: "0 1 2 3 4 5 6 7 8 9\n", +// func solutions(n int, n2 int) string { +// solutions := map[[2]int]string{ +// [2]int{1, 10}: "1 2 3 4 5 6 7 8 9 9\n", +// [2]int{10, 1}: "10 9 8 7 6 5 4 3 2 1\n", +// [2]int{1, 1}: "1\n", +// [2]int{10, 10}: "\n", +// [2]int{0, 9}: "0 1 2 3 4 5 6 7 8 9\n", +// [2]int{-1, -10}: "\n", +// [2]int{-10, -1}: "\n", +// [2]int{-1, 9}: "0 1 2 3 4 5 6 7 8 9\n", +// } +// return solutions[[2]int{n, n2}] +// } + + +func printRange(n, m int) { + if n < 0 && m < 0 || n > 9 && m > 9 { + z01.PrintRune('\n') + return + } + if n < 0 { + n = 0 + } else if n > 9 { + n = 9 + } + if m < 0 { + m = 0 + } else if m > 9 { + m = 9 } - return solutions[[2]int{n, n2}] + if n > m { + for i := n; i >= m; i-- { + z01.PrintRune(rune(i) + '0') + if i != m { + z01.PrintRune(' ') + } + } + } else { + for i := n; i <= m; i++ { + z01.PrintRune(rune(i) + '0') + if i != m { + z01.PrintRune(' ') + } + } + } + z01.PrintRune('\n') } + func main() { args := [][]int{ {1, 10}, @@ -32,5 +68,7 @@ func main() { {-10, -1}, {-1, 9}, } - challenge.Function("printRange", student.printRange,solutions, args) + for _, arg := range args { + challenge.Function("printRange", student.PrintRange,printRange, arg[0], arg[1]) + } } From cef29cc03ff705540a6fa44f75147f561ee41410 Mon Sep 17 00:00:00 2001 From: hamza Date: Thu, 9 Jun 2022 13:22:53 +0100 Subject: [PATCH 29/56] fix(prototype):fix name --- solutions/printrange.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/printrange.go b/solutions/printrange.go index f59cebc7..61296593 100644 --- a/solutions/printrange.go +++ b/solutions/printrange.go @@ -2,7 +2,7 @@ package solutions import "github.com/01-edu/z01" -func printRange(n, m int) { +func PrintRange(n, m int) { if n < 0 && m < 0 || n > 9 && m > 9 { z01.PrintRune('\n') return From 389cc1b9e866a0b82565e26896f772de95df41c6 Mon Sep 17 00:00:00 2001 From: Hamza elkhatri <40549481+Hamzaelkhatri@users.noreply.github.com> Date: Fri, 17 Jun 2022 21:15:58 +0100 Subject: [PATCH 30/56] Update main.go --- tests/printrange_test/main.go | 53 ++--------------------------------- 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/tests/printrange_test/main.go b/tests/printrange_test/main.go index ea8b0d5a..e9bd42b2 100644 --- a/tests/printrange_test/main.go +++ b/tests/printrange_test/main.go @@ -5,58 +5,9 @@ import ( "github.com/01-edu/go-tests/lib/challenge" "github.com/01-edu/z01" - // "github.com/01-edu/go-tests/lib/random" + "github.com/01-edu/go-tests/solutions" ) -// func solutions(n int, n2 int) string { -// solutions := map[[2]int]string{ -// [2]int{1, 10}: "1 2 3 4 5 6 7 8 9 9\n", -// [2]int{10, 1}: "10 9 8 7 6 5 4 3 2 1\n", -// [2]int{1, 1}: "1\n", -// [2]int{10, 10}: "\n", -// [2]int{0, 9}: "0 1 2 3 4 5 6 7 8 9\n", -// [2]int{-1, -10}: "\n", -// [2]int{-10, -1}: "\n", -// [2]int{-1, 9}: "0 1 2 3 4 5 6 7 8 9\n", -// } -// return solutions[[2]int{n, n2}] -// } - - -func printRange(n, m int) { - if n < 0 && m < 0 || n > 9 && m > 9 { - z01.PrintRune('\n') - return - } - if n < 0 { - n = 0 - } else if n > 9 { - n = 9 - } - if m < 0 { - m = 0 - } else if m > 9 { - m = 9 - } - if n > m { - for i := n; i >= m; i-- { - z01.PrintRune(rune(i) + '0') - if i != m { - z01.PrintRune(' ') - } - } - } else { - for i := n; i <= m; i++ { - z01.PrintRune(rune(i) + '0') - if i != m { - z01.PrintRune(' ') - } - } - } - z01.PrintRune('\n') -} - - func main() { args := [][]int{ {1, 10}, @@ -69,6 +20,6 @@ func main() { {-1, 9}, } for _, arg := range args { - challenge.Function("printRange", student.PrintRange,printRange, arg[0], arg[1]) + challenge.Function("PrintRange", student.PrintRange,solutions.PrintRange, arg[0], arg[1]) } } From 240e52e918b292029fc78c46df7d2323b74a2c08 Mon Sep 17 00:00:00 2001 From: hamza Date: Fri, 24 Jun 2022 18:35:45 +0100 Subject: [PATCH 31/56] fix:format & remove unsed library --- solutions/printrange.go | 2 +- tests/printrange_test/main.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/solutions/printrange.go b/solutions/printrange.go index 61296593..16bbf09c 100644 --- a/solutions/printrange.go +++ b/solutions/printrange.go @@ -33,4 +33,4 @@ func PrintRange(n, m int) { } } z01.PrintRune('\n') -} \ No newline at end of file +} diff --git a/tests/printrange_test/main.go b/tests/printrange_test/main.go index e9bd42b2..25478975 100644 --- a/tests/printrange_test/main.go +++ b/tests/printrange_test/main.go @@ -4,7 +4,6 @@ import ( student "student" "github.com/01-edu/go-tests/lib/challenge" - "github.com/01-edu/z01" "github.com/01-edu/go-tests/solutions" ) @@ -20,6 +19,6 @@ func main() { {-1, 9}, } for _, arg := range args { - challenge.Function("PrintRange", student.PrintRange,solutions.PrintRange, arg[0], arg[1]) + challenge.Function("PrintRange", student.PrintRange, solutions.PrintRange, arg[0], arg[1]) } } From f73cb9b4cb799bafa835618dc17ee221121115a2 Mon Sep 17 00:00:00 2001 From: Hamza elkhatri <40549481+Hamzaelkhatri@users.noreply.github.com> Date: Tue, 28 Jun 2022 15:20:32 +0100 Subject: [PATCH 32/56] Update main.go --- tests/printrange_test/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/printrange_test/main.go b/tests/printrange_test/main.go index 25478975..b71033d0 100644 --- a/tests/printrange_test/main.go +++ b/tests/printrange_test/main.go @@ -17,6 +17,8 @@ func main() { {-1, -10}, {-10, -1}, {-1, 9}, + {-10, 15}, + {10, -15}, } for _, arg := range args { challenge.Function("PrintRange", student.PrintRange, solutions.PrintRange, arg[0], arg[1]) From c05deee1f74522350bfc6e78d6405143e7af6ae5 Mon Sep 17 00:00:00 2001 From: hamza Date: Thu, 16 Jun 2022 14:52:24 +0100 Subject: [PATCH 33/56] test(swap-args):add test & solution --- solutions/swapargs/main.go | 20 ++++++++++++++++++++ tests/swapargs_test/main.go | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 solutions/swapargs/main.go create mode 100644 tests/swapargs_test/main.go diff --git a/solutions/swapargs/main.go b/solutions/swapargs/main.go new file mode 100644 index 00000000..f492889a --- /dev/null +++ b/solutions/swapargs/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "github.com/01-edu/z01" + "os" +) + +func main() { + if len(os.Args) != 3 { + z01.PrintRune('\n') + return + } + for i := 0; i < len(os.Args[2]); i++ { + z01.PrintRune(rune(os.Args[2][i])) + } + for i := 0; i < len(os.Args[1]); i++ { + z01.PrintRune(rune(os.Args[1][i])) + } + z01.PrintRune('\n') +} diff --git a/tests/swapargs_test/main.go b/tests/swapargs_test/main.go new file mode 100644 index 00000000..a2f74dbb --- /dev/null +++ b/tests/swapargs_test/main.go @@ -0,0 +1,19 @@ +package main + +import ( + "github.com/01-edu/go-tests/lib/challenge" +) + +func main() { + table := [][]string{ + {"choumi", "is", "the", "best", "cat"}, + {" "}, + {""}, + {"hello", "world"}, + {"1", "2"}, + {"", " "}, + } + for _, s := range table { + challenge.Program("printparams", s...) + } +} From 3e9cfde20777cef96ed1b0a4cdcafdf35f7f28c7 Mon Sep 17 00:00:00 2001 From: hamza Date: Fri, 24 Jun 2022 18:30:38 +0100 Subject: [PATCH 34/56] fix:name of program --- tests/swapargs_test/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/swapargs_test/main.go b/tests/swapargs_test/main.go index a2f74dbb..6b40841f 100644 --- a/tests/swapargs_test/main.go +++ b/tests/swapargs_test/main.go @@ -14,6 +14,6 @@ func main() { {"", " "}, } for _, s := range table { - challenge.Program("printparams", s...) + challenge.Program("swapargs", s...) } } From 054b6fee10f90fe84bd7e2670a629b49b167ce24 Mon Sep 17 00:00:00 2001 From: hamza Date: Mon, 27 Jun 2022 10:35:53 +0100 Subject: [PATCH 35/56] fix: space between args --- solutions/swapargs/main.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/solutions/swapargs/main.go b/solutions/swapargs/main.go index f492889a..eee5c490 100644 --- a/solutions/swapargs/main.go +++ b/solutions/swapargs/main.go @@ -1,20 +1,14 @@ package main import ( - "github.com/01-edu/z01" + "fmt" "os" ) func main() { if len(os.Args) != 3 { - z01.PrintRune('\n') + fmt.Println("") return } - for i := 0; i < len(os.Args[2]); i++ { - z01.PrintRune(rune(os.Args[2][i])) - } - for i := 0; i < len(os.Args[1]); i++ { - z01.PrintRune(rune(os.Args[1][i])) - } - z01.PrintRune('\n') + fmt.Println(os.Args[2] + " " + os.Args[1]) } From 668304c31213d62578b04dce81a8cb1279c9eb01 Mon Sep 17 00:00:00 2001 From: estlop Date: Wed, 29 Jun 2022 11:50:00 +0100 Subject: [PATCH 36/56] Add solution for concatenate subject --- solutions/concatenate/main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solutions/concatenate/main.go diff --git a/solutions/concatenate/main.go b/solutions/concatenate/main.go new file mode 100644 index 00000000..79bf8fb8 --- /dev/null +++ b/solutions/concatenate/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + if len(os.Args) < 2 { + fmt.Println() + return + } + result := "" + for _, arg := range os.Args[1:] { + result += arg + } + fmt.Println(result) +} From 05ee99f3a44644d9aedcc392df270d9730fdc402 Mon Sep 17 00:00:00 2001 From: estlop Date: Wed, 29 Jun 2022 11:50:44 +0100 Subject: [PATCH 37/56] test: Add tests for concatenate subject --- tests/concatenate_test/main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/concatenate_test/main.go diff --git a/tests/concatenate_test/main.go b/tests/concatenate_test/main.go new file mode 100644 index 00000000..83168974 --- /dev/null +++ b/tests/concatenate_test/main.go @@ -0,0 +1,17 @@ +package main + +import "github.com/01-edu/go-tests/lib/challenge" + +func main() { + table := [][]string{ + {"", "a", "b", "c"}, + {"a", "b", "c", "d"}, + {"Hello", "World", "!"}, + {"Hello", "World", "!"}, + {"Hello", ""}, + {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, + } + for _, arg := range table { + challenge.Program("concatenate", arg...) + } +} From 6e8c5b15bb98bc2501fa85e676742c717437df7d Mon Sep 17 00:00:00 2001 From: estlop Date: Wed, 29 Jun 2022 12:02:21 +0100 Subject: [PATCH 38/56] Add missing test --- tests/concatenate_test/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/concatenate_test/main.go b/tests/concatenate_test/main.go index 83168974..93194ec4 100644 --- a/tests/concatenate_test/main.go +++ b/tests/concatenate_test/main.go @@ -4,6 +4,7 @@ import "github.com/01-edu/go-tests/lib/challenge" func main() { table := [][]string{ + {}, {"", "a", "b", "c"}, {"a", "b", "c", "d"}, {"Hello", "World", "!"}, From 2892f2207f599951fe9bd156f9c4d90aa5f4839b Mon Sep 17 00:00:00 2001 From: estlop Date: Fri, 1 Jul 2022 12:44:34 +0100 Subject: [PATCH 39/56] test: Add test cases as per review --- tests/concatenate_test/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/concatenate_test/main.go b/tests/concatenate_test/main.go index 93194ec4..57b68b60 100644 --- a/tests/concatenate_test/main.go +++ b/tests/concatenate_test/main.go @@ -11,6 +11,8 @@ func main() { {"Hello", "World", "!"}, {"Hello", ""}, {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, + {"hello there", "how are you?"}, + {"hello there", " "}, } for _, arg := range table { challenge.Program("concatenate", arg...) From 98df52d20ad493a263a6c6feb6c9917122dc8ae6 Mon Sep 17 00:00:00 2001 From: estlop Date: Wed, 29 Jun 2022 11:00:33 +0100 Subject: [PATCH 40/56] feat: Add solution for sum subject --- solutions/sum.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 solutions/sum.go diff --git a/solutions/sum.go b/solutions/sum.go new file mode 100644 index 00000000..a4f23675 --- /dev/null +++ b/solutions/sum.go @@ -0,0 +1,14 @@ +package solutions + +import ( + "strconv" +) + +func Sum(a, b string) int { + numA, _ := strconv.Atoi(a) + numB, _ := strconv.Atoi(b) + if numA > 9 || numA < -9 || numB > 9 || numB < -9 { + return 0 + } + return numA + numB +} From 30896bcfcc47c7d5aceb738f6105a6b140ba6924 Mon Sep 17 00:00:00 2001 From: estlop Date: Wed, 29 Jun 2022 11:01:33 +0100 Subject: [PATCH 41/56] test: Add test for sum subject --- tests/sum_test/main.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/sum_test/main.go diff --git a/tests/sum_test/main.go b/tests/sum_test/main.go new file mode 100644 index 00000000..113d5b3b --- /dev/null +++ b/tests/sum_test/main.go @@ -0,0 +1,24 @@ +package main + +import ( + student "student" + + "github.com/01-edu/go-tests/lib/challenge" + "github.com/01-edu/go-tests/solutions" +) + +func main() { + args := [][]string{ + {"0", "0"}, + {"1", "0"}, + {"0", "1"}, + {"1", "2"}, + {"9", "9"}, + {"-9", "-9"}, + {"-3", "7"}, + {"8", "-7"}, + } + for _, arg := range args { + challenge.Function("Sum", student.Sum, solutions.Sum, arg[0], arg[1]) + } +} From b4a12555d099814b6c179bc601fb921cade96593 Mon Sep 17 00:00:00 2001 From: estlop Date: Wed, 29 Jun 2022 13:14:54 +0100 Subject: [PATCH 42/56] test: add missing test cases --- tests/sum_test/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/sum_test/main.go b/tests/sum_test/main.go index 113d5b3b..b8c2587d 100644 --- a/tests/sum_test/main.go +++ b/tests/sum_test/main.go @@ -17,6 +17,8 @@ func main() { {"-9", "-9"}, {"-3", "7"}, {"8", "-7"}, + {"11", "7"}, + {"6", "256"}, } for _, arg := range args { challenge.Function("Sum", student.Sum, solutions.Sum, arg[0], arg[1]) From 465d7013d4a45866bc2d998300dbb901be9bf3cb Mon Sep 17 00:00:00 2001 From: estlop Date: Thu, 30 Jun 2022 11:46:15 +0100 Subject: [PATCH 43/56] feat: Implement solution for evenlength subject --- solutions/evenlength.go | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 solutions/evenlength.go diff --git a/solutions/evenlength.go b/solutions/evenlength.go new file mode 100644 index 00000000..3bed7746 --- /dev/null +++ b/solutions/evenlength.go @@ -0,0 +1,11 @@ +package solutions + +func EvenLength(strings []string) []string { + var newSlice []string + for _, str := range strings { + if len(str)%2 == 0 { + newSlice = append(newSlice, str) + } + } + return newSlice +} From a22ea61a55417ce3f5cd755782a59f0d646dd897 Mon Sep 17 00:00:00 2001 From: estlop Date: Thu, 30 Jun 2022 11:47:21 +0100 Subject: [PATCH 44/56] test: Implement test for evenlength subject --- tests/evenlength_test/main.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/evenlength_test/main.go diff --git a/tests/evenlength_test/main.go b/tests/evenlength_test/main.go new file mode 100644 index 00000000..893df8d4 --- /dev/null +++ b/tests/evenlength_test/main.go @@ -0,0 +1,28 @@ +package main + +import ( + student "student" + + "github.com/01-edu/go-tests/lib/challenge" + "github.com/01-edu/go-tests/solutions" +) + +func main() { + args := [][]string{ + {}, + {"A", "b", "C", "d"}, + {"HA", "HI", "UH"}, + {"A", "BE", "c", "DE"}, + {"two", "words", "or", "three"}, + {"café", "fête", "naïve", "façade"}, + { + "Lorem ipsum dolor sit amet,", + " consectetur adipiscing elit,", + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", + }, + } + + for _, arg := range args { + challenge.Function("EvenLength", student.EvenLength, solutions.EvenLength, arg) + } +} From b52f9a0a825da6978d096dbf0021ab5b6662eb22 Mon Sep 17 00:00:00 2001 From: estlop Date: Thu, 30 Jun 2022 13:20:05 +0100 Subject: [PATCH 45/56] feat: Add solution for delete subject --- solutions/delete.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 solutions/delete.go diff --git a/solutions/delete.go b/solutions/delete.go new file mode 100644 index 00000000..b938a16d --- /dev/null +++ b/solutions/delete.go @@ -0,0 +1,15 @@ +package solutions + +func Delete(ints []int, position int) []int { + if position > len(ints)-1 { + return ints + } + result := []int{} + for i, integer := range ints { + if i == position-1 { + continue + } + result = append(result, integer) + } + return result +} From 44c263eabdf91c395d564e7f812c052f6bf94d78 Mon Sep 17 00:00:00 2001 From: estlop Date: Thu, 30 Jun 2022 13:20:30 +0100 Subject: [PATCH 46/56] test: Write test for delete subject --- tests/delete_test/main.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/delete_test/main.go diff --git a/tests/delete_test/main.go b/tests/delete_test/main.go new file mode 100644 index 00000000..0cc211e4 --- /dev/null +++ b/tests/delete_test/main.go @@ -0,0 +1,23 @@ +package main + +import ( + student "student" + + "github.com/01-edu/go-tests/lib/challenge" + "github.com/01-edu/go-tests/solutions" +) + +func main() { + intsArgs := [][]int{ + {}, + {}, + {1, 2, 3, 4, 5}, + {1, 2}, + {23, 25, 26, 65}, + {98, 345, 456}, + } + positionArgs := []int{0, 1, 6, 1, 3, 2} + for index, arg := range intsArgs { + challenge.Function("Delete", student.Delete, solutions.Delete, arg, positionArgs[index]) + } +} From 8ce3d00cf93ce9922b697dda6040c3a5b8c70ef5 Mon Sep 17 00:00:00 2001 From: estlop Date: Wed, 22 Jun 2022 13:42:36 +0100 Subject: [PATCH 47/56] feat: Add solution to pingpong subject --- solutions/pingpong/main.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 solutions/pingpong/main.go diff --git a/solutions/pingpong/main.go b/solutions/pingpong/main.go new file mode 100644 index 00000000..70779349 --- /dev/null +++ b/solutions/pingpong/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "os" + "strconv" +) + +func main() { + if len(os.Args) != 2 { + return + } + num, err := strconv.Atoi(os.Args[1]) + if err != nil { + fmt.Println(err.Error()) + return + } + + for i := 0; i < num; i++ { + if i%2 == 0 { + fmt.Println(strconv.Itoa(i) + " ping") + continue + } + fmt.Println(strconv.Itoa(i) + " pong") + } +} \ No newline at end of file From d71320234564db208831cda6541d965199e33404 Mon Sep 17 00:00:00 2001 From: estlop Date: Wed, 22 Jun 2022 13:45:00 +0100 Subject: [PATCH 48/56] test: Add test for pingpong subject --- tests/pingpong_test/main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/pingpong_test/main.go diff --git a/tests/pingpong_test/main.go b/tests/pingpong_test/main.go new file mode 100644 index 00000000..74b152dc --- /dev/null +++ b/tests/pingpong_test/main.go @@ -0,0 +1,18 @@ +package main + +import "github.com/01-edu/go-tests/lib/challenge" + +func main() { + args := [][]string{ + {""}, + {"0"}, + {"3", "5"}, + {"5"}, + {"9"}, + {"24"}, + {"99"}, + } + for _, arg := range args { + challenge.Program("pingpong", arg...) + } +} From 67e08e3d456c7b5c270042fb48f545288aa03d17 Mon Sep 17 00:00:00 2001 From: estlop Date: Wed, 22 Jun 2022 13:46:14 +0100 Subject: [PATCH 49/56] test: add one more test case --- tests/pingpong_test/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/pingpong_test/main.go b/tests/pingpong_test/main.go index 74b152dc..299fdb4a 100644 --- a/tests/pingpong_test/main.go +++ b/tests/pingpong_test/main.go @@ -11,6 +11,7 @@ func main() { {"9"}, {"24"}, {"99"}, + {"100"}, } for _, arg := range args { challenge.Program("pingpong", arg...) From c89483611c4d0a55589c36bfd2e0f894f312d076 Mon Sep 17 00:00:00 2001 From: estlop Date: Fri, 24 Jun 2022 10:36:34 +0100 Subject: [PATCH 50/56] fix: Add extra line at the end of file as by the review --- solutions/pingpong/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/pingpong/main.go b/solutions/pingpong/main.go index 70779349..41df0363 100644 --- a/solutions/pingpong/main.go +++ b/solutions/pingpong/main.go @@ -23,4 +23,4 @@ func main() { } fmt.Println(strconv.Itoa(i) + " pong") } -} \ No newline at end of file +} From 9ce4d8e25e47919045b033a470a9f5105440bf4b Mon Sep 17 00:00:00 2001 From: estlop Date: Tue, 28 Jun 2022 13:39:56 +0100 Subject: [PATCH 51/56] test: Add random tests as per review --- tests/pingpong_test/main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/pingpong_test/main.go b/tests/pingpong_test/main.go index 299fdb4a..37f63309 100644 --- a/tests/pingpong_test/main.go +++ b/tests/pingpong_test/main.go @@ -1,6 +1,11 @@ package main -import "github.com/01-edu/go-tests/lib/challenge" +import ( + "strconv" + + "github.com/01-edu/go-tests/lib/challenge" + "github.com/01-edu/go-tests/lib/random" +) func main() { args := [][]string{ @@ -13,6 +18,10 @@ func main() { {"99"}, {"100"}, } + for i := 0; i < 10; i++ { + rand := []string{strconv.Itoa(random.IntBetween(0, 99))} + args = append(args, rand) + } for _, arg := range args { challenge.Program("pingpong", arg...) } From d851014c2db0e8a09558308f28c79bb8aeb642e2 Mon Sep 17 00:00:00 2001 From: estlop Date: Tue, 28 Jun 2022 14:25:22 +0100 Subject: [PATCH 52/56] fix: Remove random tests --- tests/pingpong_test/main.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/pingpong_test/main.go b/tests/pingpong_test/main.go index 37f63309..6500ddd0 100644 --- a/tests/pingpong_test/main.go +++ b/tests/pingpong_test/main.go @@ -1,10 +1,7 @@ package main import ( - "strconv" - "github.com/01-edu/go-tests/lib/challenge" - "github.com/01-edu/go-tests/lib/random" ) func main() { @@ -18,10 +15,6 @@ func main() { {"99"}, {"100"}, } - for i := 0; i < 10; i++ { - rand := []string{strconv.Itoa(random.IntBetween(0, 99))} - args = append(args, rand) - } for _, arg := range args { challenge.Program("pingpong", arg...) } From 57db84b9480f80764ce60a4e7864a3aa00bc08d3 Mon Sep 17 00:00:00 2001 From: zainabdnaya Date: Mon, 20 Jun 2022 19:37:29 +0100 Subject: [PATCH 53/56] squareroot --- solutions/squareroot.go | 17 +++++++++++++++++ tests/squareroot_test/main.go | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 solutions/squareroot.go create mode 100644 tests/squareroot_test/main.go diff --git a/solutions/squareroot.go b/solutions/squareroot.go new file mode 100644 index 00000000..198164e5 --- /dev/null +++ b/solutions/squareroot.go @@ -0,0 +1,17 @@ +package solutions + +func SquareRoot(number int) int { + if number == 1{ + return 1 + } + if number >= 0 { + sqrt := number / 2 + temp := 0 + for sqrt != temp { + temp = sqrt + sqrt = (number/temp + temp) / 2 + } + return sqrt + } + return -1 +} diff --git a/tests/squareroot_test/main.go b/tests/squareroot_test/main.go new file mode 100644 index 00000000..6cae4248 --- /dev/null +++ b/tests/squareroot_test/main.go @@ -0,0 +1,15 @@ +package main + +import ( + student "student" + + "github.com/01-edu/go-tests/lib/challenge" + "github.com/01-edu/go-tests/solutions" +) + +func main() { + arr := []int{1, 244, 3, 45,-58,8,2147483647,0,98,7} + for _, arg := range arr { + challenge.Function("SquareRoot", student.SquareRoot, solutions.SquareRoot, arg) + } +} From 699a0f87fb2b38b33cfbf06bc0832720fdd337b1 Mon Sep 17 00:00:00 2001 From: zainabdnaya Date: Mon, 20 Jun 2022 20:04:56 +0100 Subject: [PATCH 54/56] squareroot --- solutions/squareroot.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/solutions/squareroot.go b/solutions/squareroot.go index 198164e5..be87641d 100644 --- a/solutions/squareroot.go +++ b/solutions/squareroot.go @@ -1,17 +1,17 @@ package solutions func SquareRoot(number int) int { - if number == 1{ + if number == 1 { return 1 } if number >= 0 { - sqrt := number / 2 - temp := 0 + var sqrt float32 = float32(number / 2) + var temp float32 = 0.0 for sqrt != temp { temp = sqrt - sqrt = (number/temp + temp) / 2 + sqrt = float32((float32(number)/temp + temp) / 2) } - return sqrt + return int(sqrt) } return -1 } From 283c24120c02f1a0b62c42711fadea1e565eee10 Mon Sep 17 00:00:00 2001 From: zainabdnaya Date: Thu, 7 Jul 2022 09:12:17 +0100 Subject: [PATCH 55/56] corrected --- tests/squareroot_test/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/squareroot_test/main.go b/tests/squareroot_test/main.go index 6cae4248..07e41214 100644 --- a/tests/squareroot_test/main.go +++ b/tests/squareroot_test/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - arr := []int{1, 244, 3, 45,-58,8,2147483647,0,98,7} + arr := []int{1, 244, 3, 45, -58, 8, 2147483647, 0, 98, 7} for _, arg := range arr { challenge.Function("SquareRoot", student.SquareRoot, solutions.SquareRoot, arg) } From 37bb35eed33f45ebcc16520f5d13649221e0d06c Mon Sep 17 00:00:00 2001 From: rcatini <100608277+rcatini@users.noreply.github.com> Date: Mon, 1 Aug 2022 18:36:47 +0200 Subject: [PATCH 56/56] Reproduce the behavior of tail This modification makes ztail reproduce the behavior of tail in the case there are multiple files to output (a banner is printed). In particular, the filename banner should not be preceded by a newline if it's preceded only by errors --- solutions/ztail/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/solutions/ztail/main.go b/solutions/ztail/main.go index 634fc8c3..2dd822cb 100644 --- a/solutions/ztail/main.go +++ b/solutions/ztail/main.go @@ -27,6 +27,7 @@ func main() { flag.Int64Var(&bytes, "c", 0, "output the last NUM bytes") flag.Parse() filenames := flag.Args() + var oneFileHasBeenPrinted bool for i, filename := range filenames { file, err := os.Open(filename) if notNil(err) { @@ -47,12 +48,13 @@ func main() { continue } if len(filenames) > 1 { - if i > 0 { + if i > 0 && oneFileHasBeenPrinted { fmt.Println() } fmt.Println("==>", filename, "<==") } os.Stdout.Write(b) + oneFileHasBeenPrinted = true } os.Exit(status) }