Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: Replace StringDataCompare with slices.Contains and cleanup string funcs #1631

Merged
merged 3 commits into from
Sep 13, 2024

Conversation

thrasher-
Copy link
Collaborator

PR Description

Replace StringDataCompare with slices.Contains + a bit of a cleanup. I've made StringSliceDifference generic since I thought it might be useful moving forward, though since we don't currently use it anywhere now I'd be happy to rm -rf it 😈

Type of change

  • New feature (non-breaking change which adds functionality)

How has this been tested

  • go test ./... -race
  • golangci-lint run

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation and regenerated documentation via the documentation tool
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally and on Github Actions with my changes
  • Any dependent changes have been merged and published in downstream modules

@thrasher- thrasher- added the review me This pull request is ready for review label Aug 26, 2024
@thrasher- thrasher- self-assigned this Aug 26, 2024
Copy link

codecov bot commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 32.65306% with 99 lines in your changes missing coverage. Please review.

Project coverage is 38.35%. Comparing base (649f3df) to head (66f4770).

Files Patch % Lines
exchanges/huobi/huobi_futures.go 6.89% 17 Missing and 10 partials ⚠️
exchanges/binance/binance_cfutures.go 0.00% 10 Missing and 14 partials ⚠️
exchanges/binance/binance_ufutures.go 0.00% 9 Missing and 7 partials ⚠️
exchanges/huobi/huobi_cfutures.go 0.00% 7 Missing and 7 partials ⚠️
exchanges/kraken/kraken_websocket.go 0.00% 5 Missing ⚠️
exchanges/kraken/kraken_futures.go 25.00% 3 Missing ⚠️
exchanges/bitfinex/bitfinex.go 33.33% 0 Missing and 2 partials ⚠️
currency/forexprovider/base/base_interface.go 50.00% 0 Missing and 1 partial ⚠️
exchanges/bitfinex/bitfinex_wrapper.go 0.00% 1 Missing ⚠️
exchanges/btcmarkets/btcmarkets_websocket.go 0.00% 1 Missing ⚠️
... and 5 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1631      +/-   ##
==========================================
+ Coverage   36.50%   38.35%   +1.84%     
==========================================
  Files         414      414              
  Lines      179351   149152   -30199     
==========================================
- Hits        65472    57201    -8271     
+ Misses     106004    84076   -21928     
  Partials     7875     7875              
Files Coverage Δ
cmd/apichecker/apicheck.go 40.88% <100.00%> (+2.68%) ⬆️
common/common.go 94.28% <100.00%> (-0.04%) ⬇️
config/config.go 88.15% <100.00%> (+1.11%) ⬆️
engine/engine.go 49.91% <100.00%> (+1.01%) ⬆️
engine/helpers.go 82.18% <100.00%> (+2.07%) ⬆️
engine/order_manager.go 67.11% <100.00%> (+1.74%) ⬆️
exchanges/bitfinex/bitfinex_types.go 100.00% <100.00%> (ø)
exchanges/bybit/bybit.go 32.84% <100.00%> (+2.18%) ⬆️
gctscript/modules/gct/exchange.go 53.76% <100.00%> (+5.42%) ⬆️
portfolio/portfolio.go 92.06% <100.00%> (+1.35%) ⬆️
... and 15 more

... and 366 files with indirect coverage changes

Copy link
Collaborator

@shazbert shazbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff just a minor thing, commentary and suggestion.

common/common.go Show resolved Hide resolved
@@ -267,9 +267,9 @@ func TestGetEnabledExchanges(t *testing.T) {
t.Errorf("received: '%v' but expected '%v'", len(exchanges), defaultEnabledExchanges)
}

if !common.StringDataCompare(exchanges, "Bitfinex") {
if !slices.Contains(exchanges, "Bitfinex") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This is just pedantic nit picky all these changes on test files can use assert or require package. Resolve if you can't be bothered.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed these since they aren't relevant anymore, can do a full updated pass in #1494 once Bitget PR is opened

allowedGranularities := [6]int64{60, 300, 900, 3600, 21600, 86400}
validGran, _ := common.InArray(granularity, allowedGranularities)
if !validGran {
allowedGranularities := []int64{60, 300, 900, 3600, 21600, 86400}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: Just had a quick play and which I thought was interesting, we can reduce the two parameter instance of a lot of these. Out of scope though.

// Container is a generic type for slices
type Container[T comparable] []T

func (c Container[T]) Contains(in T) bool {
	return slices.Contains(c, in)
}

func TestXxx(t *testing.T) {
	allowedGranularities := Container[int64]{60, 300, 900, 3600, 21600, 86400}
	assert.True(t, allowedGranularities.Contains(300))
}

Copy link
Collaborator

@shazbert shazbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Thanks. chACK.

Copy link
Collaborator

@shazbert shazbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soz

common/common.go Show resolved Hide resolved
Copy link
Collaborator

@shazbert shazbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks tACK.

Copy link
Collaborator

@gloriousCode gloriousCode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK!

🌞

@thrasher- thrasher- merged commit b8e836d into thrasher-corp:master Sep 13, 2024
5 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review me This pull request is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants