mirror of
https://github.com/divan/expvarmon.git
synced 2025-04-25 13:48:54 +08:00
Small improvements to PR
This commit is contained in:
parent
b33870f09c
commit
34398877f7
9
stack.go
9
stack.go
@ -33,13 +33,13 @@ func (s *Stack) Push(val VarValue) {
|
|||||||
s.Values = s.Values[1:]
|
s.Values = s.Values[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
switch val.(type) {
|
|
||||||
case int64:
|
|
||||||
if s.Max == nil {
|
if s.Max == nil {
|
||||||
s.Max = val
|
s.Max = val
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch val.(type) {
|
||||||
|
case int64:
|
||||||
switch s.Max.(type) {
|
switch s.Max.(type) {
|
||||||
case int64:
|
case int64:
|
||||||
if val.(int64) > s.Max.(int64) {
|
if val.(int64) > s.Max.(int64) {
|
||||||
@ -51,11 +51,6 @@ func (s *Stack) Push(val VarValue) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case float64:
|
case float64:
|
||||||
if s.Max == nil {
|
|
||||||
s.Max = val
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch s.Max.(type) {
|
switch s.Max.(type) {
|
||||||
case int64:
|
case int64:
|
||||||
if val.(float64) > float64(s.Max.(int64)) {
|
if val.(float64) > float64(s.Max.(int64)) {
|
||||||
|
@ -7,6 +7,13 @@ func TestPushWithFloatAndIntValue(t *testing.T) {
|
|||||||
s.Push(VarValue(int64(0.0))) // from service.go:guessValue
|
s.Push(VarValue(int64(0.0))) // from service.go:guessValue
|
||||||
s.Push(VarValue(5.0))
|
s.Push(VarValue(5.0))
|
||||||
s.Push(VarValue(float64(15.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) {
|
func TestStack(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user