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

     1  package slice
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func ignorePanic(fn func()) {
     9  	defer func() {
    10  		if e := recover(); e != nil {
    11  			fmt.Println(e)
    12  		}
    13  	}()
    14  	fn()
    15  }
    16  
    17  func TestChunks(t *testing.T) {
    18  	a := Chunks[int]{{}, {1, 2, 3}, {}, {4, 5, 6}, {7, 8, 9, 10}, {}}
    19  	fmt.Println(a.Slice(10, 10))
    20  	//a := Chunks[int]{{}, {}, {}, {}, {}, {}}
    21  	for i := -1; i < 12; i++ {
    22  		ignorePanic(func() {
    23  			fmt.Println(a.Slice(-1, i))
    24  		})
    25  	}
    26  	for i := -1; i < 12; i++ {
    27  		ignorePanic(func() {
    28  			fmt.Println(a.Slice(i, -1))
    29  		})
    30  	}
    31  	for i := 0; i < 12; i++ {
    32  		for j := 0; j < 12; j++ {
    33  			ignorePanic(func() {
    34  				fmt.Println(a.Slice(i, j))
    35  			})
    36  		}
    37  	}
    38  }