mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 23:16:54 +00:00
modernise: Run new gopls modernise tool against the codebase and fix minor issues (#1826)
* modernise: Run new gopls modernise tool against codebase
* Address shazbert's nits
* apichecker, gctcli: Simplify HTML scraping functions and improve depth limit handling
* refactor: Create minSyncInterval const and update order book limit handling for binance and binanceUS
* refactor: Various slice usage improvements and rename TODO
* tranches: Revert deleteByID changes due to performance decrease
Shazbert was a F1 driver in a past lifetime 🏎️
* tranches: Simply retrieve copy
Thanks to shazbert
* documentation: Sort contributors list by contributions
* tranches: Remove deadcode in deleteByID
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -570,35 +571,22 @@ func deploySliceOrdered() Tranches {
|
||||
}
|
||||
|
||||
func TestReverse(t *testing.T) {
|
||||
var b Base
|
||||
b.VerifyOrderbook = true
|
||||
|
||||
if b.Bids = deploySliceOrdered(); len(b.Bids) != 1000 {
|
||||
t.Fatal("incorrect length")
|
||||
b := Base{
|
||||
VerifyOrderbook: true,
|
||||
}
|
||||
|
||||
err := b.Verify()
|
||||
if !errors.Is(err, errPriceOutOfOrder) {
|
||||
t.Fatalf("error expected %v received %v", errPriceOutOfOrder, err)
|
||||
}
|
||||
b.Bids = deploySliceOrdered()
|
||||
require.Len(t, b.Bids, 1000)
|
||||
assert.ErrorIs(t, b.Verify(), errPriceOutOfOrder)
|
||||
|
||||
b.Bids.Reverse()
|
||||
err = b.Verify()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.NoError(t, b.Verify())
|
||||
|
||||
b.Asks = append(b.Bids[:0:0], b.Bids...) //nolint:gocritic // Short hand
|
||||
err = b.Verify()
|
||||
if !errors.Is(err, errPriceOutOfOrder) {
|
||||
t.Fatalf("error expected %v received %v", errPriceOutOfOrder, err)
|
||||
}
|
||||
b.Asks = slices.Clone(b.Bids)
|
||||
assert.ErrorIs(t, b.Verify(), errPriceOutOfOrder)
|
||||
|
||||
b.Asks.Reverse()
|
||||
err = b.Verify()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.NoError(t, b.Verify())
|
||||
}
|
||||
|
||||
// 705985 1856 ns/op 0 B/op 0 allocs/op
|
||||
|
||||
@@ -84,18 +84,13 @@ updates:
|
||||
continue
|
||||
}
|
||||
|
||||
if y < len(*ts) {
|
||||
copy((*ts)[y:], (*ts)[y+1:])
|
||||
*ts = (*ts)[:len(*ts)-1]
|
||||
} else {
|
||||
*ts = append((*ts)[:y], (*ts)[y+1:]...)
|
||||
}
|
||||
copy((*ts)[y:], (*ts)[y+1:])
|
||||
*ts = (*ts)[:len(*ts)-1]
|
||||
|
||||
continue updates
|
||||
}
|
||||
if !bypassErr {
|
||||
return fmt.Errorf("delete error: %w %d not found",
|
||||
errIDCannotBeMatched,
|
||||
updts[x].ID)
|
||||
return fmt.Errorf("delete error: %w %d not found", errIDCannotBeMatched, updts[x].ID)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -117,7 +112,9 @@ func (ts Tranches) retrieve(count int) Tranches {
|
||||
if count == 0 || count >= len(ts) {
|
||||
count = len(ts)
|
||||
}
|
||||
return append(Tranches{}, ts[:count]...)
|
||||
result := make(Tranches, count)
|
||||
copy(result, ts)
|
||||
return result
|
||||
}
|
||||
|
||||
// updateInsertByPrice amends, inserts, moves and cleaves length of depth by
|
||||
|
||||
@@ -1107,7 +1107,7 @@ func TestInsertUpdatesAsk(t *testing.T) {
|
||||
}
|
||||
|
||||
// check checks depth values after an update has taken place
|
||||
func Check(t *testing.T, depth interface{}, liquidity, value float64, expectedLen int) {
|
||||
func Check(t *testing.T, depth any, liquidity, value float64, expectedLen int) {
|
||||
t.Helper()
|
||||
b, isBid := depth.(bidTranches)
|
||||
a, isAsk := depth.(askTranches)
|
||||
|
||||
Reference in New Issue
Block a user