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.
28 lines
566 B
Go
28 lines
566 B
Go
4 years ago
|
package syncx
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestAtomicBool(t *testing.T) {
|
||
|
val := ForAtomicBool(true)
|
||
|
assert.True(t, val.True())
|
||
|
val.Set(false)
|
||
|
assert.False(t, val.True())
|
||
|
val.Set(true)
|
||
|
assert.True(t, val.True())
|
||
|
val.Set(false)
|
||
|
assert.False(t, val.True())
|
||
|
ok := val.CompareAndSwap(false, true)
|
||
|
assert.True(t, ok)
|
||
|
assert.True(t, val.True())
|
||
|
ok = val.CompareAndSwap(true, false)
|
||
|
assert.True(t, ok)
|
||
|
assert.False(t, val.True())
|
||
|
ok = val.CompareAndSwap(true, false)
|
||
|
assert.False(t, ok)
|
||
|
assert.False(t, val.True())
|
||
|
}
|