gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/slice/slice_test.go (about)

     1  package slice
     2  
     3  import (
     4  	"fmt"
     5  	sliceUnsafe "gitee.com/sy_183/go-common/slice/unsafe"
     6  	"gitee.com/sy_183/go-common/unit"
     7  	"testing"
     8  	"unsafe"
     9  )
    10  
    11  func TestBuild(t *testing.T) {
    12  	s := make([]byte, unit.MeBiByte)
    13  	p := unsafe.Pointer(&s[0])
    14  	var bs []byte
    15  	for i := 0; i < unit.KiBiByte<<4; i++ {
    16  		for i := 0; i < unit.MeBiByte; i++ {
    17  			bs = sliceUnsafe.Build[byte](p, i, i)
    18  		}
    19  	}
    20  	fmt.Println(len(bs))
    21  }
    22  
    23  func TestConvert(t *testing.T) {
    24  	s := make([]byte, unit.MeBiByte)
    25  	var bs []byte
    26  	for i := 0; i < unit.KiBiByte<<4; i++ {
    27  		for i := 0; i < unit.MeBiByte; i++ {
    28  			bs = sliceUnsafe.Convert[byte, byte](s, i, i)
    29  		}
    30  	}
    31  	fmt.Println(len(bs))
    32  }
    33  
    34  func TestReverse(t *testing.T) {
    35  	s := make([]byte, unit.MeBiByte)
    36  	for i := 0; i < unit.KiBiByte<<4; i++ {
    37  		Reverse(s)
    38  	}
    39  	fmt.Println(s[0])
    40  }
    41  
    42  func TestGrow(t *testing.T) {
    43  	a := []int{1, 2, 3}
    44  	fmt.Println(len(a), cap(a))
    45  	a = Grow(a, 100)
    46  	fmt.Println(len(a), cap(a))
    47  }
    48  
    49  func TestAssignLen(t *testing.T) {
    50  	a := []int{1, 2, 3}
    51  	fmt.Println(len(a), cap(a))
    52  	a = AssignLen(a, 100)
    53  	fmt.Println(len(a), cap(a))
    54  }