mirror of https://github.com/divan/expvarmon.git
Merge branch 'hhatto-master'
This commit is contained in:
commit
b4e096514e
23
stack.go
23
stack.go
|
@ -33,16 +33,35 @@ func (s *Stack) Push(val VarValue) {
|
|||
s.Values = s.Values[1:]
|
||||
}
|
||||
|
||||
if s.Max == nil {
|
||||
s.Max = val
|
||||
return
|
||||
}
|
||||
|
||||
switch val.(type) {
|
||||
case int64:
|
||||
if s.Max == nil || val.(int64) > s.Max.(int64) {
|
||||
switch s.Max.(type) {
|
||||
case int64:
|
||||
if val.(int64) > s.Max.(int64) {
|
||||
s.Max = val
|
||||
}
|
||||
case float64:
|
||||
if s.Max == nil || val.(float64) > s.Max.(float64) {
|
||||
if float64(val.(int64)) > s.Max.(float64) {
|
||||
s.Max = val
|
||||
}
|
||||
}
|
||||
case float64:
|
||||
switch s.Max.(type) {
|
||||
case int64:
|
||||
if val.(float64) > float64(s.Max.(int64)) {
|
||||
s.Max = val
|
||||
}
|
||||
case float64:
|
||||
if val.(float64) > s.Max.(float64) {
|
||||
s.Max = val
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Front returns front value.
|
||||
|
|
|
@ -2,6 +2,20 @@ package main
|
|||
|
||||
import "testing"
|
||||
|
||||
func TestPushWithFloatAndIntValue(t *testing.T) {
|
||||
s := NewStack()
|
||||
s.Push(VarValue(int64(0.0))) // from service.go:guessValue
|
||||
s.Push(VarValue(5.0))
|
||||
s.Push(VarValue(float64(15.0)))
|
||||
if _, ok := s.Max.(float64); !ok {
|
||||
t.Fatalf("Expected Max to be float64, but it's not")
|
||||
}
|
||||
s.Push(VarValue(int64(25.0)))
|
||||
if _, ok := s.Max.(int64); !ok {
|
||||
t.Fatalf("Expected Max to be int64, but it's not")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStack(t *testing.T) {
|
||||
size := 10
|
||||
s := NewStackWithSize(size)
|
||||
|
|
Loading…
Reference in New Issue