forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath_test.go
81 lines (74 loc) · 2.1 KB
/
math_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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(
"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(
"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(
"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(
"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(
"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("RoundFloat Expected '%f'. Actual '%f'.",
expectedOutput, actualOutput)
}
}
}