github.com/scottcagno/storage@v1.8.0/pkg/hashmap/openaddr/rhhmap_u64_test.go (about)

     1  package openaddr
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/scottcagno/storage/pkg/util"
     6  	"testing"
     7  )
     8  
     9  func Test_HashMapU64_Del(t *testing.T) {
    10  	hm := NewHashMapU64(128)
    11  	for i := 0; i < len(words); i++ {
    12  		hm.Set(uint64(i), 0x69)
    13  	}
    14  	util.AssertExpected(t, 25, hm.Len())
    15  	count := hm.Len()
    16  	var stop = hm.Len()
    17  	for i := 0; i < stop; i++ {
    18  		ret, ok := hm.Del(uint64(i))
    19  		util.AssertExpected(t, true, ok)
    20  		util.AssertExpected(t, 0x69, ret)
    21  		count--
    22  	}
    23  	util.AssertExpected(t, 0, count)
    24  	hm.Close()
    25  }
    26  
    27  func Test_HashMapU64_Get(t *testing.T) {
    28  	hm := NewHashMapU64(128)
    29  	for i := 0; i < len(words); i++ {
    30  		hm.Set(uint64(i), 0x69)
    31  	}
    32  	util.AssertExpected(t, 25, hm.Len())
    33  	var count int
    34  	for i := 0; i < hm.Len(); i++ {
    35  		ret, ok := hm.Get(uint64(i))
    36  		util.AssertExpected(t, true, ok)
    37  		util.AssertExpected(t, 0x69, ret)
    38  		count++
    39  	}
    40  	util.AssertExpected(t, 25, count)
    41  	hm.Close()
    42  }
    43  
    44  func Test_HashMapU64_Len(t *testing.T) {
    45  	hm := NewHashMapU64(128)
    46  	for i := 0; i < len(words); i++ {
    47  		hm.Set(uint64(i), 0x69)
    48  	}
    49  	util.AssertExpected(t, 25, hm.Len())
    50  	hm.Close()
    51  }
    52  
    53  func Test_HashMapU64_PercentFull(t *testing.T) {
    54  	hm := NewHashMapU64(0)
    55  	for i := 0; i < len(words); i++ {
    56  		hm.Set(uint64(i), 0x69)
    57  	}
    58  	percent := fmt.Sprintf("%.2f", hm.PercentFull())
    59  	util.AssertExpected(t, "0.78", percent)
    60  	hm.Close()
    61  }
    62  
    63  func Test_HashMapU64_Set(t *testing.T) {
    64  	hm := NewHashMapU64(128)
    65  	for i := 0; i < len(words); i++ {
    66  		hm.Set(uint64(i), 0x69)
    67  	}
    68  	util.AssertExpected(t, 25, hm.Len())
    69  	hm.Close()
    70  }
    71  
    72  func Test_HashMapU64_Range(t *testing.T) {
    73  	hm := NewHashMapU64(128)
    74  	for i := 0; i < len(words); i++ {
    75  		hm.Set(uint64(i), 0x69)
    76  	}
    77  	util.AssertExpected(t, 25, hm.Len())
    78  	var counted int
    79  	hm.Range(func(key uint64, value uint64) bool {
    80  		if key != 0 && value == 0x69 {
    81  			counted++
    82  			return true
    83  		}
    84  		return false
    85  	})
    86  	util.AssertExpected(t, 25, counted)
    87  	hm.Close()
    88  }