You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.3 KiB
80 lines
1.3 KiB
3 years ago
|
package group
|
||
|
|
||
|
import (
|
||
3 years ago
|
"reflect"
|
||
3 years ago
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestGroupGet(t *testing.T) {
|
||
|
count := 0
|
||
|
g := NewGroup(func() interface{} {
|
||
|
count++
|
||
|
return count
|
||
|
})
|
||
|
v := g.Get("key_0")
|
||
3 years ago
|
if !reflect.DeepEqual(v.(int), 1) {
|
||
|
t.Errorf("expect 1, actual %v", v)
|
||
|
}
|
||
3 years ago
|
|
||
|
v = g.Get("key_1")
|
||
3 years ago
|
if !reflect.DeepEqual(v.(int), 2) {
|
||
|
t.Errorf("expect 2, actual %v", v)
|
||
|
}
|
||
3 years ago
|
|
||
|
v = g.Get("key_0")
|
||
3 years ago
|
if !reflect.DeepEqual(v.(int), 1) {
|
||
|
t.Errorf("expect 1, actual %v", v)
|
||
|
}
|
||
|
if !reflect.DeepEqual(count, 2) {
|
||
|
t.Errorf("expect count 2, actual %v", count)
|
||
|
}
|
||
3 years ago
|
}
|
||
|
|
||
|
func TestGroupReset(t *testing.T) {
|
||
|
g := NewGroup(func() interface{} {
|
||
|
return 1
|
||
|
})
|
||
|
g.Get("key")
|
||
|
call := false
|
||
|
g.Reset(func() interface{} {
|
||
|
call = true
|
||
|
return 1
|
||
|
})
|
||
|
|
||
|
length := 0
|
||
|
for range g.vals {
|
||
|
length++
|
||
|
}
|
||
3 years ago
|
if !reflect.DeepEqual(length, 0) {
|
||
|
t.Errorf("expect length 0, actual %v", length)
|
||
|
}
|
||
3 years ago
|
|
||
|
g.Get("key")
|
||
3 years ago
|
if !reflect.DeepEqual(call, true) {
|
||
|
t.Errorf("expect call true, actual %v", call)
|
||
|
}
|
||
3 years ago
|
}
|
||
|
|
||
|
func TestGroupClear(t *testing.T) {
|
||
|
g := NewGroup(func() interface{} {
|
||
|
return 1
|
||
|
})
|
||
|
g.Get("key")
|
||
|
length := 0
|
||
|
for range g.vals {
|
||
|
length++
|
||
|
}
|
||
3 years ago
|
if !reflect.DeepEqual(length, 1) {
|
||
|
t.Errorf("expect length 1, actual %v", length)
|
||
|
}
|
||
3 years ago
|
|
||
|
g.Clear()
|
||
|
length = 0
|
||
|
for range g.vals {
|
||
|
length++
|
||
|
}
|
||
3 years ago
|
if !reflect.DeepEqual(length, 0) {
|
||
|
t.Errorf("expect length 0, actual %v", length)
|
||
|
}
|
||
3 years ago
|
}
|