mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-01 07:26:48 +00:00
Add/improve common string functions, currency pair handling, fix LBTC orderbook amount
This commit is contained in:
@@ -139,12 +139,22 @@ func StringContains(input, substring string) bool {
|
||||
return strings.Contains(input, substring)
|
||||
}
|
||||
|
||||
// DataContains checks the substring array with an input and returns a bool
|
||||
func DataContains(haystack []string, needle string) bool {
|
||||
// StringDataContains checks the substring array with an input and returns a bool
|
||||
func StringDataContains(haystack []string, needle string) bool {
|
||||
data := strings.Join(haystack, ",")
|
||||
return strings.Contains(data, needle)
|
||||
}
|
||||
|
||||
// StringDataCompare data checks the substring array with an input and returns a bool
|
||||
func StringDataCompare(haystack []string, needle string) bool {
|
||||
for x := range haystack {
|
||||
if haystack[x] == needle {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// JoinStrings joins an array together with the required separator and returns
|
||||
// it as a string
|
||||
func JoinStrings(input []string, separator string) string {
|
||||
|
||||
@@ -243,19 +243,38 @@ func TestStringContains(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDataContains(t *testing.T) {
|
||||
func TestStringDataContains(t *testing.T) {
|
||||
t.Parallel()
|
||||
originalHaystack := []string{"hello", "world", "data", "Contains", "string"}
|
||||
originalNeedle := "world"
|
||||
originalHaystack := []string{"hello", "world", "USDT", "Contains", "string"}
|
||||
originalNeedle := "USD"
|
||||
anotherNeedle := "thing"
|
||||
expectedOutput := true
|
||||
expectedOutputTwo := false
|
||||
actualResult := DataContains(originalHaystack, originalNeedle)
|
||||
actualResult := StringDataContains(originalHaystack, originalNeedle)
|
||||
if actualResult != expectedOutput {
|
||||
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
|
||||
expectedOutput, actualResult)
|
||||
}
|
||||
actualResult = DataContains(originalHaystack, anotherNeedle)
|
||||
actualResult = StringDataContains(originalHaystack, anotherNeedle)
|
||||
if actualResult != expectedOutputTwo {
|
||||
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
|
||||
expectedOutput, actualResult)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringDataCompare(t *testing.T) {
|
||||
t.Parallel()
|
||||
originalHaystack := []string{"hello", "WoRld", "USDT", "Contains", "string"}
|
||||
originalNeedle := "WoRld"
|
||||
anotherNeedle := "USD"
|
||||
expectedOutput := true
|
||||
expectedOutputTwo := false
|
||||
actualResult := StringDataCompare(originalHaystack, originalNeedle)
|
||||
if actualResult != expectedOutput {
|
||||
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
|
||||
expectedOutput, actualResult)
|
||||
}
|
||||
actualResult = StringDataCompare(originalHaystack, anotherNeedle)
|
||||
if actualResult != expectedOutputTwo {
|
||||
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
|
||||
expectedOutput, actualResult)
|
||||
|
||||
Reference in New Issue
Block a user