Skip to content

Commit

Permalink
Simplify unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arturogonzalezm committed Jul 29, 2024
1 parent 6b1c1b4 commit d946d07
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/flexint/flexint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flexint
import (
"encoding/json"
"errors"
"fmt"
"math"
"strconv"
)
Expand All @@ -25,6 +26,7 @@ func (i *Int64) UnmarshalJSON(data []byte) error {
// Try to unmarshal as a float64 and then convert
var floatVal float64
if err := json.Unmarshal(data, &floatVal); err == nil {
fmt.Printf("floatVal: %f\n", floatVal) // Debug print
if floatVal > float64(math.MaxInt64) {
*i = Int64(math.MaxInt64)
} else if floatVal < float64(math.MinInt64) {
Expand Down
1 change: 1 addition & 0 deletions pkg/flexint/flexint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestUnmarshalJSON(t *testing.T) {
{"floating point value round half to even 12344.5", "12344.5", 12344, false},
{"max int64", "9223372036854775807", Int64(math.MaxInt64), false},
{"min int64", "-9223372036854775808", Int64(math.MinInt64), false},
{"float64 exceeds max int64", "9223372036854775808.0", Int64(math.MaxInt64), false},
{"float64 below min int64", "-9223372036854775809.0", Int64(math.MinInt64), false},
{"string integer value", `"12345"`, 12345, false},
{"string floating point value", `"12345.67"`, 12346, false},
Expand Down

0 comments on commit d946d07

Please sign in to comment.