forked from leavengood/donation_tracker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
summary_test.go
92 lines (70 loc) · 1.97 KB
/
summary_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
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
//==============================================================================
// CurrencyAmounts.Add
//==============================================================================
func TestAddWithAllCurrencies(t *testing.T) {
ca := CurrencyAmounts{
"USD": 12.34,
"EUR": 10.00,
}
ca2 := CurrencyAmounts{
"USD": 23.45,
"EUR": 20.00,
}
result := ca.Add(ca2)
assert.Equal(t, 35.79, result["USD"])
assert.Equal(t, 30.00, result["EUR"])
}
func TestAddWithSomeMissingCurrencies(t *testing.T) {
ca := CurrencyAmounts{
"EUR": 10.00,
}
ca2 := CurrencyAmounts{
"USD": 23.45,
}
result := ca.Add(ca2)
assert.Equal(t, 23.45, result["USD"])
assert.Equal(t, 10.00, result["EUR"])
}
//==============================================================================
// CurrencyAmounts.Sub
//==============================================================================
// func TestSub(t *testing.T) {
// ca := CurrencyAmounts{
// "USD": 12.34,
// "EUR": 10.00,
// }
// ca2 := CurrencyAmounts{
// "USD": 23.45,
// "EUR": 20.00,
// }
// result := ca2.Sub(ca)
// assert.InDelta(t, 11.11, result["USD"], 0.0001)
// assert.Equal(t, 10.00, result["EUR"])
// }
//==============================================================================
// CurrencyAmounts.GrandTotal
//==============================================================================
const eurToUsdRate = 1.25
func TestGrandTotalWithEmptyMap(t *testing.T) {
ca := make(CurrencyAmounts)
assert.Equal(t, 0, ca.GrandTotal(eurToUsdRate))
}
func TestGrandTotalWithJustUSD(t *testing.T) {
ca := CurrencyAmounts{
"USD": 34.56,
}
assert.Equal(t, 34.56, ca.GrandTotal(eurToUsdRate))
}
func TestGrandTotalWithJustUSDAndEUR(t *testing.T) {
ca := CurrencyAmounts{
"USD": 34.56,
"EUR": 10.00,
}
assert.Equal(t, 47.06, ca.GrandTotal(eurToUsdRate))
}
//==============================================================================