From 978b8c8111334e6ec51972a79d5a56d2ae819add Mon Sep 17 00:00:00 2001 From: Max Blazejewski Date: Thu, 9 May 2024 20:56:06 +0200 Subject: [PATCH] 1.7.1 (#15) * Set cache clean up time to cacheTTL if it's less than an hour * Fix life fame calculation formula * Bump version number --- cache/cache.go | 2 +- handlers/GetStatus.go | 2 +- utils/CalculateLifeFame.go | 2 +- utils/CalculateLifeFame_test.go | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 utils/CalculateLifeFame_test.go diff --git a/cache/cache.go b/cache/cache.go index 7cade43..3a32af9 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -28,7 +28,7 @@ func NewCache[T any]() *cache[T] { cacheTTL := config.GetCacheTTL() return &cache[T]{ - internalCache: goCache.New(cacheTTL, time.Hour), + internalCache: goCache.New(cacheTTL, min(time.Hour, cacheTTL)), } } diff --git a/handlers/GetStatus.go b/handlers/GetStatus.go index 19f1f6d..00e832e 100644 --- a/handlers/GetStatus.go +++ b/handlers/GetStatus.go @@ -28,6 +28,6 @@ func GetStatus(w http.ResponseWriter, r *http.Request) { }, "proxies": len(config.GetProxyList()), "uptime": time.Since(initTime).Round(time.Second).String(), - "version": "1.7.0", + "version": "1.7.1", }) } diff --git a/utils/CalculateLifeFame.go b/utils/CalculateLifeFame.go index 3409655..b5f5f54 100644 --- a/utils/CalculateLifeFame.go +++ b/utils/CalculateLifeFame.go @@ -18,7 +18,7 @@ func CalculateLifeFame(specs [11]string) (lifeFame uint16) { } else if text == "Master" { lifeFame += 150 + uint16(number)*3 } else if text == "Guru" { - lifeFame += 253 + lifeFame += 240 + uint16(number)*3 } } diff --git a/utils/CalculateLifeFame_test.go b/utils/CalculateLifeFame_test.go new file mode 100644 index 0000000..d9f60db --- /dev/null +++ b/utils/CalculateLifeFame_test.go @@ -0,0 +1,32 @@ +package utils + +import ( + "testing" +) + +func TestCalculateLifeFame(t *testing.T) { + tests := []struct { + input [11]string + expected uint16 + }{ + { + input: [11]string{"Artisan 6", "Professional 4", "Artisan 1", "Master 6", "Professional 7", "Artisan 8", "Professional 10", "Apprentice 9", "Skilled 4", "Apprentice 4", "Beginner 1"}, + expected: 907, + }, + { + input: [11]string{"Guru 7", "Skilled 5", "Beginner 8", "Guru 52", "Guru 27", "Guru 35", "Artisan 3", "Apprentice 7", "Guru 15", "Geginner 6", "Beginner 1"}, + expected: 1738, + }, + { + input: [11]string{"Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1"}, + expected: 1, + }, + } + + for _, test := range tests { + result := CalculateLifeFame(test.input) + if result != test.expected { + t.Errorf("Input: %v, Expected: %v, Got: %v", test.input, test.expected, result) + } + } +}