-
Notifications
You must be signed in to change notification settings - Fork 5
/
options_test.go
92 lines (83 loc) · 2.04 KB
/
options_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package memorycache
import (
"testing"
"time"
"github.com/dolthub/swiss"
"github.com/lxzan/memorycache/internal/containers"
"github.com/stretchr/testify/assert"
)
func TestWithBucketNum(t *testing.T) {
var as = assert.New(t)
{
var mc = New[string, any](WithBucketNum(3))
as.Equal(mc.conf.BucketNum, 4)
}
{
var mc = New[string, any](WithBucketNum(0))
as.Equal(mc.conf.BucketNum, defaultBucketNum)
}
}
func TestWithInterval(t *testing.T) {
var as = assert.New(t)
{
var mc = New[string, any]()
as.Equal(mc.conf.MinInterval, defaultMinInterval)
as.Equal(mc.conf.MaxInterval, defaultMaxInterval)
}
{
var mc = New[string, any](WithInterval(time.Second, 2*time.Second))
as.Equal(mc.conf.MinInterval, time.Second)
as.Equal(mc.conf.MaxInterval, 2*time.Second)
}
}
func TestWithCapacity(t *testing.T) {
var as = assert.New(t)
{
var mc = New[string, any](WithBucketSize(0, 0))
as.Equal(mc.conf.BucketSize, defaultBucketSize)
as.Equal(mc.conf.BucketCap, defaultBucketCap)
}
{
var mc = New[string, any](WithBucketSize(100, 1000))
as.Equal(mc.conf.BucketSize, 100)
as.Equal(mc.conf.BucketCap, 1000)
}
}
func TestWithDeleteLimits(t *testing.T) {
var as = assert.New(t)
{
var mc = New[string, any](WithDeleteLimits(0))
as.Equal(mc.conf.DeleteLimits, defaultDeleteLimits)
}
{
var mc = New[string, any](WithDeleteLimits(10))
as.Equal(mc.conf.DeleteLimits, 10)
}
}
func TestWithTimeCache(t *testing.T) {
var as = assert.New(t)
{
var mc = New[string, any]()
as.Equal(mc.conf.CachedTime, true)
}
{
var mc = New[string, any](WithCachedTime(false))
as.Equal(mc.conf.CachedTime, false)
}
}
func TestWithSwissTable(t *testing.T) {
t.Run("", func(t *testing.T) {
var mc = New[string, int](
WithSwissTable(true),
)
_, ok := mc.storage[0].Map.(*swiss.Map[uint64, pointer])
assert.True(t, ok)
assert.True(t, mc.conf.SwissTable)
})
t.Run("", func(t *testing.T) {
var mc = New[string, int]()
_, ok := mc.storage[0].Map.(containers.Map[uint64, pointer])
assert.True(t, ok)
assert.False(t, mc.conf.SwissTable)
})
}