github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/isc/test/listobj_test.go (about)

     1  package test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/isyscore/isc-gobase/isc"
     7  )
     8  
     9  type MyStruct struct {
    10  	Name string
    11  	Age  int
    12  }
    13  
    14  func TestISCList_associateBy(t *testing.T) {
    15  	var testList isc.ISCList[MyStruct]
    16  	s1 := MyStruct{
    17  		Name: "K",
    18  		Age:  1,
    19  	}
    20  	testList.Add(s1)
    21  	testList.Add(MyStruct{
    22  		Name: "K2",
    23  		Age:  2,
    24  	})
    25  	testList.Add(MyStruct{
    26  		Name: "K3",
    27  		Age:  3,
    28  	})
    29  	//l := isc.AssociateBy(testList, func(t MyStruct) any {
    30  	//	return t.Name
    31  	//})
    32  	//t.Logf("%v\n", isc.ToString(l))
    33  }
    34  
    35  func TestNewListWithList(t *testing.T) {
    36  	//list := []string{"1","2"}
    37  	l := isc.NewList[string]()
    38  	t.Logf("%v", l)
    39  }
    40  
    41  func TestISCList_Add(t *testing.T) {
    42  	l := isc.NewList[string]()
    43  	l.Add("3")
    44  	t.Logf("%v", l)
    45  }
    46  
    47  func TestISCList_AddAll(t *testing.T) {
    48  	l := isc.NewList[string]()
    49  	l.AddAll("4", "5", "6")
    50  	t.Logf("%v", l)
    51  }
    52  
    53  func TestISCList_Insert(t *testing.T) {
    54  	l := isc.NewListWithItems("1", "2", "3")
    55  	l.Insert(2, "7")
    56  	t.Logf("%v", l)
    57  }
    58  
    59  func TestISCList_Delete(t *testing.T) {
    60  	l := isc.NewListWithItems("1", "2", "3", "4")
    61  	l.Delete(2)
    62  	t.Logf("%v", l)
    63  }
    64  
    65  func TestISCList_Clear(t *testing.T) {
    66  	l := isc.NewListWithItems("1", "2", "3", "4")
    67  	l.Clear()
    68  	t.Logf("%v", l)
    69  }
    70  
    71  func TestISCList_IsEmpty(t *testing.T) {
    72  	l := isc.NewListWithItems("1", "2", "3", "4")
    73  	r := l.IsEmpty()
    74  	t.Logf("%v", r)
    75  	l.Clear()
    76  	r = l.IsEmpty()
    77  	t.Logf("%v", r)
    78  }
    79  
    80  func TestISCList_ForEach(t *testing.T) {
    81  	l := isc.NewListWithItems("1", "2", "3", "4")
    82  	l.ForEach(func(item string) {
    83  		t.Logf("%s", item)
    84  	})
    85  }