github.com/haraldrudell/parl@v0.4.176/sets/map-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 TestMapSet(t *testing.T) {
    16  	var value1, value2 = basics(1), basics(2)
    17  	var value1d = strconv.Itoa(int(value1))
    18  	var m = map[basics]basics{
    19  		value1: value1,
    20  		value2: value2,
    21  	}
    22  
    23  	var isValid, hasValue bool
    24  	var value, zeroValue basics
    25  	var iterator iters.Iterator[basics]
    26  	var full string
    27  
    28  	// IsValid() Iterator() Description() StringT() String()
    29  	var set SetID[basics, basics]
    30  	var reset = func() {
    31  		// E is basics
    32  		// T is int
    33  		set = NewMapSet(m)
    34  	}
    35  
    36  	// IsValid of element should return true
    37  	reset()
    38  	isValid = set.IsValid(value1)
    39  	if !isValid {
    40  		t.Error("IsValid false")
    41  	}
    42  
    43  	// IsValid of non-element should return true
    44  	reset()
    45  	isValid = set.IsValid(zeroValue)
    46  	if isValid {
    47  		t.Error("IsValid true")
    48  	}
    49  
    50  	// Iterator should iterate
    51  	reset()
    52  	iterator = set.Iterator()
    53  	value, hasValue = iterator.Next()
    54  	_ = hasValue
    55  	if value != value1 {
    56  		t.Errorf("Iterator.Next %d exp %d", value, value1)
    57  	}
    58  
    59  	// Description
    60  	reset()
    61  	full = set.Description(value1)
    62  	if full != value1d {
    63  		t.Errorf("Description %q exp %q", full, value1d)
    64  	}
    65  
    66  	// StringT
    67  	reset()
    68  	var _ = (&FuncSet[int, string]{}).StringT
    69  	full = set.StringT(value1)
    70  	if full != value1d {
    71  		t.Errorf("StringT %q exp %q", full, value1d)
    72  	}
    73  }