| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | // Copyright 2023 The Prometheus Authors
 | 
					
						
							|  |  |  | // Licensed under the Apache License, Version 2.0 (the "License");
 | 
					
						
							|  |  |  | // you may not use this file except in compliance with the License.
 | 
					
						
							|  |  |  | // You may obtain a copy of the License at
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Unless required by applicable law or agreed to in writing, software
 | 
					
						
							|  |  |  | // distributed under the License is distributed on an "AS IS" BASIS,
 | 
					
						
							|  |  |  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					
						
							|  |  |  | // See the License for the specific language governing permissions and
 | 
					
						
							|  |  |  | // limitations under the License.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package promql | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"math" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/stretchr/testify/require" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestBucketQuantile_ForcedMonotonicity(t *testing.T) { | 
					
						
							|  |  |  | 	eps := 1e-12 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for name, tc := range map[string]struct { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 		getInput       func() Buckets // The buckets can be modified in-place so return a new one each time.
 | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 		expectedForced bool | 
					
						
							|  |  |  | 		expectedFixed  bool | 
					
						
							|  |  |  | 		expectedValues map[float64]float64 | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		"simple - monotonic": { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 			getInput: func() Buckets { | 
					
						
							|  |  |  | 				return Buckets{ | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 10, | 
					
						
							|  |  |  | 						Count:      10, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 15, | 
					
						
							|  |  |  | 						Count:      15, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 20, | 
					
						
							|  |  |  | 						Count:      15, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 30, | 
					
						
							|  |  |  | 						Count:      15, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: math.Inf(1), | 
					
						
							|  |  |  | 						Count:      15, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			expectedForced: false, | 
					
						
							|  |  |  | 			expectedFixed:  false, | 
					
						
							|  |  |  | 			expectedValues: map[float64]float64{ | 
					
						
							|  |  |  | 				1:    15., | 
					
						
							|  |  |  | 				0.99: 14.85, | 
					
						
							|  |  |  | 				0.9:  13.5, | 
					
						
							|  |  |  | 				0.5:  7.5, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		"simple - non-monotonic middle": { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 			getInput: func() Buckets { | 
					
						
							|  |  |  | 				return Buckets{ | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 10, | 
					
						
							|  |  |  | 						Count:      10, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 15, | 
					
						
							|  |  |  | 						Count:      15, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 20, | 
					
						
							|  |  |  | 						Count:      15.00000000001, // Simulate the case there's a small imprecision in float64.
 | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 30, | 
					
						
							|  |  |  | 						Count:      15, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: math.Inf(1), | 
					
						
							|  |  |  | 						Count:      15, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			expectedForced: false, | 
					
						
							|  |  |  | 			expectedFixed:  true, | 
					
						
							|  |  |  | 			expectedValues: map[float64]float64{ | 
					
						
							|  |  |  | 				1:    15., | 
					
						
							|  |  |  | 				0.99: 14.85, | 
					
						
							|  |  |  | 				0.9:  13.5, | 
					
						
							|  |  |  | 				0.5:  7.5, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		"real example - monotonic": { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 			getInput: func() Buckets { | 
					
						
							|  |  |  | 				return Buckets{ | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 1, | 
					
						
							|  |  |  | 						Count:      6454661.3014166197, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 5, | 
					
						
							|  |  |  | 						Count:      8339611.2001912938, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 10, | 
					
						
							|  |  |  | 						Count:      14118319.2444762159, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 25, | 
					
						
							|  |  |  | 						Count:      14130031.5272856522, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 50, | 
					
						
							|  |  |  | 						Count:      46001270.3030008152, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 64, | 
					
						
							|  |  |  | 						Count:      46008473.8585563600, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 80, | 
					
						
							|  |  |  | 						Count:      46008473.8585563600, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 100, | 
					
						
							|  |  |  | 						Count:      46008473.8585563600, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 250, | 
					
						
							|  |  |  | 						Count:      46008473.8585563600, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 1000, | 
					
						
							|  |  |  | 						Count:      46008473.8585563600, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: math.Inf(1), | 
					
						
							|  |  |  | 						Count:      46008473.8585563600, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			expectedForced: false, | 
					
						
							|  |  |  | 			expectedFixed:  false, | 
					
						
							|  |  |  | 			expectedValues: map[float64]float64{ | 
					
						
							|  |  |  | 				1:    64., | 
					
						
							|  |  |  | 				0.99: 49.64475715376406, | 
					
						
							|  |  |  | 				0.9:  46.39671690938454, | 
					
						
							|  |  |  | 				0.5:  31.96098248992002, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		"real example - non-monotonic": { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 			getInput: func() Buckets { | 
					
						
							|  |  |  | 				return Buckets{ | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 1, | 
					
						
							|  |  |  | 						Count:      6454661.3014166225, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 5, | 
					
						
							|  |  |  | 						Count:      8339611.2001912957, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 10, | 
					
						
							|  |  |  | 						Count:      14118319.2444762159, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 25, | 
					
						
							|  |  |  | 						Count:      14130031.5272856504, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 50, | 
					
						
							|  |  |  | 						Count:      46001270.3030008227, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 64, | 
					
						
							|  |  |  | 						Count:      46008473.8585563824, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 80, | 
					
						
							|  |  |  | 						Count:      46008473.8585563898, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 100, | 
					
						
							|  |  |  | 						Count:      46008473.8585563824, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 250, | 
					
						
							|  |  |  | 						Count:      46008473.8585563824, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 1000, | 
					
						
							|  |  |  | 						Count:      46008473.8585563898, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: math.Inf(1), | 
					
						
							|  |  |  | 						Count:      46008473.8585563824, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			expectedForced: false, | 
					
						
							|  |  |  | 			expectedFixed:  true, | 
					
						
							|  |  |  | 			expectedValues: map[float64]float64{ | 
					
						
							|  |  |  | 				1:    64., | 
					
						
							|  |  |  | 				0.99: 49.64475715376406, | 
					
						
							|  |  |  | 				0.9:  46.39671690938454, | 
					
						
							|  |  |  | 				0.5:  31.96098248992002, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		"real example 2 - monotonic": { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 			getInput: func() Buckets { | 
					
						
							|  |  |  | 				return Buckets{ | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.005, | 
					
						
							|  |  |  | 						Count:      9.6, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.01, | 
					
						
							|  |  |  | 						Count:      9.688888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.025, | 
					
						
							|  |  |  | 						Count:      9.755555556, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.05, | 
					
						
							|  |  |  | 						Count:      9.844444444, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.1, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.25, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.5, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 1, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 2.5, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 5, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 10, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 25, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 50, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 100, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: math.Inf(1), | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			expectedForced: false, | 
					
						
							|  |  |  | 			expectedFixed:  false, | 
					
						
							|  |  |  | 			expectedValues: map[float64]float64{ | 
					
						
							|  |  |  | 				1:    0.1, | 
					
						
							|  |  |  | 				0.99: 0.03468750000281261, | 
					
						
							|  |  |  | 				0.9:  0.00463541666671875, | 
					
						
							|  |  |  | 				0.5:  0.0025752314815104174, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		"real example 2 - non-monotonic": { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 			getInput: func() Buckets { | 
					
						
							|  |  |  | 				return Buckets{ | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.005, | 
					
						
							|  |  |  | 						Count:      9.6, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.01, | 
					
						
							|  |  |  | 						Count:      9.688888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.025, | 
					
						
							|  |  |  | 						Count:      9.755555556, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.05, | 
					
						
							|  |  |  | 						Count:      9.844444444, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.1, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.25, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 0.5, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 1, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 2.5, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 5, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 10, | 
					
						
							|  |  |  | 						Count:      9.888888889001, // Simulate the case there's a small imprecision in float64.
 | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 25, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 50, | 
					
						
							|  |  |  | 						Count:      9.888888888999, // Simulate the case there's a small imprecision in float64.
 | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: 100, | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 						UpperBound: math.Inf(1), | 
					
						
							|  |  |  | 						Count:      9.888888889, | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 					}, | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			expectedForced: false, | 
					
						
							|  |  |  | 			expectedFixed:  true, | 
					
						
							|  |  |  | 			expectedValues: map[float64]float64{ | 
					
						
							|  |  |  | 				1:    0.1, | 
					
						
							|  |  |  | 				0.99: 0.03468750000281261, | 
					
						
							|  |  |  | 				0.9:  0.00463541666671875, | 
					
						
							|  |  |  | 				0.5:  0.0025752314815104174, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} { | 
					
						
							|  |  |  | 		t.Run(name, func(t *testing.T) { | 
					
						
							|  |  |  | 			for q, v := range tc.expectedValues { | 
					
						
							| 
									
										
										
										
											2024-11-27 20:20:23 +08:00
										 |  |  | 				res, forced, fixed := BucketQuantile(q, tc.getInput()) | 
					
						
							| 
									
										
										
										
											2023-11-25 07:05:38 +08:00
										 |  |  | 				require.Equal(t, tc.expectedForced, forced) | 
					
						
							|  |  |  | 				require.Equal(t, tc.expectedFixed, fixed) | 
					
						
							|  |  |  | 				require.InEpsilon(t, v, res, eps) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |