Test deduplication with two object arrays

This commit is contained in:
Marius Orcsik 2018-04-10 20:09:06 +02:00
parent 247c71a767
commit 9e61b5fcea
No known key found for this signature in database
GPG key ID: 889CE8E4FB2D877A
2 changed files with 14 additions and 6 deletions

View file

@ -284,6 +284,7 @@ func RecipientsDeduplication(recArgs ...*ObjectsArr) error {
if recList == nil {
continue
}
toRemove := make([]int, 0)
for i, rec := range *recList {
save := true
@ -301,11 +302,7 @@ func RecipientsDeduplication(recArgs ...*ObjectsArr) error {
sort.Sort(sort.Reverse(sort.IntSlice(toRemove)))
for _, idx := range toRemove {
if idx == len(*recList) {
*recList = (*recList)[:idx]
} else {
*recList = append((*recList)[:idx], (*recList)[idx+1:]...)
}
*recList = append((*recList)[:idx], (*recList)[idx+1:]...)
}
}
return nil

View file

@ -178,7 +178,18 @@ func TestRecipientsDeduplication(t *testing.T) {
RecipientsDeduplication(&first)
if len(first) != 4 {
t.Errorf("Objects array should have exactly 8(eight) elements, not %d", len(first))
t.Errorf("Objects array should have exactly 4(four) elements, not %d", len(first))
}
second := make(ObjectsArr, 0)
second.Append(bar)
second.Append(foo)
RecipientsDeduplication(&first, &second)
if len(first) != 4 {
t.Errorf("First Objects array should have exactly 8(eight) elements, not %d", len(first))
}
if len(second) != 0 {
t.Errorf("Second Objects array should have exactly 0(zero) elements, not %d", len(second))
}
}