Add/improve common string functions, currency pair handling, fix LBTC orderbook amount

This commit is contained in:
Adrian Gallagher
2018-02-08 11:59:54 +11:00
parent 5f10897b5b
commit e8f8e32609
19 changed files with 129 additions and 51 deletions

View File

@@ -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 {

View File

@@ -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)