github.com/mitranim/gg@v0.1.17/lazy_coll_test.go (about)

     1  package gg_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/mitranim/gg"
     7  	"github.com/mitranim/gg/gtest"
     8  )
     9  
    10  func TestLazyColl(t *testing.T) {
    11  	defer gtest.Catch(t)
    12  	testColl[*gg.LazyColl[SomeKey, SomeModel]]()
    13  }
    14  
    15  func TestLazyCollOf(t *testing.T) {
    16  	defer gtest.Catch(t)
    17  
    18  	gtest.Zero(gg.LazyCollOf[SomeKey, SomeModel]())
    19  
    20  	testLazyCollMake(func(src ...SomeModel) SomeLazyColl {
    21  		return gg.LazyCollOf[SomeKey, SomeModel](src...)
    22  	})
    23  }
    24  
    25  func testLazyCollMake[Coll AnyColl](fun func(...SomeModel) Coll) {
    26  	test := func(slice []SomeModel, index map[SomeKey]int) {
    27  		tar := fun(slice...)
    28  		testCollEqual(tar, SomeColl{Slice: slice, Index: index})
    29  		gtest.Is(getCollSlice(tar), slice)
    30  	}
    31  
    32  	test(
    33  		[]SomeModel{SomeModel{10, `one`}},
    34  		nil,
    35  	)
    36  
    37  	test(
    38  		[]SomeModel{
    39  			SomeModel{10, `one`},
    40  			SomeModel{20, `two`},
    41  		},
    42  		nil,
    43  	)
    44  }
    45  
    46  func TestLazyCollFrom(t *testing.T) {
    47  	defer gtest.Catch(t)
    48  
    49  	gtest.Zero(gg.LazyCollFrom[SomeKey, SomeModel, []SomeModel]())
    50  
    51  	testLazyCollMake(func(src ...SomeModel) SomeLazyColl {
    52  		return gg.LazyCollFrom[SomeKey, SomeModel](src)
    53  	})
    54  }