add test for mixed numerics and fix infer
parent
193fd501db
commit
dd278a10f6
|
@ -1330,8 +1330,8 @@ func (t topOuts) Less(i, j int) bool {
|
|||
w2, n2 := infer(t.values[j].Value)
|
||||
|
||||
// If we had "numeric" data, use that for comparison
|
||||
if n1 != n2 && (w1 == intWeight && w2 == floatWeight) || (w1 == floatWeight && w2 == intWeight) {
|
||||
return n1 < n2
|
||||
if (w1 == floatWeight || w1 == intWeight) && (w2 == floatWeight || w2 == intWeight) {
|
||||
return sortFloat(n1, n2)
|
||||
}
|
||||
|
||||
return w1 < w2
|
||||
|
|
|
@ -627,6 +627,40 @@ func TestMapTop(t *testing.T) {
|
|||
},
|
||||
call: &Call{Name: "top", Args: []Expr{&VarRef{Val: "field1"}, &VarRef{Val: "host"}, &NumberLiteral{Val: 2}}},
|
||||
},
|
||||
{
|
||||
name: "mixed numerics - ints",
|
||||
iter: &testIterator{
|
||||
values: []point{
|
||||
{"", 10, int64(99), map[string]string{"host": "a"}},
|
||||
{"", 10, int64(53), map[string]string{"host": "b"}},
|
||||
{"", 20, uint64(88), map[string]string{"host": "a"}},
|
||||
},
|
||||
},
|
||||
exp: topOuts{
|
||||
values: []topOut{
|
||||
topOut{10, int64(99), map[string]string{"host": "a"}},
|
||||
topOut{20, uint64(88), map[string]string{"host": "a"}},
|
||||
},
|
||||
},
|
||||
call: &Call{Name: "top", Args: []Expr{&VarRef{Val: "field1"}, &NumberLiteral{Val: 2}}},
|
||||
},
|
||||
{
|
||||
name: "mixed numerics - ints & floats",
|
||||
iter: &testIterator{
|
||||
values: []point{
|
||||
{"", 10, float64(99), map[string]string{"host": "a"}},
|
||||
{"", 10, int64(53), map[string]string{"host": "b"}},
|
||||
{"", 20, uint64(88), map[string]string{"host": "a"}},
|
||||
},
|
||||
},
|
||||
exp: topOuts{
|
||||
values: []topOut{
|
||||
topOut{10, float64(99), map[string]string{"host": "a"}},
|
||||
topOut{20, uint64(88), map[string]string{"host": "a"}},
|
||||
},
|
||||
},
|
||||
call: &Call{Name: "top", Args: []Expr{&VarRef{Val: "field1"}, &NumberLiteral{Val: 2}}},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
Loading…
Reference in New Issue