Skip to content

Commit

Permalink
refactor Complex64 test
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Apr 25, 2021
1 parent bf9f055 commit 448e8aa
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions complex64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package atomix
import "testing"

func TestComplex64(t *testing.T) {
a := NewComplex64(complex(float32(10.5), float32(10.5)))
a := NewComplex64(complex(float32(10.5), float32(12.3)))

Equal(t, complex(float32(10.5), float32(10.5)), a.Load(), "Load wrong value")
Equal(t, "(10.5+12.3i)", a.String(), "Wrong String")

Equal(t, complex(float32(10.8), float32(10.8)), a.Add(complex(float32(0.3), float32(0.3))), "Add wrong value")
Equal(t, complex(float32(10.3), float32(10.3)), a.Sub(complex(float32(0.5), float32(0.5))), "Sub wrong value")
Equal(t, complex(float32(10.5), 12.3), a.Load(), "Load wrong value")

OK(t, a.CAS(complex(float32(10.3), float32(10.3)), complex(float32(0.5), float32(0.5))), "CAS should swap")
Equal(t, complex(float32(10.8), float32(12.6)), a.Add(complex(float32(0.3), float32(0.3))), "Add wrong value")
Equal(t, complex(float32(10.3), float32(12.1)), a.Sub(complex(float32(0.5), float32(0.5))), "Sub wrong value")

OK(t, a.CAS(complex(float32(10.3), float32(12.1)), complex(float32(0.5), float32(0.5))), "CAS should swap")
Equal(t, complex(float32(0.5), float32(0.5)), a.Load(), "CAS wrong value")
NotOK(t, a.CAS(complex(float32(0.0), float32(0.0)), complex(float32(1.5), float32(1.5))), "CAS shouldn't swap")

Expand Down

0 comments on commit 448e8aa

Please sign in to comment.