Fixed Coins IsValid, issue #8

This commit is contained in:
Ethan Frey 2017-01-31 12:24:49 +01:00
parent 6e3a199f09
commit 2f7875dec0
2 changed files with 15 additions and 0 deletions

View File

@ -35,6 +35,8 @@ func (coins Coins) IsValid() bool {
if coin.Amount == 0 {
return false
}
// we compare each coin against the last denom
lowDenom = coin.Denom
}
return true
}

View File

@ -42,6 +42,19 @@ func TestCoinsBadSort(t *testing.T) {
}
}
func TestCoinsBadSort2(t *testing.T) {
// both are after the first one, but the second and third are in the wrong order
coins := Coins{
Coin{"GAS", 1},
Coin{"TREE", 1},
Coin{"MINERAL", 1},
}
if coins.IsValid() {
t.Fatal("Coins are not sorted")
}
}
func TestCoinsBadAmount(t *testing.T) {
coins := Coins{
Coin{"GAS", 1},