Skip to content

Commit

Permalink
fix test issues with float imprecisions
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoVeille committed Nov 14, 2024
1 parent 4960133 commit d12e3eb
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func TestToInt32(t *testing.T) {
})

assertInt32Error(t, []caseInt32[float32]{
{name: "positive out of range", input: math.MaxInt32 + 1},
{name: "positive out of range", input: math.MaxInt32 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
})
})

Expand All @@ -654,7 +654,7 @@ func TestToInt32(t *testing.T) {
})

assertInt32Error(t, []caseInt32[float64]{
{name: "positive out of range", input: math.MaxInt32 + 1},
{name: "positive out of range", input: math.MaxInt32 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
})
})
}
Expand Down Expand Up @@ -768,7 +768,7 @@ func TestToUint32(t *testing.T) {
})

assertUint32Error(t, []caseUint32[float32]{
{name: "positive out of range", input: math.MaxUint32 + 1},
{name: "positive out of range", input: math.MaxUint32 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
})
})

Expand All @@ -780,7 +780,7 @@ func TestToUint32(t *testing.T) {
})

assertUint32Error(t, []caseUint32[float64]{
{name: "positive out of range", input: math.MaxUint32 + 1},
{name: "positive out of range", input: math.MaxUint32 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
{name: "negative value", input: -1},
})
})
Expand Down Expand Up @@ -881,7 +881,7 @@ func TestToInt64(t *testing.T) {
})

assertInt64Error(t, []caseInt64[float32]{
{name: "out of range math.MaxInt64 + 1", input: math.MaxInt64 + 1},
{name: "out of range math.MaxInt64", input: math.MaxInt64 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
{name: "out of range math.MaxUint64", input: math.MaxUint64},
{name: "out of range math.MinInt64", input: math.MinInt64 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
{name: "out of range math.MaxFloat32", input: math.MaxFloat32},
Expand All @@ -901,7 +901,7 @@ func TestToInt64(t *testing.T) {
})

assertInt64Error(t, []caseInt64[float64]{
{name: "out of range math.MaxInt64 + 1", input: math.MaxInt64 + 1},
{name: "out of range math.MaxInt64 + 1", input: math.MaxInt64 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
{name: "out of range math.MaxUint64", input: math.MaxUint64},
{name: "out of range math.MinInt64", input: math.MinInt64 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
{name: "out of range math.MaxFloat32", input: math.MaxFloat32},
Expand Down Expand Up @@ -1012,7 +1012,7 @@ func TestToUint64(t *testing.T) {

assertUint64Error(t, []caseUint64[float32]{
{name: "negative value", input: -1},
{name: "out of range max uint64", input: math.MaxUint64},
{name: "out of range max uint64", input: math.MaxUint64 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
})
})

Expand All @@ -1025,7 +1025,7 @@ func TestToUint64(t *testing.T) {

assertUint64Error(t, []caseUint64[float64]{
{name: "negative value", input: -1},
{name: "out of range max uint64", input: math.MaxUint64},
{name: "out of range max uint64", input: math.MaxUint64 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
{name: "out of range max float32", input: math.MaxFloat32},
{name: "out of range max float64", input: math.MaxFloat64},
})
Expand Down Expand Up @@ -1123,7 +1123,7 @@ func TestToInt(t *testing.T) {
})

assertIntError(t, []caseInt[float32]{
{name: "out of range math.MaxInt64 + 1", input: math.MaxInt64 + 1},
{name: "out of range math.MaxInt64 + 1", input: math.MaxInt64 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
{name: "out of range math.MaxUint64", input: math.MaxUint64},
{name: "out of range math.MinInt64", input: math.MinInt64 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
{name: "out of range math.MaxFloat32", input: math.MaxFloat32},
Expand All @@ -1141,7 +1141,7 @@ func TestToInt(t *testing.T) {
})

assertIntError(t, []caseInt[float64]{
{name: "out of range math.MaxInt64 + 1", input: math.MaxInt64 + 1},
{name: "out of range math.MaxInt64 + 1", input: math.MaxInt64 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
{name: "out of range math.MaxUint64", input: math.MaxUint64},
{name: "out of range math.MinInt64", input: math.MinInt64 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
{name: "out of range math.MaxFloat32", input: math.MaxFloat32},
Expand Down Expand Up @@ -1252,7 +1252,7 @@ func TestToUint(t *testing.T) {

assertUint64Error(t, []caseUint64[float32]{
{name: "negative value", input: -1},
{name: "out of range max uint64", input: math.MaxUint64},
{name: "out of range max uint64", input: math.MaxUint64 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
{name: "out of range max float32", input: math.MaxFloat32},
})
})
Expand All @@ -1266,7 +1266,7 @@ func TestToUint(t *testing.T) {

assertUintError(t, []caseUint[float64]{
{name: "negative value", input: -1},
{name: "out of range max uint64", input: math.MaxUint64},
{name: "out of range max uint64", input: math.MaxUint64 * 1.02}, // because of float imprecision, we have to exceed the min int64 to trigger the error
{name: "out of range max float32", input: math.MaxFloat32},
{name: "out of range max float64", input: math.MaxFloat64},
})
Expand Down

0 comments on commit d12e3eb

Please sign in to comment.