github.com/haraldrudell/parl@v0.4.176/sets/set-id_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  	"testing"
    10  
    11  	"github.com/haraldrudell/parl/iters"
    12  )
    13  
    14  func TestSetID(t *testing.T) {
    15  	var value1, value2 = 1, 2
    16  	var name1, name2 = "n1", "n2"
    17  
    18  	var values = []SetElement[int]{
    19  		{ValueV: value1, Name: name1},
    20  		{ValueV: value2, Name: name2},
    21  	}
    22  
    23  	var hasValue bool
    24  	var value, elementType *SetElement[int]
    25  	var eIterator iters.Iterator[*SetElement[int]]
    26  
    27  	// IsValid() Iterator() Description() StringT() String()
    28  	var set SetID[int, SetElement[int]]
    29  	var reset = func() {
    30  		set = NewSetID[int](values)
    31  	}
    32  
    33  	// Element of element should return true
    34  	reset()
    35  	elementType = set.Element(value1)
    36  	if elementType != &values[0] {
    37  		t.Error("set.Element bad")
    38  	}
    39  
    40  	// Iterator should iterate
    41  	reset()
    42  	eIterator = set.EIterator()
    43  	value, hasValue = eIterator.Next()
    44  	_ = hasValue
    45  	if value != &values[0] {
    46  		t.Error("Iterator.Next bad")
    47  	}
    48  }