dubbo.apache.org/dubbo-go/v3@v3.1.1/metrics/util/aggregate/quantile_test.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   * contributor license agreements.  See the NOTICE file distributed with
     4   * this work for additional information regarding copyright ownership.
     5   * The ASF licenses this file to You under the Apache License, Version 2.0
     6   * (the "License"); you may not use this file except in compliance with
     7   * the License.  You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package aggregate
    19  
    20  import (
    21  	"testing"
    22  )
    23  
    24  func TestAddAndQuantile(t1 *testing.T) {
    25  	timeWindowQuantile := NewTimeWindowQuantile(100, 10, 1)
    26  	for i := 1; i <= 100; i++ {
    27  		timeWindowQuantile.Add(float64(i))
    28  	}
    29  
    30  	type args struct {
    31  		q float64
    32  	}
    33  
    34  	tests := []struct {
    35  		name string
    36  		args args
    37  		want float64
    38  	}{
    39  		{
    40  			name: "Quantile: 0.01",
    41  			args: args{
    42  				q: 0.01,
    43  			},
    44  			want: 1.5,
    45  		},
    46  		{
    47  			name: "Quantile: 0.99",
    48  			args: args{
    49  				q: 0.99,
    50  			},
    51  			want: 99.5,
    52  		},
    53  	}
    54  	for _, tt := range tests {
    55  		t1.Run(tt.name, func(t1 *testing.T) {
    56  			t := timeWindowQuantile
    57  			if got := t.Quantile(tt.args.q); got != tt.want {
    58  				t1.Errorf("Quantile() = %v, want %v", got, tt.want)
    59  			}
    60  		})
    61  	}
    62  }