v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/util/slice/object_test.go (about)

     1  package slice
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestObject(t *testing.T) {
     9  	type args struct {
    10  		keys   []uint64
    11  		values []string
    12  	}
    13  	tests := []struct {
    14  		name string
    15  		args args
    16  		want map[uint64]string
    17  	}{
    18  		{
    19  			name: "Object keys=1 values=1",
    20  			args: args{
    21  				keys:   []uint64{1},
    22  				values: []string{"1"},
    23  			},
    24  			want: map[uint64]string{1: "1"},
    25  		},
    26  		{
    27  			name: "Object keys=1 values=2",
    28  			args: args{
    29  				keys:   []uint64{1},
    30  				values: []string{"1", "2"},
    31  			},
    32  			want: map[uint64]string{1: "1"},
    33  		},
    34  		{
    35  			name: "Object keys=10 values=10",
    36  			args: args{
    37  				keys:   []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
    38  				values: []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"},
    39  			},
    40  			want: map[uint64]string{
    41  				1:  "1",
    42  				2:  "2",
    43  				3:  "3",
    44  				4:  "4",
    45  				5:  "5",
    46  				6:  "6",
    47  				7:  "7",
    48  				8:  "8",
    49  				9:  "9",
    50  				10: "10",
    51  			},
    52  		},
    53  		{
    54  			name: "Object keys=0 values=0",
    55  			args: args{
    56  				keys:   []uint64{},
    57  				values: []string{},
    58  			},
    59  			want: map[uint64]string{},
    60  		},
    61  		{
    62  			name: "Object keys=5 values=3",
    63  			args: args{
    64  				keys:   []uint64{1, 2, 3, 4, 5},
    65  				values: []string{"1", "2", "3"},
    66  			},
    67  			want: map[uint64]string{1: "1", 2: "2", 3: "3"},
    68  		},
    69  	}
    70  	for _, tt := range tests {
    71  		t.Run(tt.name, func(t *testing.T) {
    72  			if got := Object(tt.args.keys, tt.args.values); !reflect.DeepEqual(got, tt.want) {
    73  				t.Errorf("Object() = %v, want %v", got, tt.want)
    74  			}
    75  		})
    76  	}
    77  }