github.com/cloudwego/kitex@v0.9.0/pkg/utils/int_len_test.go (about)

     1  /*
     2   * Copyright 2021 CloudWeGo Authors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package utils
    18  
    19  import "testing"
    20  
    21  func TestGetUIntLen(t *testing.T) {
    22  	type args struct {
    23  		n uint64
    24  	}
    25  	tests := []struct {
    26  		name string
    27  		args args
    28  		want int
    29  	}{
    30  		{
    31  			name: "0",
    32  			args: args{0},
    33  			want: 1,
    34  		},
    35  		{
    36  			name: "5",
    37  			args: args{5},
    38  			want: 1,
    39  		},
    40  		{
    41  			name: "10",
    42  			args: args{10},
    43  			want: 2,
    44  		},
    45  		{
    46  			name: "56",
    47  			args: args{56},
    48  			want: 2,
    49  		},
    50  		{
    51  			name: "102",
    52  			args: args{102},
    53  			want: 3,
    54  		},
    55  		{
    56  			name: "99999",
    57  			args: args{99999},
    58  			want: 5,
    59  		},
    60  	}
    61  	for _, tt := range tests {
    62  		t.Run(tt.name, func(t *testing.T) {
    63  			if got := GetUIntLen(tt.args.n); got != tt.want {
    64  				t.Errorf("GetIntLen() = %v, want %v", got, tt.want)
    65  			}
    66  		})
    67  	}
    68  }