seekia/internal/convertCurrencies/convertCurrencies_test.go

66 lines
1.9 KiB
Go

package convertCurrencies_test
import "testing"
import "seekia/internal/convertCurrencies"
import "seekia/internal/helpers"
func TestConvertCurrencies(t *testing.T){
{
ethereumWeiAmount := int64(1234567899876543210)
etherAmount, err := convertCurrencies.ConvertCryptocurrencyAtomicUnitsToWholeUnits("Ethereum", ethereumWeiAmount)
if (err != nil){
t.Fatalf("ConvertCryptocurrencyAtomicUnitsToWholeUnits failed: " + err.Error())
}
if (etherAmount != 1.23456789987654321){
etherAmountString := helpers.ConvertFloat64ToString(etherAmount)
t.Fatalf("Unexpected Ether amount: " + etherAmountString)
}
}
{
ethereumWeiAmount := int64(123456)
etherAmount, err := convertCurrencies.ConvertCryptocurrencyAtomicUnitsToWholeUnits("Ethereum", ethereumWeiAmount)
if (err != nil){
t.Fatalf("ConvertCryptocurrencyAtomicUnitsToWholeUnits failed: " + err.Error())
}
if (etherAmount != 0.000000000000123456){
etherAmountString := helpers.ConvertFloat64ToString(etherAmount)
t.Fatalf("Unexpected Ether amount: " + etherAmountString)
}
}
{
cardanoLovelaceAmount := int64(1234567)
adaAmount, err := convertCurrencies.ConvertCryptocurrencyAtomicUnitsToWholeUnits("Cardano", cardanoLovelaceAmount)
if (err != nil){
t.Fatalf("ConvertCryptocurrencyAtomicUnitsToWholeUnits failed: " + err.Error())
}
if (adaAmount != 1.2345670){
adaAmountString := helpers.ConvertFloat64ToString(adaAmount)
t.Fatalf("Unexpected ADA amount: " + adaAmountString)
}
}
{
cardanoLovelaceAmount := int64(123456789987654321)
adaAmount, err := convertCurrencies.ConvertCryptocurrencyAtomicUnitsToWholeUnits("Cardano", cardanoLovelaceAmount)
if (err != nil){
t.Fatalf("ConvertCryptocurrencyAtomicUnitsToWholeUnits failed: " + err.Error())
}
if (adaAmount != 123456789987.6543274){
adaAmountString := helpers.ConvertFloat64ToString(adaAmount)
t.Fatalf("Unexpected ADA amount: " + adaAmountString)
}
}
}