github.com/haraldrudell/parl@v0.4.176/sets/basic-set_test.go (about) 1 /* 2 © 2023–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package sets 7 8 import ( 9 "strconv" 10 "testing" 11 12 "github.com/haraldrudell/parl/iters" 13 ) 14 15 func TestBasicSet(t *testing.T) { 16 var value1, value2 = basics(1), basics(2) 17 var value1d = strconv.Itoa(int(value1)) 18 var values = []basics{value1, value2} 19 20 var isValid, hasValue bool 21 var value, zeroValue basics 22 var iterator iters.Iterator[basics] 23 var full string 24 25 // IsValid() Iterator() Description() StringT() String() 26 var set Set[basics] 27 var reset = func() { 28 set = NewBasicSet(values) 29 } 30 31 // IsValid of element should return true 32 reset() 33 isValid = set.IsValid(value1) 34 if !isValid { 35 t.Error("IsValid false") 36 } 37 38 // IsValid of non-element should return false 39 reset() 40 isValid = set.IsValid(zeroValue) 41 if isValid { 42 t.Error("IsValid true") 43 } 44 45 // Iterator should iterate 46 reset() 47 iterator = set.Iterator() 48 value, hasValue = iterator.Next() 49 _ = hasValue 50 if value != value1 { 51 t.Errorf("Iterator.Next %d exp %d", value, value1) 52 } 53 54 // Description 55 reset() 56 full = set.Description(value1) 57 if full != value1d { 58 t.Errorf("Description %q exp %q", full, value1d) 59 } 60 61 // StringT 62 reset() 63 full = set.StringT(value1) 64 if full != value1d { 65 t.Errorf("StringT %q exp %q", full, value1d) 66 } 67 } 68 69 type basics int 70 71 func (i basics) Description() (s string) { return strconv.Itoa(int(i)) }