mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-15 07:17:01 +00:00
test(promql): keep Go float format tests with go_format and pin histogram_quantiles constants
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
This commit is contained in:
@@ -898,28 +898,6 @@ fn an_aggregation_of_sparse_inputs_is_compared_in_full_against_the_reference() {
|
||||
assert_eq!(piece_ranges(&counts), vec![(2, 1), (6, 1)]);
|
||||
}
|
||||
|
||||
/// `count_values` writes value labels the way Go's `strconv.FormatFloat(v, 'f', -1, 64)` does,
|
||||
/// including the round-half-even choice of the last shortest digit; see the header of
|
||||
/// `format_float_cases.txt` (promql-compat `cmd/narthex-golden-formatfloat`).
|
||||
#[test]
|
||||
fn value_labels_format_like_go() {
|
||||
let mut checked = 0;
|
||||
for line in include_str!("format_float_cases.txt").lines() {
|
||||
let (bits, expected) = line.split_once(' ').unwrap();
|
||||
let value = f64::from_bits(u64::from_str_radix(bits, 16).unwrap());
|
||||
assert_eq!(crate::go_format::format_float_f(value), expected, "{bits}");
|
||||
checked += 1;
|
||||
}
|
||||
assert!(checked > 2_400, "{checked}");
|
||||
for (value, expected) in [
|
||||
(f64::NAN, "NaN"),
|
||||
(f64::INFINITY, "+Inf"),
|
||||
(f64::NEG_INFINITY, "-Inf"),
|
||||
] {
|
||||
assert_eq!(crate::go_format::format_float_f(value), expected);
|
||||
}
|
||||
}
|
||||
|
||||
/// A point where the `q` scalar has no value has no `quantile` result, as a missing scalar point
|
||||
/// yields no output in the other scalar operators.
|
||||
#[test]
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::go_format::format_open_metrics_float;
|
||||
use crate::go_format::{format_float_f, format_open_metrics_float};
|
||||
|
||||
/// Prometheus `labels.FormatOpenMetricsFloat`; `open_metrics_cases.txt` comes from promql-compat
|
||||
/// `narthex-golden-formatfloat -openmetrics` as `<hex bits> <formatted>`.
|
||||
@@ -27,3 +27,25 @@ fn open_metrics_floats_format_like_prometheus() {
|
||||
}
|
||||
assert!(checked > 300, "{checked}");
|
||||
}
|
||||
|
||||
/// Go's `strconv.FormatFloat(v, 'f', -1, 64)`, the form `count_values` writes value labels in,
|
||||
/// including the round-half-even choice of the last shortest digit and the round-trip check at
|
||||
/// powers of two; `float_cases.txt` comes from promql-compat `narthex-golden-formatfloat`.
|
||||
#[test]
|
||||
fn floats_format_like_go() {
|
||||
let mut checked = 0;
|
||||
for line in include_str!("float_cases.txt").lines() {
|
||||
let (bits, expected) = line.split_once(' ').unwrap();
|
||||
let value = f64::from_bits(u64::from_str_radix(bits, 16).unwrap());
|
||||
assert_eq!(format_float_f(value), expected, "{bits}");
|
||||
checked += 1;
|
||||
}
|
||||
assert!(checked > 2_400, "{checked}");
|
||||
for (value, expected) in [
|
||||
(f64::NAN, "NaN"),
|
||||
(f64::INFINITY, "+Inf"),
|
||||
(f64::NEG_INFINITY, "-Inf"),
|
||||
] {
|
||||
assert_eq!(format_float_f(value), expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,9 @@ pub enum HistogramFunction {
|
||||
/// writes it. Results that then share a label set merge as [`merge_same_labelset`] does, so a
|
||||
/// repeated `q`, or a `label` that overwrites the label telling two histograms apart, fails at a
|
||||
/// point both hold.
|
||||
///
|
||||
/// Each `q` is a constant. Prometheus evaluates the quantile arguments at every step, so a
|
||||
/// quantile that varies over time is not this kernel's to evaluate.
|
||||
pub fn histogram_quantiles(
|
||||
label: &str,
|
||||
quantiles: &[f64],
|
||||
|
||||
@@ -151,7 +151,7 @@ fn histogram_quantiles_match_prometheus() {
|
||||
let actual = histogram_quantiles(&case.spec[1], &quantiles, &schema, &input);
|
||||
failed += usize::from(assert_outcome(case, actual, &case.outcome));
|
||||
}
|
||||
assert!(failed > 5, "{failed} failed");
|
||||
assert_eq!(failed, 13, "{failed} failed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user