Add note about contract

This commit is contained in:
Adrian Brink 2018-01-23 16:22:14 +01:00 committed by Jae Kwon
parent 1cc0cf236c
commit 12fef05733
2 changed files with 3 additions and 1 deletions

View File

@ -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

View File

@ -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)
}
}