github.com/tursom/GoCollections@v0.3.10/collections/ArrayList_test.go (about)

     1  /*
     2   * Copyright (c) 2022 tursom. All rights reserved.
     3   * Use of this source code is governed by a GPL-3
     4   * license that can be found in the LICENSE file.
     5   */
     6  
     7  package collections
     8  
     9  import (
    10  	"fmt"
    11  	"testing"
    12  
    13  	"github.com/tursom/GoCollections/exceptions"
    14  	"github.com/tursom/GoCollections/lang"
    15  )
    16  
    17  func Test_NewArrayListByCapacity(t *testing.T) {
    18  	capacity := 10
    19  	list := NewArrayListByCapacity[lang.Int](capacity)
    20  	if len(list.array) != 0 && cap(list.array) != capacity {
    21  		t.Fail()
    22  	}
    23  }
    24  
    25  func Test_NewArrayListFrom(t *testing.T) {
    26  	list := NewArrayList[lang.Int]()
    27  	for i := 0; i < 10; i++ {
    28  		list.Add(lang.Int(i))
    29  	}
    30  	newList := NewArrayListFrom[lang.Int](list, 5, 6)
    31  	fmt.Println(newList)
    32  }
    33  
    34  func TestArrayListAdd(t *testing.T) {
    35  	list := NewArrayList[lang.Int]()
    36  	for i := 0; i < 10; i++ {
    37  		list.Add(lang.Int(i))
    38  		fmt.Println(list)
    39  	}
    40  	for i := 0; i < 10; i++ {
    41  		list.RemoveLast()
    42  		fmt.Println(list)
    43  	}
    44  }
    45  
    46  func TestLinkedList(t *testing.T) {
    47  	list := NewLinkedList[lang.Int]()
    48  	for i := 0; i < 10; i++ {
    49  		list.Add(lang.Int(i))
    50  		fmt.Println(list)
    51  		for j := 0; j <= i; j++ {
    52  			//exceptions.Exec2r0[
    53  			//	func(func() (error, error, error)) (error, error),
    54  			//	func() (error, error, error),
    55  			//	error,
    56  			//](
    57  			exceptions.Exec2r0(
    58  				//exceptions.Exec1r1,
    59  				//exceptions.Exec0r2,
    60  				exceptions.Exec1r1[func() (error, error, error), error, error],
    61  				exceptions.Exec0r2[error, error, error],
    62  				func() (error, error, error) {
    63  					return nil, nil, nil
    64  				},
    65  			)
    66  			//get := (*LinkedList[lang.Int]).Get
    67  			//fmt.Println(exceptions.Exec2r1[func(int) (int, exceptions.Exception), List[int], int](get, list, j).AsInt())
    68  		}
    69  	}
    70  	for i := 0; i < 10; i++ {
    71  		list.RemoveLast()
    72  		fmt.Println(list)
    73  	}
    74  }
    75  
    76  func TestEqualsFunc(t *testing.T) {
    77  	f := func() {}
    78  	fmt.Println(equals(f, f))
    79  }
    80  
    81  func equals(v1, v2 any) bool {
    82  	return v1 == v2
    83  }