Add note about contract
This commit is contained in:
parent
1cc0cf236c
commit
12fef05733
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue