github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/collection/immutable/map_/test/map_go_1_22_test.go (about)

     1  //go:build goexperiment.rangefunc
     2  
     3  package test
     4  
     5  import (
     6  	"sort"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  
    11  	"github.com/m4gshm/gollections/collection/immutable/map_"
    12  	"github.com/m4gshm/gollections/k"
    13  	"github.com/m4gshm/gollections/slice"
    14  )
    15  
    16  func Test_Map_Iterate_All(t *testing.T) {
    17  	dict := map_.Of(k.V(1, "1"), k.V(1, "1"), k.V(2, "2"), k.V(4, "4"), k.V(3, "3"), k.V(1, "1"))
    18  
    19  	expectedK := slice.Of(1, 2, 3, 4)
    20  	expectedV := slice.Of("1", "2", "3", "4")
    21  
    22  	keys := make([]int, 0)
    23  	values := make([]string, 0)
    24  
    25  	for key, val := range dict.All {
    26  		keys = append(keys, key)
    27  		values = append(values, val)
    28  	}
    29  
    30  	sort.Ints(keys)
    31  	sort.Strings(values)
    32  	assert.Equal(t, expectedK, keys)
    33  	assert.Equal(t, expectedV, values)
    34  
    35  	keys = dict.Keys().Slice()
    36  	values = dict.Values().Slice()
    37  	sort.Ints(keys)
    38  	sort.Strings(values)
    39  	assert.Equal(t, slice.Of(1, 2, 3, 4), keys)
    40  	assert.Equal(t, slice.Of("1", "2", "3", "4"), values)
    41  }