mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
package math
|
|
|
|
import "testing"
|
|
|
|
func TestCalculateFee(t *testing.T) {
|
|
t.Parallel()
|
|
originalInput := float64(1)
|
|
fee := float64(1)
|
|
expectedOutput := float64(0.01)
|
|
actualResult := CalculateFee(originalInput, fee)
|
|
if expectedOutput != actualResult {
|
|
t.Errorf(
|
|
"Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
|
|
}
|
|
}
|
|
|
|
func TestCalculateAmountWithFee(t *testing.T) {
|
|
t.Parallel()
|
|
originalInput := float64(1)
|
|
fee := float64(1)
|
|
expectedOutput := float64(1.01)
|
|
actualResult := CalculateAmountWithFee(originalInput, fee)
|
|
if expectedOutput != actualResult {
|
|
t.Errorf(
|
|
"Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
|
|
}
|
|
}
|
|
|
|
func TestCalculatePercentageGainOrLoss(t *testing.T) {
|
|
t.Parallel()
|
|
originalInput := float64(9300)
|
|
secondInput := float64(9000)
|
|
expectedOutput := 3.3333333333333335
|
|
actualResult := CalculatePercentageGainOrLoss(originalInput, secondInput)
|
|
if expectedOutput != actualResult {
|
|
t.Errorf(
|
|
"Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
|
|
}
|
|
}
|
|
|
|
func TestCalculatePercentageDifference(t *testing.T) {
|
|
t.Parallel()
|
|
originalInput := float64(10)
|
|
secondAmount := float64(5)
|
|
expectedOutput := 66.66666666666666
|
|
actualResult := CalculatePercentageDifference(originalInput, secondAmount)
|
|
if expectedOutput != actualResult {
|
|
t.Errorf(
|
|
"Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
|
|
}
|
|
}
|
|
|
|
func TestCalculateNetProfit(t *testing.T) {
|
|
t.Parallel()
|
|
amount := float64(5)
|
|
priceThen := float64(1)
|
|
priceNow := float64(10)
|
|
costs := float64(1)
|
|
expectedOutput := float64(44)
|
|
actualResult := CalculateNetProfit(amount, priceThen, priceNow, costs)
|
|
if expectedOutput != actualResult {
|
|
t.Errorf(
|
|
"Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
|
|
}
|
|
}
|
|
|
|
func TestRoundFloat(t *testing.T) {
|
|
t.Parallel()
|
|
// mapping of input vs expected result
|
|
testTable := map[float64]float64{
|
|
2.3232323: 2.32,
|
|
-2.3232323: -2.32,
|
|
}
|
|
for testInput, expectedOutput := range testTable {
|
|
actualOutput := RoundFloat(testInput, 2)
|
|
if actualOutput != expectedOutput {
|
|
t.Errorf("Test failed. RoundFloat Expected '%f'. Actual '%f'.",
|
|
expectedOutput, actualOutput)
|
|
}
|
|
}
|
|
}
|