git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/slicesx/unique_test.go (about)

     1  package slicesx_test
     2  
     3  import (
     4  	"slices"
     5  	"testing"
     6  
     7  	"git.sr.ht/~pingoo/stdx/slicesx"
     8  	"git.sr.ht/~pingoo/stdx/uuid"
     9  )
    10  
    11  func TestUniqueUUIDs(t *testing.T) {
    12  	uuid1 := uuid.NewV4()
    13  	uuid2 := uuid.NewV4()
    14  	uuid3 := uuid.NewV4()
    15  	uuid4 := uuid.NewV4()
    16  	uuid5 := uuid.NewV4()
    17  
    18  	input := [][]uuid.UUID{
    19  		{},
    20  		{uuid1},
    21  		{uuid1, uuid1},
    22  		{uuid1, uuid1, uuid2},
    23  		{uuid1, uuid1, uuid2, uuid2, uuid1, uuid3},
    24  		{uuid1, uuid2, uuid3, uuid4, uuid5},
    25  	}
    26  	expected := [][]uuid.UUID{
    27  		{},
    28  		{uuid1},
    29  		{uuid1},
    30  		{uuid1, uuid2},
    31  		{uuid1, uuid2, uuid3},
    32  		{uuid1, uuid2, uuid3, uuid4, uuid5},
    33  	}
    34  
    35  	for i := range input {
    36  		output := slicesx.Unique(input[i])
    37  		if !slices.EqualFunc(expected[i], output, func(a, b uuid.UUID) bool {
    38  			return a.String() == b.String()
    39  		}) {
    40  			t.Errorf("(%d) %#v (output) != %#v (expected)", i, output, expected[i])
    41  		}
    42  	}
    43  
    44  }