From 12fef057330011db863f606742965b577c737a6a Mon Sep 17 00:00:00 2001 From: Adrian Brink Date: Tue, 23 Jan 2018 16:22:14 +0100 Subject: [PATCH] Add note about contract --- types/coin.go | 1 + types/coin_test.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/types/coin.go b/types/coin.go index eebec4896..620c2f289 100644 --- a/types/coin.go +++ b/types/coin.go @@ -73,6 +73,7 @@ func (coins Coins) IsValid() bool { } // Plus combines two sets of coins +// CONTRACT: Plus will never return Coins where one Coin has a 0 amount. func (coins Coins) Plus(coinsB Coins) Coins { sum := []Coin{} indexA, indexB := 0, 0 diff --git a/types/coin_test.go b/types/coin_test.go index 3c85b5fed..1ca3f3499 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -64,12 +64,13 @@ func TestPlusCoins(t *testing.T) { {Coins{{"A", 0}, {"B", 1}}, Coins{{"A", 0}, {"B", 0}}, Coins{{"B", 1}}}, {Coins{{"A", 0}, {"B", 0}}, Coins{{"A", 0}, {"B", 0}}, Coins{}}, {Coins{{"A", 1}, {"B", 0}}, Coins{{"A", -1}, {"B", 0}}, Coins{}}, + {Coins{{"A", -1}, {"B", 0}}, Coins{{"A", 0}, {"B", 0}}, Coins{{"A", -1}}}, } for _, tc := range cases { res := tc.inputOne.Plus(tc.inputTwo) assert.True(res.IsValid()) - assert.Equal(res, tc.expected) + assert.Equal(tc.expected, res) } }