From 1fff2b1aa156f9dfb93caf1a2293297ced26d51d Mon Sep 17 00:00:00 2001 From: carlos97gr Date: Thu, 17 Mar 2022 23:01:11 +0300 Subject: [PATCH 1/3] adding method for add dineros to a dineros collection --- dinero_test.go | 5 +++-- methods.go | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dinero_test.go b/dinero_test.go index c82aa16..ad856be 100644 --- a/dinero_test.go +++ b/dinero_test.go @@ -434,7 +434,8 @@ func TestMinimun(t *testing.T) { dinero := dinerogo.NewDinero(50) dineros := dinerogo.NewDineros() - dineros = append(dineros, *dinero1, *dinero2, *dinero3, *dinero4) + + dineros = dinero.AddToCollection(dineros, *dinero1, *dinero2, *dinero3, *dinero4) minimunDinero := dinero.Minimun(dineros) if minimunDinero.GetAmount() != expectedAmount { @@ -455,7 +456,7 @@ func TestMaximun(t *testing.T) { dinero := dinerogo.NewDinero(50) dineros := dinerogo.NewDineros() - dineros = append(dineros, *dinero1, *dinero2, *dinero3, *dinero4) + dineros = dinero.AddToCollection(dineros, *dinero1, *dinero2, *dinero3, *dinero4) maximunDinero := dinero.Maximun(dineros) if maximunDinero.GetAmount() != expectedAmount { diff --git a/methods.go b/methods.go index fb7df69..17ebffd 100644 --- a/methods.go +++ b/methods.go @@ -274,3 +274,8 @@ func (d *dinero) Maximun(dineros []dinero) *dinero { result := dineros[index] return &result } + +//AddToCollection : Add Dinero object to a Array of Dinero objects +func (d *dinero) AddToCollection(dineros []dinero, din ...dinero) []dinero { + return append(dineros, din...) +} From cba9c53a1b94e90cd7052222711166eb306b3a21 Mon Sep 17 00:00:00 2001 From: carlos97gr Date: Thu, 17 Mar 2022 23:11:07 +0300 Subject: [PATCH 2/3] adding remove method --- dinero.go | 2 +- dinero_test.go | 4 ++-- methods.go | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/dinero.go b/dinero.go index 1bc7bd5..9d157bd 100644 --- a/dinero.go +++ b/dinero.go @@ -61,7 +61,7 @@ func NewDineroWithPrecisionAndCurrency(amount int64, currency string, precision } // NewDineros: Create a collection for create a dinero array -func NewDineros() []dinero { +func NewDineroCollection() []dinero { return []dinero{} } diff --git a/dinero_test.go b/dinero_test.go index ad856be..e69c19f 100644 --- a/dinero_test.go +++ b/dinero_test.go @@ -433,7 +433,7 @@ func TestMinimun(t *testing.T) { dinero := dinerogo.NewDinero(50) - dineros := dinerogo.NewDineros() + dineros := dinerogo.NewDineroCollection() dineros = dinero.AddToCollection(dineros, *dinero1, *dinero2, *dinero3, *dinero4) @@ -455,7 +455,7 @@ func TestMaximun(t *testing.T) { dinero := dinerogo.NewDinero(50) - dineros := dinerogo.NewDineros() + dineros := dinerogo.NewDineroCollection() dineros = dinero.AddToCollection(dineros, *dinero1, *dinero2, *dinero3, *dinero4) maximunDinero := dinero.Maximun(dineros) diff --git a/methods.go b/methods.go index 17ebffd..38921ab 100644 --- a/methods.go +++ b/methods.go @@ -279,3 +279,9 @@ func (d *dinero) Maximun(dineros []dinero) *dinero { func (d *dinero) AddToCollection(dineros []dinero, din ...dinero) []dinero { return append(dineros, din...) } + +//RemoveFromCollection : Remove Dinero object from a Array of Dinero objects +func (d *dinero) RemoveFromCollection(dineros []dinero, index int) []dinero { + //TODO: Add validation for only positive index + return append(dineros[:index], dineros[index+1:]...) +} From 836df521ac8a4850f305efe724f12d83045f23f5 Mon Sep 17 00:00:00 2001 From: carlos97gr Date: Thu, 17 Mar 2022 23:13:45 +0300 Subject: [PATCH 3/3] update collection added --- methods.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/methods.go b/methods.go index 38921ab..1b7e6fd 100644 --- a/methods.go +++ b/methods.go @@ -285,3 +285,9 @@ func (d *dinero) RemoveFromCollection(dineros []dinero, index int) []dinero { //TODO: Add validation for only positive index return append(dineros[:index], dineros[index+1:]...) } + +//UpdateCollectionElem : Update a dinero object inside of a collection of dineros +func (d *dinero) UpdateCollectionElm(dineros []dinero, index int, newDinero dinero) []dinero { + dineros[index] = newDinero + return dineros +}