cbrfWorker/utils/currency_exchange_test.go
2023-05-22 19:48:44 +00:00

107 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils_test
import (
"fmt"
"testing"
"github.com/danilsolovyov/croupierCbrf/dal"
"github.com/danilsolovyov/croupierCbrf/utils"
"github.com/stretchr/testify/assert"
)
func TestCurrencyExchange(t *testing.T) {
currencies := map[string]dal.Quote{
"USD": {ID: "USD", Value: 79.9093},
"EUR": {ID: "EUR", Value: 86.2770},
"BYN": {ID: "BYN", Value: 27.3110},
}
testCases := []struct {
from string
to string
value int64
expected int64
isError bool
}{
{
from: "USD",
to: "RUB",
value: 10000,
expected: 799100,
},
{
from: "RUB",
to: "RUB",
value: 10000,
expected: 10000,
},
{
from: "BYN",
to: "RUB",
value: 10000,
expected: 273100,
},
{
from: "EUR",
to: "RUB",
value: 10000,
expected: 862800,
},
{
from: "RUB",
to: "USD",
value: 799100,
expected: 10000,
},
{
from: "RUB",
to: "BYN",
value: 273100,
expected: 10000,
},
{
from: "RUB",
to: "EUR",
value: 862800,
expected: 10000,
},
{
from: "BYN",
to: "EUR",
value: 10000,
expected: 3165,
},
{
from: "BYNNN",
to: "EURRR",
value: 19900,
expected: 0,
isError: true,
},
{
from: "BYN",
to: "EURRR",
value: 19900,
expected: 0,
isError: true,
},
}
for _, testCase := range testCases {
result, err := utils.CurrencyExchange(currencies, testCase.from, testCase.to, testCase.value)
if testCase.isError {
assert.Equal(t, testCase.expected, result)
assert.Error(t, err)
continue
}
assert.NoError(t, err)
assert.Equal(t,
testCase.expected,
result,
fmt.Sprintf("Неверный результат при переводе с %s на %s", testCase.from, testCase.to),
)
}
}