Browse Source

Fix convertbase exercise

pull/625/head
4 years ago
parent
commit
b0725cfb42
  1. 28
      go/tests/func/convertbase_test/main.go
  2. 24
      go/tests/tofix/func/correct/convertbase.go

28
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)
}
}

24
go/tests/tofix/func/correct/convertbase.go

@ -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
Loading…
Cancel
Save