Skip to content

Commit

Permalink
Fixed Coins IsValid, issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Jan 31, 2017
1 parent 6e3a199 commit 2f7875d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions types/coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 2f7875d

Please sign in to comment.