From bf505423aa6f9a05d1631c30c4a0cf224c5a77b8 Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Sat, 31 Aug 2024 18:09:42 -0700 Subject: [PATCH] some server tests, unsure if they pass --- server/test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 server/test.go diff --git a/server/test.go b/server/test.go new file mode 100644 index 0000000..a4b0c1c --- /dev/null +++ b/server/test.go @@ -0,0 +1,46 @@ +package main + +import ( + "encoding/base64" + "fmt" + "strconv" + "strings" +) + +func decodeBase64ToIntArray(encodedString string) ([]int, error) { + // Decode the base64 string + decodedBytes, err := base64.StdEncoding.DecodeString(encodedString) + if err != nil { + return nil, fmt.Errorf("error decoding base64: %w", err) + } + + // Convert bytes to string + decodedString := string(decodedBytes) + + // Split the string by commas + stringSlice := strings.Split(decodedString, ",") + + // Convert each string to an integer + intSlice := make([]int, len(stringSlice)) + for i, s := range stringSlice { + num, err := strconv.Atoi(s) + if err != nil { + return nil, fmt.Errorf("error converting string to int: %w", err) + } + intSlice[i] = num + } + + return intSlice, nil +} + +func main2() { + encodedString := "MSwxMSwzMiw1MCw5OCw1Nyw1Myw1NywxMDIsNTAsNTQsNTIsNTYsMTAyLDEwMCwxMDAsOTksNTEsNTQsNTcsMTAwLDk3LDEwMCwxMDIsMTAxLDU0LDQ5LDUzLDk5LDQ4LDEwMCw0OSw1NCwxMDIsNTI=" + + intArray, err := decodeBase64ToIntArray(encodedString) + if err != nil { + fmt.Println("Error:", err) + return + } + + fmt.Println("Decoded integer array:", intArray) +}