feat: removes sorted map
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Marvin Preuss 2023-04-14 06:12:29 +00:00
parent 030c39580d
commit 6b69f825bf
2 changed files with 1 additions and 47 deletions

View File

@ -5,7 +5,6 @@ import (
"math"
"os"
"regexp"
"sort"
"strconv"
"strings"
"time"
@ -139,12 +138,9 @@ func Create(out, dir string) error {
m[i.Company] += i.Value
}
sm := SortMap(m)
valueLength := 0
for k, v := range sm {
log.Info("KEY", "key", k, "category", cat)
for k, v := range m {
if err := f.SetCellStr(cat, fmt.Sprintf("A%d", valueLength+1), k); err != nil {
return fmt.Errorf("failed to set cell: %w", err)
}
@ -224,21 +220,3 @@ func createCategoryChart(category string, length int, f *excelize.File) error {
return nil
}
func SortMap[V any](m map[string]V) map[string]V {
r := map[string]V{}
keys := make([]string, 0, len(m))
for key := range m {
keys = append(keys, key)
}
sort.Strings(keys)
for _, k := range keys {
r[k] = m[k]
}
return r
}

View File

@ -124,27 +124,3 @@ func TestCategoriesInsert(t *testing.T) {
is.Equal(dirtoexcel.Categories{"NonFood": []dirtoexcel.Value{{"AMAZON", 11.11}}}, m)
}
func TestSortMap(t *testing.T) {
tables := []struct {
name string
input map[string]int
expected map[string]int
}{
{
"00",
map[string]int{"FOO": 1, "BAR": 2, "ZONK": 3},
map[string]int{"BAR": 2, "FOO": 1, "ZONK": 3},
},
}
is := is.New(t)
for _, tt := range tables {
tt := tt
t.Run(tt.name, func(t *testing.T) {
is.Equal(dirtoexcel.SortMap(tt.input), tt.expected)
})
}
}