Commit c3462234 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel

Added IsNegative/IsZero/IsNonPositive functions to Amount

parent 5ef0bac3
......@@ -125,6 +125,21 @@ func (amt Amount) String() string {
return fmt.Sprintf("%s %s", amt.Currency, amt.Value.String())
}
// IsNegative returns true iff the amount is negative.
func (amt Amount) IsNegative() bool {
return amt.Value.Cents() < 0
}
// IsZero returns true iff the amount is zero.
func (amt Amount) IsZero() bool {
return amt.Value.Cents() == 0
}
// IsNonPositive returns true iff the amount is non-positive.
func (amt Amount) IsNonPositive() bool {
return amt.Value.Cents() <= 0
}
// Cents returns the number of cents as int.
func (c Cents) Cents() int {
return int(c)
......
......@@ -91,4 +91,18 @@ func TestAmount_Comparisons(t *testing.T) {
assert.True(t, a.Equals(NewAmount("EUR", 47)))
assert.False(t, a.Equals(b))
assert.False(t, a.Equals(NewAmount("HRK", a.Value.Cents())))
assert.False(t, a.IsNegative())
assert.False(t, a.IsZero())
assert.False(t, a.IsNonPositive())
z := NewAmount("EUR", 0)
assert.False(t, z.IsNegative())
assert.True(t, z.IsZero())
assert.True(t, z.IsNonPositive())
n := NewAmount("EUR", -30)
assert.True(t, n.IsNegative())
assert.False(t, n.IsZero())
assert.True(t, n.IsNonPositive())
}
......@@ -79,7 +79,7 @@ func (c *Client) SessionStart() {
"firstName": c.session.UserPerson.FirstName,
"lastName": c.session.UserPerson.LastName,
"session": c.session.Token,
}).Info("session created")
}).Debug("session created")
}
// SessionStop closes the current bunq session.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment