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/argrot1/main.go b/solutions/argrot1/main.go new file mode 100644 index 00000000..4bc2c156 --- /dev/null +++ b/solutions/argrot1/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + if len(os.Args) < 3 { + fmt.Println() + return + } + 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/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/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) +} 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 +} 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 +} 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 +} 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/solutions/pingpong/main.go b/solutions/pingpong/main.go new file mode 100644 index 00000000..41df0363 --- /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") + } +} 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] +} diff --git a/solutions/printevenarguments/main.go b/solutions/printevenarguments/main.go new file mode 100644 index 00000000..d5efd2d7 --- /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) + } + } +} diff --git a/solutions/printmiddle/main.go b/solutions/printmiddle/main.go new file mode 100644 index 00000000..83621dae --- /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]) + } +} diff --git a/solutions/printrange.go b/solutions/printrange.go new file mode 100644 index 00000000..16bbf09c --- /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') +} diff --git a/solutions/revargs/main.go b/solutions/revargs/main.go new file mode 100644 index 00000000..5c349ee6 --- /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() +} 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 } diff --git a/solutions/squareroot.go b/solutions/squareroot.go new file mode 100644 index 00000000..be87641d --- /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 { + var sqrt float32 = float32(number / 2) + var temp float32 = 0.0 + for sqrt != temp { + temp = sqrt + sqrt = float32((float32(number)/temp + temp) / 2) + } + return int(sqrt) + } + return -1 +} 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 +} diff --git a/solutions/swapargs/main.go b/solutions/swapargs/main.go new file mode 100644 index 00000000..eee5c490 --- /dev/null +++ b/solutions/swapargs/main.go @@ -0,0 +1,14 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + if len(os.Args) != 3 { + fmt.Println("") + return + } + fmt.Println(os.Args[2] + " " + os.Args[1]) +} 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) } 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/argrot1_test/main.go b/tests/argrot1_test/main.go new file mode 100644 index 00000000..edf86245 --- /dev/null +++ b/tests/argrot1_test/main.go @@ -0,0 +1,23 @@ +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...) + } +} 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/concatenate_test/main.go b/tests/concatenate_test/main.go new file mode 100644 index 00000000..57b68b60 --- /dev/null +++ b/tests/concatenate_test/main.go @@ -0,0 +1,20 @@ +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"}, + {"hello there", "how are you?"}, + {"hello there", " "}, + } + for _, arg := range table { + challenge.Program("concatenate", 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/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]) + } +} 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/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) + } +} 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)...) diff --git a/tests/oddlength_test/main.go b/tests/oddlength_test/main.go new file mode 100644 index 00000000..b7424e57 --- /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) + } +} 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...) diff --git a/tests/pingpong_test/main.go b/tests/pingpong_test/main.go new file mode 100644 index 00000000..6500ddd0 --- /dev/null +++ b/tests/pingpong_test/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "github.com/01-edu/go-tests/lib/challenge" +) + +func main() { + args := [][]string{ + {""}, + {"0"}, + {"3", "5"}, + {"5"}, + {"9"}, + {"24"}, + {"99"}, + {"100"}, + } + for _, arg := range args { + challenge.Program("pingpong", arg...) + } +} 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) + } +} diff --git a/tests/printevenarguments_test/main.go b/tests/printevenarguments_test/main.go new file mode 100644 index 00000000..2531fce9 --- /dev/null +++ b/tests/printevenarguments_test/main.go @@ -0,0 +1,19 @@ +package main + +import "github.com/01-edu/go-tests/lib/challenge" + +func main() { + table := [][]string{ + {}, + {"a"}, + {"", "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("printevenarguments", arg...) + } +} diff --git a/tests/printmiddle_test/main.go b/tests/printmiddle_test/main.go new file mode 100644 index 00000000..e2e09091 --- /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"}, + {"1", "z", "1"}, + } + for _, s := range args { + challenge.Program("printmiddle", s...) + } +} diff --git a/tests/printrange_test/main.go b/tests/printrange_test/main.go new file mode 100644 index 00000000..b71033d0 --- /dev/null +++ b/tests/printrange_test/main.go @@ -0,0 +1,26 @@ +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, 10}, + {10, 1}, + {1, 1}, + {10, 10}, + {0, 9}, + {-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]) + } +} diff --git a/tests/revargs_test/main.go b/tests/revargs_test/main.go new file mode 100644 index 00000000..1f6620ab --- /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("revargs", s...) + } +} diff --git a/tests/squareroot_test/main.go b/tests/squareroot_test/main.go new file mode 100644 index 00000000..07e41214 --- /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) + } +} diff --git a/tests/sum_test/main.go b/tests/sum_test/main.go new file mode 100644 index 00000000..b8c2587d --- /dev/null +++ b/tests/sum_test/main.go @@ -0,0 +1,26 @@ +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"}, + {"11", "7"}, + {"6", "256"}, + } + for _, arg := range args { + challenge.Function("Sum", student.Sum, solutions.Sum, arg[0], arg[1]) + } +} diff --git a/tests/swapargs_test/main.go b/tests/swapargs_test/main.go new file mode 100644 index 00000000..6b40841f --- /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("swapargs", s...) + } +}