diff --git a/go/tests/func/convertbase_test/main.go b/go/tests/func/convertbase_test/main.go index b9c582403..99f63b8f0 100644 --- a/go/tests/func/convertbase_test/main.go +++ b/go/tests/func/convertbase_test/main.go @@ -3,11 +3,31 @@ package main import ( student "student" - "./base" - "./correct" - "github.com/01-edu/public/go/lib" + "base" + "lib" ) +func convertNbrBase(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 convertBase(nbr, baseFrom, baseTo string) string { + resultIntermediary := base.Atoi(nbr, baseFrom) + + resultFinal := convertNbrBase(resultIntermediary, baseTo) + + return resultFinal +} + func main() { type node struct { nbr string @@ -35,7 +55,7 @@ func main() { ) for _, arg := range table { - lib.Challenge("ConvertBase", student.ConvertBase, correct.ConvertBase, arg.nbr, arg.baseFrom, arg.baseTo) + lib.Challenge("ConvertBase", student.ConvertBase, convertBase, arg.nbr, arg.baseFrom, arg.baseTo) } } diff --git a/go/tests/tofix/func/correct/convertbase.go b/go/tests/tofix/func/correct/convertbase.go deleted file mode 100644 index 0654ee5a7..000000000 --- a/go/tests/tofix/func/correct/convertbase.go +++ /dev/null @@ -1,24 +0,0 @@ -package correct - -func ConvertNbrBase(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 ConvertBase(nbr, baseFrom, baseTo string) string { - resultIntermediary := AtoiBase(nbr, baseFrom) - - resultFinal := ConvertNbrBase(resultIntermediary, baseTo) - - return resultFinal -} - -// TODO: fix base exercises