fix encoding to zero
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Arnas Udovic 2024-08-08 14:53:11 +03:00
parent 7bd5c7ec48
commit c11c23dd98
4 changed files with 58 additions and 36 deletions

5
CHANGELOG.md Normal file
View file

@ -0,0 +1,5 @@
# v1.0.1
2024-08-08
* fix encoding to zero

View file

@ -1,14 +1,17 @@
package abcex package abcex
import "fmt" import (
import "math" "fmt"
"math"
)
var decToAbcex = map[int]string{ var decToAbcex = map[int]string{
0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7",
8: "8", 9: "9", 10: "a", 11: "b", 12: "c", 13: "d", 14: "e", 8: "8", 9: "9", 10: "a", 11: "b", 12: "c", 13: "d", 14: "e",
15: "f", 16: "g", 17: "h", 18: "i", 19: "j", 20: "k", 21: "l", 15: "f", 16: "g", 17: "h", 18: "i", 19: "j", 20: "k", 21: "l",
22: "m", 23: "n", 24: "o", 25: "p", 26: "q", 27: "r", 28: "s", 22: "m", 23: "n", 24: "o", 25: "p", 26: "q", 27: "r", 28: "s",
29: "t", 30: "u", 31: "v", 32: "w", 33: "x", 34: "y", 35: "z" } 29: "t", 30: "u", 31: "v", 32: "w", 33: "x", 34: "y", 35: "z",
}
var abcexToDec = flipMap() var abcexToDec = flipMap()
@ -30,6 +33,10 @@ func flipMap() map[string]int {
} }
func Encode(number int64) string { func Encode(number int64) string {
if number == 0 {
return "0"
}
result := "" result := ""
for number > 0 { for number > 0 {

View file

@ -1,7 +1,9 @@
package abcex package abcex
import "fmt" import (
import "testing" "fmt"
"testing"
)
func TestEncode(t *testing.T) { func TestEncode(t *testing.T) {
fmt.Println(Encode(12345)) fmt.Println(Encode(12345))
@ -12,3 +14,11 @@ func TestDecode(t *testing.T) {
fmt.Println(Decode("9ix")) fmt.Println(Decode("9ix"))
// Output: 12345 // Output: 12345
} }
func TestZero(t *testing.T) {
fmt.Println(Encode(0))
// Output: 0
fmt.Println(Decode("0"))
// Output: 0
}