github.com/primecitizens/pcz/std@v0.2.1/core/iter/utils_test.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  package iter
     5  
     6  import "testing"
     7  
     8  func TestIndex(t *testing.T) {
     9  	type args struct {
    10  		i int
    11  		n int
    12  	}
    13  	tests := []struct {
    14  		name      string
    15  		args      args
    16  		wantIndex int
    17  		wantValid bool
    18  	}{
    19  		{
    20  			name:      "index > sz",
    21  			args:      args{1, 0},
    22  			wantIndex: 1,
    23  			wantValid: false,
    24  		},
    25  		{
    26  			name:      "index = sz",
    27  			args:      args{1, 1},
    28  			wantIndex: 1,
    29  			wantValid: false,
    30  		},
    31  		{
    32  			name:      "neg index > sz",
    33  			args:      args{-2, 0},
    34  			wantIndex: -1,
    35  			wantValid: false,
    36  		},
    37  		{
    38  			name:      "neg index > sz",
    39  			args:      args{-3, 1},
    40  			wantIndex: -2,
    41  			wantValid: false,
    42  		},
    43  		{
    44  			name:      "index < sz",
    45  			args:      args{1, 2},
    46  			wantIndex: 1,
    47  			wantValid: true,
    48  		},
    49  		{
    50  			name:      "index < sz",
    51  			args:      args{0, 1},
    52  			wantIndex: 0,
    53  			wantValid: true,
    54  		},
    55  		{
    56  			name:      "neg index < sz",
    57  			args:      args{-2, 3},
    58  			wantIndex: 1,
    59  			wantValid: true,
    60  		},
    61  		{
    62  			name:      "neg index < sz",
    63  			args:      args{-3, 3},
    64  			wantIndex: 0,
    65  			wantValid: true,
    66  		},
    67  	}
    68  	for _, tt := range tests {
    69  		t.Run(tt.name, func(t *testing.T) {
    70  			gotIndex, gotValid := Index(tt.args.i, tt.args.n)
    71  			if gotIndex != tt.wantIndex {
    72  				t.Errorf("Index() gotIndex = %v, want %v", gotIndex, tt.wantIndex)
    73  			}
    74  			if gotValid != tt.wantValid {
    75  				t.Errorf("Index() gotValid = %v, want %v", gotValid, tt.wantValid)
    76  			}
    77  		})
    78  	}
    79  }
    80  
    81  func TestBound(t *testing.T) {
    82  	type args struct {
    83  		i int
    84  		n int
    85  	}
    86  	tests := []struct {
    87  		name      string
    88  		args      args
    89  		wantBound int
    90  		wantValid bool
    91  	}{
    92  		{
    93  			name:      "bound > sz",
    94  			args:      args{1, 0},
    95  			wantBound: 1,
    96  			wantValid: false,
    97  		},
    98  		{
    99  			name:      "bound = sz",
   100  			args:      args{1, 1},
   101  			wantBound: 1,
   102  			wantValid: true,
   103  		},
   104  		{
   105  			name:      "neg bound > sz",
   106  			args:      args{-2, 0},
   107  			wantBound: -1,
   108  			wantValid: false,
   109  		},
   110  		{
   111  			name:      "neg bound > sz",
   112  			args:      args{-4, 1},
   113  			wantBound: -2,
   114  			wantValid: false,
   115  		},
   116  		{
   117  			name:      "bound < sz",
   118  			args:      args{1, 2},
   119  			wantBound: 1,
   120  			wantValid: true,
   121  		},
   122  		{
   123  			name:      "bound < sz",
   124  			args:      args{0, 1},
   125  			wantBound: 0,
   126  			wantValid: true,
   127  		},
   128  		{
   129  			name:      "neg bound < sz",
   130  			args:      args{-2, 3},
   131  			wantBound: 2,
   132  			wantValid: true,
   133  		},
   134  		{
   135  			name:      "neg bound < sz",
   136  			args:      args{-4, 3},
   137  			wantBound: 0,
   138  			wantValid: true,
   139  		},
   140  	}
   141  	for _, tt := range tests {
   142  		t.Run(tt.name, func(t *testing.T) {
   143  			gotBound, gotValid := Bound(tt.args.i, tt.args.n)
   144  			if gotBound != tt.wantBound {
   145  				t.Errorf("Bound() gotBound = %v, want %v", gotBound, tt.wantBound)
   146  			}
   147  			if gotValid != tt.wantValid {
   148  				t.Errorf("Bound() gotValid = %v, want %v", gotValid, tt.wantValid)
   149  			}
   150  		})
   151  	}
   152  }
   153  
   154  func TestStartEnd(t *testing.T) {
   155  	type args struct {
   156  		i int
   157  		j int
   158  		n int
   159  	}
   160  	tests := []struct {
   161  		name        string
   162  		args        args
   163  		wantActuali int
   164  		wantActualj int
   165  		wantValid   bool
   166  	}{
   167  		// TODO: Add test cases.
   168  	}
   169  	for _, tt := range tests {
   170  		t.Run(tt.name, func(t *testing.T) {
   171  			gotActuali, gotActualj, gotValid := Range(tt.args.i, tt.args.j, tt.args.n)
   172  			if gotActuali != tt.wantActuali {
   173  				t.Errorf("StartEnd() gotActuali = %v, want %v", gotActuali, tt.wantActuali)
   174  			}
   175  			if gotActualj != tt.wantActualj {
   176  				t.Errorf("StartEnd() gotActualj = %v, want %v", gotActualj, tt.wantActualj)
   177  			}
   178  			if gotValid != tt.wantValid {
   179  				t.Errorf("StartEnd() gotValid = %v, want %v", gotValid, tt.wantValid)
   180  			}
   181  		})
   182  	}
   183  }
   184  
   185  func TestEach(t *testing.T) {
   186  	type args struct {
   187  		iter SliceIter[int]
   188  		fn   func(i int, v int) bool
   189  	}
   190  	tests := []struct {
   191  		name string
   192  		args args
   193  	}{
   194  		// TODO: Add test cases.
   195  	}
   196  	for _, tt := range tests {
   197  		t.Run(tt.name, func(t *testing.T) {
   198  			Each(tt.args.iter, tt.args.fn)
   199  		})
   200  	}
   201  }
   202  
   203  func TestEachEx(t *testing.T) {
   204  	type args struct {
   205  		iter Core[int]
   206  		arg  float32
   207  		fn   func(i int, v int, arg float32) bool
   208  	}
   209  	tests := []struct {
   210  		name string
   211  		args args
   212  	}{
   213  		// TODO: Add test cases.
   214  	}
   215  	for _, tt := range tests {
   216  		t.Run(tt.name, func(t *testing.T) {
   217  			EachEx(tt.args.iter, tt.args.arg, tt.args.fn)
   218  		})
   219  	}
   220  }