atomicbool_test.go 566 B

123456789101112131415161718192021222324252627
  1. package syncx
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestAtomicBool(t *testing.T) {
  7. val := ForAtomicBool(true)
  8. assert.True(t, val.True())
  9. val.Set(false)
  10. assert.False(t, val.True())
  11. val.Set(true)
  12. assert.True(t, val.True())
  13. val.Set(false)
  14. assert.False(t, val.True())
  15. ok := val.CompareAndSwap(false, true)
  16. assert.True(t, ok)
  17. assert.True(t, val.True())
  18. ok = val.CompareAndSwap(true, false)
  19. assert.True(t, ok)
  20. assert.False(t, val.True())
  21. ok = val.CompareAndSwap(true, false)
  22. assert.False(t, ok)
  23. assert.False(t, val.True())
  24. }