add test for mixed numerics and fix infer

pull/3930/head
Cory LaNou 2015-08-28 16:27:34 -05:00
parent 193fd501db
commit dd278a10f6
2 changed files with 36 additions and 2 deletions

View File

@ -1330,8 +1330,8 @@ func (t topOuts) Less(i, j int) bool {
w2, n2 := infer(t.values[j].Value) w2, n2 := infer(t.values[j].Value)
// If we had "numeric" data, use that for comparison // If we had "numeric" data, use that for comparison
if n1 != n2 && (w1 == intWeight && w2 == floatWeight) || (w1 == floatWeight && w2 == intWeight) { if (w1 == floatWeight || w1 == intWeight) && (w2 == floatWeight || w2 == intWeight) {
return n1 < n2 return sortFloat(n1, n2)
} }
return w1 < w2 return w1 < w2

View File

@ -627,6 +627,40 @@ func TestMapTop(t *testing.T) {
}, },
call: &Call{Name: "top", Args: []Expr{&VarRef{Val: "field1"}, &VarRef{Val: "host"}, &NumberLiteral{Val: 2}}}, 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 { for _, test := range tests {