github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/genutil/mapz/countingmap_test.go (about)

     1  package mapz
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestBasicCountingMap(t *testing.T) {
    10  	cmap := NewCountingMultiMap[string, string]()
    11  
    12  	require.False(t, cmap.Add("foo", "1"))
    13  	require.False(t, cmap.Add("foo", "2"))
    14  	require.False(t, cmap.Add("bar", "1"))
    15  
    16  	require.True(t, cmap.Add("foo", "1"))
    17  
    18  	cmap.Remove("foo", "1")
    19  
    20  	require.False(t, cmap.Add("foo", "1"))
    21  	require.True(t, cmap.Add("foo", "2"))
    22  }