util: remove unused NotZero funcs

This commit is contained in:
c9s 2022-12-26 01:51:32 +08:00
parent ecf5ed3c85
commit c07c3c62a9
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 0 additions and 67 deletions

View File

@ -1,7 +1,6 @@
package util package util
import ( import (
"math"
"strconv" "strconv"
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
@ -27,34 +26,3 @@ func FormatValue(val fixedpoint.Value, prec int) string {
func FormatFloat(val float64, prec int) string { func FormatFloat(val float64, prec int) string {
return strconv.FormatFloat(val, 'f', prec, 64) return strconv.FormatFloat(val, 'f', prec, 64)
} }
func ParseFloat(s string) (float64, error) {
if len(s) == 0 {
return 0.0, nil
}
return strconv.ParseFloat(s, 64)
}
func MustParseFloat(s string) float64 {
if len(s) == 0 {
return 0.0
}
v, err := strconv.ParseFloat(s, 64)
if err != nil {
panic(err)
}
return v
}
const epsilon = 0.0000001
func Zero(v float64) bool {
return math.Abs(v) < epsilon
}
func NotZero(v float64) bool {
return math.Abs(v) > epsilon
}

View File

@ -1,36 +1 @@
package util package util
import "testing"
func TestNotZero(t *testing.T) {
type args struct {
v float64
}
tests := []struct {
name string
args args
want bool
}{
{
name: "0",
args: args{
v: 0,
},
want: false,
},
{
name: "0.00001",
args: args{
v: 0.00001,
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NotZero(tt.args.v); got != tt.want {
t.Errorf("NotZero() = %v, want %v", got, tt.want)
}
})
}
}