From 6d8578c056fee8e91486129e7ec8b5a1838292ea Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Tue, 4 Apr 2017 20:20:31 -0400 Subject: [PATCH] Add test for Amount.Equal() --- types_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/types_test.go b/types_test.go index e2dc8ac..026bdb8 100644 --- a/types_test.go +++ b/types_test.go @@ -121,6 +121,33 @@ func TestUnmarshalAmount(t *testing.T) { unmarshalHelper2(t, "-19487135\n", &a, &overwritten, eq) } +func TestAmountEqual(t *testing.T) { + assertEq := func(a, b ofxgo.Amount) { + if !a.Equal(b) { + t.Fatalf("Amounts should be equal but Equal returned false: %s and %s\n", a, b) + } + } + assertNEq := func(a, b ofxgo.Amount) { + if a.Equal(b) { + t.Fatalf("Amounts should not be equal but Equal returned true: %s and %s\n", a, b) + } + } + + var a, b ofxgo.Amount + a.SetInt64(-19487135) + b.SetInt64(-19487135) + assertEq(a, b) + b.SetInt64(19487135) + assertNEq(a, b) + b.SetInt64(0) + assertNEq(a, b) + a.SetInt64(-0) + assertEq(a, b) + a.SetFrac64(1, 1000000000000000000) + b.SetFrac64(1, 1000000000000000001) + assertNEq(a, b) +} + func TestMarshalDate(t *testing.T) { var d *ofxgo.Date UTC := time.FixedZone("UTC", 0)