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

     1  package slice
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestUnsafeIndex(t *testing.T) {
     9  	type args struct {
    10  		s []int
    11  		n uintptr
    12  	}
    13  	tests := []struct {
    14  		name string
    15  		args args
    16  		want int
    17  	}{
    18  		{
    19  			name: "test1",
    20  			args: args{
    21  				s: []int{1, 2, 3, 4, 5},
    22  				n: 2,
    23  			},
    24  			want: 3,
    25  		},
    26  		{
    27  			name: "test2",
    28  			args: args{
    29  				s: []int{1, 2, 3, 4, 5},
    30  				n: 4,
    31  			},
    32  			want: 5,
    33  		},
    34  	}
    35  	for _, tt := range tests {
    36  		t.Run(tt.name, func(t *testing.T) {
    37  			if got := UnsafeIndex(tt.args.s, tt.args.n); !reflect.DeepEqual(got, tt.want) {
    38  				t.Errorf("UnsafeIndex() = %v, want %v", got, tt.want)
    39  			}
    40  		})
    41  	}
    42  }