Files
gocryptotrader/exchanges/stats/stats_test.go
Ryan O'Hara-Reid 0990f9d118 Currency package update (#247)
* Initial currency overhaul before service system implementation

* Remove redundant currency string in orderbook.Base
Unexport lastupdated field in orderbook.Base as it was being instantiated multiple times
Add error handling for process orderbook

*  Remove redundant currency string in ticker.Price
 Unexport lastupdated field in ticker.Price
 Add error handling for process ticker function and fix tests

* Phase Two Update

* Update translations to use map type - thankyou to kempeng for spotting this

* Change pair method name from Display -> Format for better readability

* Fixes misspelling and tests

* Implement requested changes from GloriousCode

* Remove reduntant function and streamlined return in currency_translation.go

* Revert pair method naming conventions

* Change currency naming conventions

* Changed code type to exported Item type with underlying string to reduce complexity

* Added interim orderbook process method to orderbook.Base type

* Changed feebuilder struct field to currency.Pair

* Adds fall over system for backup fx providers

* deprecate function and children and fix linter issue with btcmarkets

* Fixed requested changes

* Fix bug and move mtx for rates

* Fixed after rebase oopsies

* Fix linter issues

* Fixes race conditions in testing functions

* Final phase coinmarketcap update

* fix linter issues

* Implement requested changes

* Adds configuration variables to increase/decrease time durations between updating currency file and fetching new currency rates

* Add a collection of tests to improve codecov

* After rebase oopsy fixes for btse

* Fix requested changes

* fix after rebase oopsies and add more efficient comparison checks within currency pair

* Fix linter issues
2019-03-19 11:49:05 +11:00

182 lines
4.2 KiB
Go

package stats
import (
"testing"
"github.com/thrasher-/gocryptotrader/currency"
)
func TestLenByPrice(t *testing.T) {
p := currency.NewPairFromStrings("BTC", "USD")
Items = []Item{
{
Exchange: "ANX",
Pair: p,
AssetType: "SPOT",
Price: 1200,
Volume: 5,
},
}
if ByPrice.Len(Items) < 1 {
t.Error("Test Failed - stats LenByPrice() length not correct.")
}
}
func TestLessByPrice(t *testing.T) {
p := currency.NewPairFromStrings("BTC", "USD")
Items = []Item{
{
Exchange: "alphapoint",
Pair: p,
AssetType: "SPOT",
Price: 1200,
Volume: 5,
},
{
Exchange: "bitfinex",
Pair: p,
AssetType: "SPOT",
Price: 1198,
Volume: 20,
},
}
if !ByPrice.Less(Items, 1, 0) {
t.Error("Test Failed - stats LessByPrice() incorrect return.")
}
if ByPrice.Less(Items, 0, 1) {
t.Error("Test Failed - stats LessByPrice() incorrect return.")
}
}
func TestSwapByPrice(t *testing.T) {
p := currency.NewPairFromStrings("BTC", "USD")
Items = []Item{
{
Exchange: "bitstamp",
Pair: p,
AssetType: "SPOT",
Price: 1324,
Volume: 5,
},
{
Exchange: "btcc",
Pair: p,
AssetType: "SPOT",
Price: 7863,
Volume: 20,
},
}
ByPrice.Swap(Items, 0, 1)
if Items[0].Exchange != "btcc" || Items[1].Exchange != "bitstamp" {
t.Error("Test Failed - stats SwapByPrice did not swap values.")
}
}
func TestLenByVolume(t *testing.T) {
if ByVolume.Len(Items) != 2 {
t.Error("Test Failed - stats lenByVolume did not swap values.")
}
}
func TestLessByVolume(t *testing.T) {
if !ByVolume.Less(Items, 1, 0) {
t.Error("Test Failed - stats LessByVolume() incorrect return.")
}
if ByVolume.Less(Items, 0, 1) {
t.Error("Test Failed - stats LessByVolume() incorrect return.")
}
}
func TestSwapByVolume(t *testing.T) {
ByPrice.Swap(Items, 0, 1)
if Items[1].Exchange != "btcc" || Items[0].Exchange != "bitstamp" {
t.Error("Test Failed - stats SwapByVolume did not swap values.")
}
}
func TestAdd(t *testing.T) {
Items = Items[:0]
p := currency.NewPairFromStrings("BTC", "USD")
Add("ANX", p, "SPOT", 1200, 42)
if len(Items) < 1 {
t.Error("Test Failed - stats Add did not add exchange info.")
}
Add("", p, "", 0, 0)
if len(Items) != 1 {
t.Error("Test Failed - stats Add did not add exchange info.")
}
p.Base = currency.XBT
Add("ANX", p, "SPOT", 1201, 43)
if Items[1].Pair.String() != "XBTUSD" {
t.Fatal("Test failed. stats Add did not add exchange info.")
}
p = currency.NewPairFromStrings("ETH", "USDT")
Add("ANX", p, "SPOT", 300, 1000)
if Items[2].Pair.String() != "ETHUSD" {
t.Fatal("Test failed. stats Add did not add exchange info.")
}
}
func TestAppend(t *testing.T) {
p := currency.NewPairFromStrings("BTC", "USD")
Append("sillyexchange", p, "SPOT", 1234, 45)
if len(Items) < 2 {
t.Error("Test Failed - stats Append did not add exchange values.")
}
Append("sillyexchange", p, "SPOT", 1234, 45)
if len(Items) == 3 {
t.Error("Test Failed - stats Append added exchange values")
}
}
func TestAlreadyExists(t *testing.T) {
p := currency.NewPairFromStrings("BTC", "USD")
if !AlreadyExists("ANX", p, "SPOT", 1200, 42) {
t.Error("Test Failed - stats AlreadyExists exchange does not exist.")
}
p.Base = currency.NewCode("dii")
if AlreadyExists("bla", p, "SPOT", 1234, 123) {
t.Error("Test Failed - stats AlreadyExists found incorrect exchange.")
}
}
func TestSortExchangesByVolume(t *testing.T) {
p := currency.NewPairFromStrings("BTC", "USD")
topVolume := SortExchangesByVolume(p, "SPOT", true)
if topVolume[0].Exchange != "sillyexchange" {
t.Error("Test Failed - stats SortExchangesByVolume incorrectly sorted values.")
}
topVolume = SortExchangesByVolume(p, "SPOT", false)
if topVolume[0].Exchange != "ANX" {
t.Error("Test Failed - stats SortExchangesByVolume incorrectly sorted values.")
}
}
func TestSortExchangesByPrice(t *testing.T) {
p := currency.NewPairFromStrings("BTC", "USD")
topPrice := SortExchangesByPrice(p, "SPOT", true)
if topPrice[0].Exchange != "sillyexchange" {
t.Error("Test Failed - stats SortExchangesByPrice incorrectly sorted values.")
}
topPrice = SortExchangesByPrice(p, "SPOT", false)
if topPrice[0].Exchange != "ANX" {
t.Error("Test Failed - stats SortExchangesByPrice incorrectly sorted values.")
}
}