You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
374 B
Go
34 lines
374 B
Go
package syncx
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestOnce(t *testing.T) {
|
|
var v int
|
|
add := Once(func() {
|
|
v++
|
|
})
|
|
|
|
for i := 0; i < 5; i++ {
|
|
add()
|
|
}
|
|
|
|
assert.Equal(t, 1, v)
|
|
}
|
|
|
|
func BenchmarkOnce(b *testing.B) {
|
|
var v int
|
|
add := Once(func() {
|
|
v++
|
|
})
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
add()
|
|
}
|
|
assert.Equal(b, 1, v)
|
|
}
|