From b0725cfb423c26e3ad2996ffee659ed981d281c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=81=A3?= <⁣> Date: Sat, 20 Jun 2020 10:10:39 +0200 Subject: [PATCH] Fix convertbase exercise --- go/tests/func/convertbase_test/main.go | 28 ++++++++++++++++++---- go/tests/tofix/func/correct/convertbase.go | 24 ------------------- 2 files changed, 24 insertions(+), 28 deletions(-) delete mode 100644 go/tests/tofix/func/correct/convertbase.go 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