Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding method for add dineros to a dineros collection #79

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dinero.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}

Expand Down
9 changes: 5 additions & 4 deletions dinero_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,9 @@ func TestMinimun(t *testing.T) {

dinero := dinerogo.NewDinero(50)

dineros := dinerogo.NewDineros()
dineros = append(dineros, *dinero1, *dinero2, *dinero3, *dinero4)
dineros := dinerogo.NewDineroCollection()

dineros = dinero.AddToCollection(dineros, *dinero1, *dinero2, *dinero3, *dinero4)

minimunDinero := dinero.Minimun(dineros)
if minimunDinero.GetAmount() != expectedAmount {
Expand All @@ -454,8 +455,8 @@ func TestMaximun(t *testing.T) {

dinero := dinerogo.NewDinero(50)

dineros := dinerogo.NewDineros()
dineros = append(dineros, *dinero1, *dinero2, *dinero3, *dinero4)
dineros := dinerogo.NewDineroCollection()
dineros = dinero.AddToCollection(dineros, *dinero1, *dinero2, *dinero3, *dinero4)

maximunDinero := dinero.Maximun(dineros)
if maximunDinero.GetAmount() != expectedAmount {
Expand Down
17 changes: 17 additions & 0 deletions methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,20 @@ 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...)
}

//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:]...)
}

//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
}