mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-20 07:26:46 +00:00
Add CopyPairFormat to pair package and expand test coverage
This commit is contained in:
@@ -149,3 +149,13 @@ func FormatPairs(pairs []string, delimiter, index string) []CurrencyPair {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// CopyPairFormat copies the pair format from a list of pairs once matched
|
||||
func CopyPairFormat(p CurrencyPair, pairs []CurrencyPair) CurrencyPair {
|
||||
for x := range pairs {
|
||||
if p.Equal(pairs[x]) {
|
||||
return pairs[x]
|
||||
}
|
||||
}
|
||||
return CurrencyPair{}
|
||||
}
|
||||
|
||||
@@ -253,6 +253,10 @@ func TestContains(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFormatPairs(t *testing.T) {
|
||||
if len(FormatPairs([]string{""}, "-", "")) > 0 {
|
||||
t.Error("Test failed. TestFormatPairs: Empty string returned a valid pair")
|
||||
}
|
||||
|
||||
if FormatPairs([]string{"BTC-USD"}, "-", "")[0].Pair().String() != "BTC-USD" {
|
||||
t.Error("Test failed. TestFormatPairs: Expected pair was not found")
|
||||
}
|
||||
@@ -265,3 +269,26 @@ func TestFormatPairs(t *testing.T) {
|
||||
t.Error("Test failed. TestFormatPairs: Expected pair was not found")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCopyPairFormat(t *testing.T) {
|
||||
pairOne := NewCurrencyPair("BTC", "USD")
|
||||
pairOne.Delimiter = "-"
|
||||
pairTwo := NewCurrencyPair("LTC", "USD")
|
||||
|
||||
var pairs []CurrencyPair
|
||||
pairs = append(pairs, pairOne)
|
||||
pairs = append(pairs, pairTwo)
|
||||
|
||||
testPair := NewCurrencyPair("BTC", "USD")
|
||||
testPair.Delimiter = "~"
|
||||
|
||||
result := CopyPairFormat(testPair, pairs)
|
||||
if result.Pair().String() != "BTC-USD" {
|
||||
t.Error("Test failed. TestCopyPairFormat: Expected pair was not found")
|
||||
}
|
||||
|
||||
result = CopyPairFormat(NewCurrencyPair("ETH", "USD"), pairs)
|
||||
if result.Pair().String() != "" {
|
||||
t.Error("Test failed. TestCopyPairFormat: Unexpected non empty pair returned")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user