mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-24 23:16:52 +00:00
build/ci: Update Go to v1.24, golangci-lint to v1.64.6 and fix issues (#1804)
* build/ci: Update Go to v1.24, golangci-lint to v1.64.5 and fix issues * Address shazbert's nitters * linter/config: Fix new linter issue and use versionSize const * Address gk's nitters and fix additional linter issue after rebase * Address glorious nits * staticcheck: Fix additional linter issues after upgrading to Go 1.24.1 and golangci-lint v1.64.6 Also addresses nits * Improve testing, assertify usage and use common.ErrParsingWSField * TestCreateNewStrategy: Replace must > should wording
This commit is contained in:
2
common/cache/lru.go
vendored
2
common/cache/lru.go
vendored
@@ -94,7 +94,7 @@ func (l *LRU) Clear() {
|
||||
|
||||
// Len returns length of l
|
||||
func (l *LRU) Len() uint64 {
|
||||
return uint64(l.l.Len())
|
||||
return uint64(l.l.Len()) //nolint:gosec // False positive as uint64 (2^64-1) can support both 2^31-1 on 32bit systems and 2^63-1 on 64bit systems
|
||||
}
|
||||
|
||||
// removeOldest removes the oldest item from the cache.
|
||||
|
||||
@@ -789,7 +789,7 @@ func TestCounter(t *testing.T) {
|
||||
// 683185328 1.787 ns/op 0 B/op 0 allocs/op
|
||||
func BenchmarkCounter(b *testing.B) {
|
||||
c := Counter{}
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
c.IncrementAndGet()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,14 +103,13 @@ func FloatToHumanFriendlyString(number float64, decimals uint, decPoint, thousan
|
||||
number = -number
|
||||
neg = true
|
||||
}
|
||||
dec := int(decimals)
|
||||
str := fmt.Sprintf("%."+strconv.Itoa(dec)+"F", number)
|
||||
return numberToHumanFriendlyString(str, dec, decPoint, thousandsSep, neg)
|
||||
str := fmt.Sprintf("%."+strconv.FormatUint(uint64(decimals), 10)+"F", number)
|
||||
return numberToHumanFriendlyString(str, decimals, decPoint, thousandsSep, neg)
|
||||
}
|
||||
|
||||
// DecimalToHumanFriendlyString converts a decimal number to a comma separated string at the thousand point
|
||||
// eg 1000 becomes 1,000
|
||||
func DecimalToHumanFriendlyString(number decimal.Decimal, rounding int, decPoint, thousandsSep string) string {
|
||||
func DecimalToHumanFriendlyString(number decimal.Decimal, rounding uint, decPoint, thousandsSep string) string {
|
||||
neg := false
|
||||
if number.LessThan(decimal.Zero) {
|
||||
number = number.Abs()
|
||||
@@ -119,20 +118,25 @@ func DecimalToHumanFriendlyString(number decimal.Decimal, rounding int, decPoint
|
||||
str := number.String()
|
||||
if rnd := strings.Split(str, "."); len(rnd) == 1 {
|
||||
rounding = 0
|
||||
} else if len(rnd[1]) < rounding {
|
||||
rounding = len(rnd[1])
|
||||
} else if uint(len(rnd[1])) < rounding {
|
||||
rounding = uint(len(rnd[1]))
|
||||
}
|
||||
return numberToHumanFriendlyString(number.StringFixed(int32(rounding)), rounding, decPoint, thousandsSep, neg)
|
||||
|
||||
if rounding > math.MaxInt32 {
|
||||
rounding = math.MaxInt32 // Not feasible to test due to the size of the number
|
||||
}
|
||||
|
||||
return numberToHumanFriendlyString(number.StringFixed(int32(rounding)), rounding, decPoint, thousandsSep, neg) //nolint:gosec // Checked above
|
||||
}
|
||||
|
||||
func numberToHumanFriendlyString(str string, dec int, decPoint, thousandsSep string, neg bool) string {
|
||||
func numberToHumanFriendlyString(str string, dec uint, decPoint, thousandsSep string, neg bool) string {
|
||||
var prefix, suffix string
|
||||
if len(str)-(dec+1) < 0 {
|
||||
if dec > 0 && (dec)+1 > uint(len(str)) {
|
||||
dec = 0
|
||||
}
|
||||
if dec > 0 {
|
||||
prefix = str[:len(str)-(dec+1)]
|
||||
suffix = str[len(str)-dec:]
|
||||
prefix = str[:len(str)-(int(dec)+1)]
|
||||
suffix = str[len(str)-int(dec):]
|
||||
} else {
|
||||
prefix = str
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -156,131 +155,44 @@ func TestBoolPtr(t *testing.T) {
|
||||
|
||||
func TestFloatToHumanFriendlyString(t *testing.T) {
|
||||
t.Parallel()
|
||||
test := FloatToHumanFriendlyString(0, 3, ".", ",")
|
||||
if strings.Contains(test, ",") {
|
||||
t.Error("unexpected ','")
|
||||
}
|
||||
test = FloatToHumanFriendlyString(100, 3, ".", ",")
|
||||
if strings.Contains(test, ",") {
|
||||
t.Error("unexpected ','")
|
||||
}
|
||||
test = FloatToHumanFriendlyString(1000, 3, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = FloatToHumanFriendlyString(-1000, 3, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = FloatToHumanFriendlyString(-1000, 10, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = FloatToHumanFriendlyString(1000.1337, 1, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
dec := strings.Split(test, ".")
|
||||
if len(dec) == 1 {
|
||||
t.Error("expected decimal place")
|
||||
}
|
||||
if dec[1] != "1" {
|
||||
t.Error("expected decimal place")
|
||||
}
|
||||
assert.Equal(t, "0.000", FloatToHumanFriendlyString(0, 3, ".", ","))
|
||||
assert.Equal(t, "100.000", FloatToHumanFriendlyString(100, 3, ".", ","))
|
||||
assert.Equal(t, "1,000.000", FloatToHumanFriendlyString(1000, 3, ".", ","))
|
||||
assert.Equal(t, "-1,000.000", FloatToHumanFriendlyString(-1000, 3, ".", ","))
|
||||
assert.Equal(t, "-1,000.0000000000", FloatToHumanFriendlyString(-1000, 10, ".", ","))
|
||||
assert.Equal(t, "1!000.1", FloatToHumanFriendlyString(1000.1337, 1, ".", "!"))
|
||||
}
|
||||
|
||||
func TestDecimalToHumanFriendlyString(t *testing.T) {
|
||||
t.Parallel()
|
||||
test := DecimalToHumanFriendlyString(decimal.Zero, 0, ".", ",")
|
||||
if strings.Contains(test, ",") {
|
||||
t.Log(test)
|
||||
t.Error("unexpected ','")
|
||||
}
|
||||
test = DecimalToHumanFriendlyString(decimal.NewFromInt(100), 0, ".", ",")
|
||||
if strings.Contains(test, ",") {
|
||||
t.Log(test)
|
||||
t.Error("unexpected ','")
|
||||
}
|
||||
test = DecimalToHumanFriendlyString(decimal.NewFromInt(1000), 0, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = DecimalToHumanFriendlyString(decimal.NewFromFloat(1000.1337), 1, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
dec := strings.Split(test, ".")
|
||||
if len(dec) == 1 {
|
||||
t.Error("expected decimal place")
|
||||
}
|
||||
if dec[1] != "1" {
|
||||
t.Error("expected decimal place")
|
||||
}
|
||||
|
||||
test = DecimalToHumanFriendlyString(decimal.NewFromFloat(-1000.1337), 1, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = DecimalToHumanFriendlyString(decimal.NewFromFloat(-1000.1337), 100000, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = DecimalToHumanFriendlyString(decimal.NewFromFloat(1000.1), 10, ".", ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
dec = strings.Split(test, ".")
|
||||
if len(dec) == 1 {
|
||||
t.Error("expected decimal place")
|
||||
}
|
||||
if dec[1] != "1" {
|
||||
t.Error("expected decimal place")
|
||||
}
|
||||
assert.Equal(t, "0", DecimalToHumanFriendlyString(decimal.Zero, 0, ".", ","))
|
||||
assert.Equal(t, "100", DecimalToHumanFriendlyString(decimal.NewFromInt(100), 0, ".", ","))
|
||||
assert.Equal(t, "1,000", DecimalToHumanFriendlyString(decimal.NewFromInt(1000), 0, ".", ","))
|
||||
assert.Equal(t, "-1,000", DecimalToHumanFriendlyString(decimal.NewFromInt(-1000), 0, ".", ","))
|
||||
assert.Equal(t, "-1~000!42", DecimalToHumanFriendlyString(decimal.NewFromFloat(-1000.42069), 2, "!", "~"))
|
||||
assert.Equal(t, "1,000.42069", DecimalToHumanFriendlyString(decimal.NewFromFloat(1000.42069), 5, ".", ","))
|
||||
assert.Equal(t, "1,000.42069", DecimalToHumanFriendlyString(decimal.NewFromFloat(1000.42069), 100, ".", ","))
|
||||
}
|
||||
|
||||
func TestIntToHumanFriendlyString(t *testing.T) {
|
||||
t.Parallel()
|
||||
test := IntToHumanFriendlyString(0, ",")
|
||||
if strings.Contains(test, ",") {
|
||||
t.Log(test)
|
||||
t.Error("unexpected ','")
|
||||
}
|
||||
test = IntToHumanFriendlyString(100, ",")
|
||||
if strings.Contains(test, ",") {
|
||||
t.Log(test)
|
||||
t.Error("unexpected ','")
|
||||
}
|
||||
test = IntToHumanFriendlyString(1000, ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = IntToHumanFriendlyString(-1000, ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
|
||||
test = IntToHumanFriendlyString(1000000, ",")
|
||||
if !strings.Contains(test, ",") {
|
||||
t.Error("expected ','")
|
||||
}
|
||||
dec := strings.Split(test, ",")
|
||||
if len(dec) <= 2 {
|
||||
t.Error("expected two commas place")
|
||||
}
|
||||
assert.Equal(t, "0", IntToHumanFriendlyString(0, ","))
|
||||
assert.Equal(t, "100", IntToHumanFriendlyString(100, ","))
|
||||
assert.Equal(t, "1,000", IntToHumanFriendlyString(1000, ","))
|
||||
assert.Equal(t, "-1,000", IntToHumanFriendlyString(-1000, ","))
|
||||
assert.Equal(t, "-1!000", IntToHumanFriendlyString(-1000, "!"))
|
||||
}
|
||||
|
||||
func TestNumberToHumanFriendlyString(t *testing.T) {
|
||||
resp := numberToHumanFriendlyString("1", 1337, ".", ",", false)
|
||||
if strings.Contains(resp, ".") {
|
||||
t.Error("expected no comma")
|
||||
}
|
||||
t.Parallel()
|
||||
|
||||
assert.Equal(t, "0", numberToHumanFriendlyString("0", 0, "", ",", false))
|
||||
assert.Equal(t, "1,337.69", numberToHumanFriendlyString("1337.69", 2, ".", ",", false))
|
||||
assert.Equal(t, "-1!000.1", numberToHumanFriendlyString("1000.1", 1, ".", "!", true))
|
||||
assert.Equal(t, "1,000", numberToHumanFriendlyString("1000", 20, ".", ",", false))
|
||||
}
|
||||
|
||||
func TestInterfaceToFloat64OrZeroValue(t *testing.T) {
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestPercentageDifference(t *testing.T) {
|
||||
|
||||
// 1000000000 0.2215 ns/op 0 B/op 0 allocs/op
|
||||
func BenchmarkPercentageDifference(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
PercentageDifference(1.469, 1.471)
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func TestPercentageDifferenceDecimal(t *testing.T) {
|
||||
// 1585596 751.8 ns/op 792 B/op 27 allocs/op
|
||||
func BenchmarkDecimalPercentageDifference(b *testing.B) {
|
||||
d1, d2 := decimal.NewFromFloat(1.469), decimal.NewFromFloat(1.471)
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
PercentageDifferenceDecimal(d1, d2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
// 2423571 503.9 ns/op 0 B/op 0 allocs/op (current)
|
||||
func BenchmarkTimedMutexTime(b *testing.B) {
|
||||
tm := NewTimedMutex(0)
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
tm.LockForDuration()
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ func BenchmarkTimedMutexTime(b *testing.B) {
|
||||
// 927051118 1.298 ns/op 0 B/op 0 allocs/op
|
||||
func BenchmarkTimedMutexTimeUnlockNotPrimed(b *testing.B) {
|
||||
tm := NewTimedMutex(0)
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
tm.UnlockIfLocked()
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ func BenchmarkTimedMutexTimeUnlockNotPrimed(b *testing.B) {
|
||||
func BenchmarkTimedMutexTimeUnlockPrimed(b *testing.B) {
|
||||
tm := NewTimedMutex(0)
|
||||
tm.LockForDuration()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
tm.UnlockIfLocked()
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func BenchmarkTimedMutexTimeUnlockPrimed(b *testing.B) {
|
||||
// 38592405 36.12 ns/op 0 B/op 0 allocs/op
|
||||
func BenchmarkTimedMutexTimeLinearInteraction(b *testing.B) {
|
||||
tm := NewTimedMutex(0)
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
tm.LockForDuration()
|
||||
tm.UnlockIfLocked()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user