github.com/vugu/vugu@v0.3.6-0.20240430171613-3f6f402e014b/comp-key_test.go (about)

     1  package vugu
     2  
     3  import (
     4  	"log"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestCompKey(t *testing.T) {
    11  
    12  	assert := assert.New(t)
    13  
    14  	id := MakeCompKeyIDNowRand()
    15  	log.Printf("id=%#v", id)
    16  
    17  	m := make(map[CompKey]bool, 5000)
    18  	for i := 0; i < 5000; i++ {
    19  		ck := CompKey{ID: MakeCompKeyIDNowRand()}
    20  		if m[ck] {
    21  			t.Logf("CompKey %#v found duplicate", ck)
    22  			t.Fail()
    23  		}
    24  		m[ck] = true
    25  	}
    26  
    27  	// verify that different IterKey values are distinct
    28  	m = make(map[CompKey]bool)
    29  	ck1 := CompKey{ID: MakeCompKeyIDNowRand(), IterKey: int(123)}
    30  	m[ck1] = true
    31  	assert.False(m[CompKey{ID: ck1.ID, IterKey: nil}])
    32  	assert.False(m[CompKey{ID: ck1.ID, IterKey: int(122)}])
    33  	assert.False(m[CompKey{ID: ck1.ID, IterKey: uint(123)}])
    34  	assert.True(m[CompKey{ID: ck1.ID, IterKey: int(123)}])
    35  
    36  }