github.com/coyove/sdss@v0.0.0-20231129015646-c2ec58cca6a2/contrib/simple/uint64_test.go (about)

     1  package simple
     2  
     3  import (
     4  	"fmt"
     5  	"math/rand"
     6  	"sort"
     7  	"testing"
     8  
     9  	"github.com/coyove/sdss/contrib/clock"
    10  )
    11  
    12  func TestDedup(t *testing.T) {
    13  	a := Uint64.Of([]int{1, 3, 2, 2})
    14  	a = Uint64.Dedup(a)
    15  	fmt.Println(a)
    16  
    17  	rand.Seed(clock.UnixNano())
    18  	for i := 0; i < 1e3; i++ {
    19  		var a, b []uint64
    20  		for i := 0; i < 1e3; i++ {
    21  			a = append(a, rand.Uint64())
    22  			b = append(b, rand.Uint64())
    23  		}
    24  		b = append(b, a[rand.Intn(len(a))])
    25  		if !Uint64.ContainsAny(a, b) {
    26  			t.Fatal()
    27  		}
    28  		if !Uint64.ContainsAny(b, a) {
    29  			t.Fatal()
    30  		}
    31  	}
    32  	for i := 0; i < 1e3; i++ {
    33  		var a, b []uint64
    34  		for i := 0; i < 1e3; i++ {
    35  			a = append(a, rand.Uint64())
    36  		}
    37  		sort.Sort(&uint64Sort{a})
    38  		b = append(b, a[0]-1, a[0], a[len(a)-1]+1)
    39  		if !Uint64.ContainsAny(a, b) {
    40  			t.Fatal()
    41  		}
    42  		if !Uint64.ContainsAny(b, a) {
    43  			t.Fatal()
    44  		}
    45  	}
    46  }