github.com/haraldrudell/parl@v0.4.176/pslices/ordered-any_test.go (about) 1 /* 2 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package pslices 7 8 import ( 9 "testing" 10 11 "github.com/haraldrudell/parl/parli" 12 "golang.org/x/exp/slices" 13 ) 14 15 func TestNewOrderedAny(t *testing.T) { 16 v1 := 1 17 v2 := 2 18 exp2 := []int{v1, v2} 19 20 var list parli.Ordered[int] 21 var list2 parli.Ordered[int] 22 var actual []int 23 var actInt int 24 cmp := func(a, b int) (result int) { 25 if a > b { 26 return 1 27 } else if a < b { 28 return -1 29 } 30 return 0 31 } 32 33 list = NewOrderedAny(cmp) 34 35 list.Insert(v2) 36 list.Insert(v1) 37 actual = list.List() 38 if slices.Compare(actual, exp2) != 0 { 39 t.Errorf("bad slice %v exp %v", actual, exp2) 40 } 41 42 list.Delete(v1) 43 if actInt = list.Index(v2); actInt != 0 { 44 t.Errorf("bad Index %d exp %d", actInt, 0) 45 } 46 if actInt = list.Index(v1); actInt != -1 { 47 t.Errorf("bad Index2 %d exp %d", actInt, -1) 48 } 49 50 list2 = list.Clone() 51 if slices.Compare(list.List(), list2.List()) != 0 { 52 t.Errorf("bad Clone %v exp %v", list.List(), list2.List()) 53 } 54 55 }