MCPcopy
hub / github.com/grafana/tempo / TestStatic_compare

Function TestStatic_compare

pkg/traceql/ast_test.go:565–599  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

563}
564
565func TestStatic_compare(t *testing.T) {
566 testCases := []struct {
567 s1, s2 Static
568 want int
569 }{
570 {s1: NewStaticInt(10), s2: NewStaticInt(5), want: 1},
571 {s1: NewStaticInt(5), s2: NewStaticInt(-10), want: 1},
572 {s1: NewStaticInt(20), s2: NewStaticInt(20), want: 0},
573 {s1: NewStaticFloat(10.5), s2: NewStaticFloat(5.5), want: 1},
574 {s1: NewStaticFloat(100.0), s2: NewStaticInt(100), want: 0},
575 {s1: NewStaticFloat(100.0), s2: NewStaticInt(50), want: 1},
576 {s1: NewStaticString("world"), s2: NewStaticString("hello"), want: 1},
577 {s1: NewStaticBool(true), s2: NewStaticBool(false), want: 1},
578 {s1: NewStaticDuration(10 * time.Second), s2: NewStaticDuration(5 * time.Second), want: 1},
579 {s1: NewStaticDuration(10), s2: NewStaticInt(10), want: 0},
580 {s1: NewStaticIntArray([]int{1, 3, 3}), s2: NewStaticIntArray([]int{1, -2, 3}), want: 1},
581 {s1: NewStaticIntArray([]int{1, 2, 3}), s2: NewStaticIntArray([]int{1, 2, 3}), want: 0},
582 {s1: NewStaticFloatArray([]float64{1.1, math.SmallestNonzeroFloat64}), s2: NewStaticFloatArray([]float64{1.1, 0}), want: 1},
583 {s1: NewStaticFloatArray([]float64{1.1, 2.2, 3.3}), s2: NewStaticFloatArray([]float64{1.1, -2.2, 3.3}), want: 1},
584 {s1: NewStaticFloatArray([]float64{1.1, 2.2, 3.3}), s2: NewStaticFloatArray([]float64{1.1, 2.2, 3.3}), want: 0},
585 {s1: NewStaticStringArray([]string{"a", "b", "c"}), s2: NewStaticStringArray([]string{"a", "b"}), want: 1},
586 {s1: NewStaticStringArray([]string{"a", "b"}), s2: NewStaticStringArray([]string{"a", "b"}), want: 0},
587 {s1: NewStaticBooleanArray([]bool{true, false, true}), s2: NewStaticBooleanArray([]bool{true, false}), want: 1},
588 {s1: NewStaticBooleanArray([]bool{true, false}), s2: NewStaticBooleanArray([]bool{true, false}), want: 0},
589 }
590
591 for _, tt := range testCases {
592 t.Run(fmt.Sprintf("%s<>%s", tt.s1.String(), tt.s2.String()), func(t *testing.T) {
593 res := tt.s1.compare(&tt.s2)
594 require.Equal(t, tt.want, res, "s1.compare(s2)")
595 res = tt.s2.compare(&tt.s1)
596 require.Equal(t, -tt.want, res, "s2.compare(s1)")
597 })
598 }
599}
600
601func TestStatic_sumInto(t *testing.T) {
602 tests := []struct {

Callers

nothing calls this directly

Calls 13

NewStaticIntFunction · 0.85
NewStaticFloatFunction · 0.85
NewStaticStringFunction · 0.85
NewStaticBoolFunction · 0.85
NewStaticDurationFunction · 0.85
NewStaticIntArrayFunction · 0.85
NewStaticFloatArrayFunction · 0.85
NewStaticStringArrayFunction · 0.85
NewStaticBooleanArrayFunction · 0.85
RunMethod · 0.45
StringMethod · 0.45
compareMethod · 0.45

Tested by

no test coverage detected