gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

atomic_test.tpl (1487B)


      1 package atomics_test
      2 
      3 import (
      4     "atomic"
      5     "unsafe"
      6     "testing"
      7 
      8     "codeberg.org/gruf/go-atomics"
      9 )
     10 
     11 func Test{{ .Name }}StoreLoad(t *testing.T) {
     12     for _, test := range {{ .Name }}Tests {
     13         val := atomics.New{{ .Name }}()
     14 
     15         val.Store(test.V1)
     16 
     17         if !({{ call .Compare "val.Load()" "test.V1" }}) {
     18             t.Fatalf("failed testing .Store and .Load: expect=%v actual=%v", val.Load(), test.V1)
     19         }
     20 
     21         val.Store(test.V2)
     22 
     23         if !({{ call .Compare "val.Load()" "test.V2" }}) {
     24             t.Fatalf("failed testing .Store and .Load: expect=%v actual=%v", val.Load(), test.V2)
     25         }
     26     }
     27 }
     28 
     29 func Test{{ .Name }}CAS(t *testing.T) {
     30     for _, test := range {{ .Name }}Tests {
     31         val := atomics.New{{ .Name }}()
     32 
     33         val.Store(test.V1)
     34 
     35         if val.CAS(test.V2, test.V1) {
     36             t.Fatalf("failed testing negative .CAS: test=%+v state=%v", test, val.Load())
     37         }
     38 
     39         if !val.CAS(test.V1, test.V2) {
     40             t.Fatalf("failed testing positive .CAS: test=%+v state=%v", test, val.Load())
     41         }
     42     }
     43 }
     44 
     45 func Test{{ .Name }}Swap(t *testing.T) {
     46     for _, test := range {{ .Name }}Tests {
     47         val := atomics.New{{ .Name }}()
     48 
     49         val.Store(test.V1)
     50 
     51         if !({{ call .Compare "val.Swap(test.V2)" "test.V1" }}) {
     52             t.Fatal("failed testing .Swap")
     53         }
     54 
     55         if !({{ call .Compare "val.Swap(test.V1)" "test.V2" }}) {
     56             t.Fatal("failed testing .Swap")
     57         }
     58     }
     59 }
     60