github.com/haraldrudell/parl@v0.4.176/pslices/ordered_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 ) 13 14 func TestOrdered(t *testing.T) { 15 v1 := 2 16 v2 := 4 17 18 var ordered parli.Ordered[int] 19 var ordered2 parli.Ordered[int] 20 var index int 21 22 ordered = NewOrdered[int]() 23 24 // check duplicates 25 ordered.Insert(v1) 26 ordered.Insert(v1) 27 if ordered.Length() != 1 { 28 t.Errorf("Length not 1: %d", ordered.Length()) 29 } 30 31 index = ordered.Index(v1) 32 if index != 0 { 33 t.Errorf("Index not 0: %d", index) 34 } 35 index = ordered.Index(v2) 36 if index != -1 { 37 t.Errorf("Index not -1: %d", index) 38 } 39 40 ordered2 = ordered.Clone() 41 if ordered2.Length() != 1 { 42 t.Errorf("Length2 not 1: %d", ordered.Length()) 43 } 44 45 ordered.Delete(v2) 46 ordered.Delete(v1) 47 48 }