Skip to content

Commit

Permalink
Rename CurrencyCount to CurrencyAmounts
Browse files Browse the repository at this point in the history
  • Loading branch information
leavengood committed Feb 5, 2015
1 parent b593a1a commit 8d98ff6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions paypal.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func (p PayPalTxns) Sort() {
sort.Sort(ByDate{p})
}

func (p PayPalTxns) TotalByCurrency() CurrencyCount {
result := make(CurrencyCount)
func (p PayPalTxns) TotalByCurrency() CurrencyAmounts {
result := make(CurrencyAmounts)

for _, txn := range p {
result[txn.CurrencyCode] += txn.Amt
Expand Down
2 changes: 1 addition & 1 deletion paypal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// PayPalTxns.TotalByCurrency
//==============================================================================

func CallTotalByCurrencyWith(txns ...*PayPalTxn) CurrencyCount {
func CallTotalByCurrencyWith(txns ...*PayPalTxn) CurrencyAmounts {
testing := PayPalTxns{}

testing = append(testing, txns...)
Expand Down
4 changes: 2 additions & 2 deletions summary.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

// Use a map because of multiple currencies
type CurrencyCount map[string]float32
type CurrencyAmounts map[string]float32

func (c CurrencyCount) GrandTotal(eurToUsdRate float32) float32 {
func (c CurrencyAmounts) GrandTotal(eurToUsdRate float32) float32 {
return c["USD"] + c["EUR"]*eurToUsdRate
}
8 changes: 4 additions & 4 deletions summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import (
)

//==============================================================================
// CurrencyCount.GrandTotal
// CurrencyAmounts.GrandTotal
//==============================================================================

const eurToUsdRate = 1.25

func TestGrandTotalWithEmptyMap(t *testing.T) {
cc := make(CurrencyCount)
cc := make(CurrencyAmounts)

assert.Equal(t, 0, cc.GrandTotal(eurToUsdRate))
}

func TestGrandTotalWithJustUSD(t *testing.T) {
cc := CurrencyCount{
cc := CurrencyAmounts{
"USD": 34.56,
}

assert.Equal(t, 34.56, cc.GrandTotal(eurToUsdRate))
}

func TestGrandTotalWithJustUSDAndEUR(t *testing.T) {
cc := CurrencyCount{
cc := CurrencyAmounts{
"USD": 34.56,
"EUR": 10.00,
}
Expand Down

0 comments on commit 8d98ff6

Please sign in to comment.