From: Reinhard Tartler Date: Fri, 27 Mar 2026 17:00:10 -0400 Subject: fix: update integer test cases to use int64 for boundary conditions Fixes: #971 Signed-off-by: Reinhard Tartler --- common/types/int_test.go | 56 ++++++++++++++++++++++++------------------------ ext/lists.go | 4 ++-- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/common/types/int_test.go b/common/types/int_test.go index 560c3df..2bf2d73 100644 --- a/common/types/int_test.go +++ b/common/types/int_test.go @@ -39,17 +39,17 @@ func TestIntAdd(t *testing.T) { if !IsError(Int(-1).Add(String("-1"))) { t.Error("Adding non-int to int was not an error.") } - if lhs, rhs := math.MaxInt64, 1; !IsError(Int(lhs).Add(Int(rhs))) { + if lhs, rhs := int64(math.MaxInt64), int64(1); !IsError(Int(lhs).Add(Int(rhs))) { t.Errorf("Expected adding %d and %d to result in overflow.", lhs, rhs) } - if lhs, rhs := math.MinInt64, -1; !IsError(Int(lhs).Add(Int(rhs))) { + if lhs, rhs := int64(math.MinInt64), int64(-1); !IsError(Int(lhs).Add(Int(rhs))) { t.Errorf("Expected adding %d and %d to result in overflow.", lhs, rhs) } - if lhs, rhs := math.MaxInt64-1, 1; !Int(lhs).Add(Int(rhs)).Equal(Int(math.MaxInt64)).(Bool) { - t.Errorf("Expected adding %d and %d to yield %d", lhs, rhs, math.MaxInt64) + if lhs, rhs := int64(math.MaxInt64-1), int64(1); !Int(lhs).Add(Int(rhs)).Equal(Int(int64(math.MaxInt64))).(Bool) { + t.Errorf("Expected adding %d and %d to yield %d", lhs, rhs, int64(math.MaxInt64)) } - if lhs, rhs := math.MinInt64+1, -1; !Int(lhs).Add(Int(rhs)).Equal(Int(math.MinInt64)).(Bool) { - t.Errorf("Expected adding %d and %d to yield %d", lhs, rhs, math.MaxInt64) + if lhs, rhs := int64(math.MinInt64+1), int64(-1); !Int(lhs).Add(Int(rhs)).Equal(Int(int64(math.MinInt64))).(Bool) { + t.Errorf("Expected adding %d and %d to yield %d", lhs, rhs, int64(math.MinInt64)) } } @@ -383,7 +383,7 @@ func TestIntDivide(t *testing.T) { if !IsError(Int(1).Divide(Double(-1))) { t.Error("Division permitted without express type-conversion.") } - if lhs, rhs := math.MinInt64, -1; !IsError(Int(lhs).Divide(Int(rhs))) { + if lhs, rhs := int64(math.MinInt64), int64(-1); !IsError(Int(lhs).Divide(Int(rhs))) { t.Errorf("Expected dividing %d and %d result in overflow.", lhs, rhs) } } @@ -462,7 +462,7 @@ func TestIntModulo(t *testing.T) { if !IsError(Int(21).Modulo(uintZero)) { t.Error("Modulus permitted between different types without type conversion.") } - if lhs, rhs := math.MinInt64, -1; !IsError(Int(lhs).Modulo(Int(rhs))) { + if lhs, rhs := int64(math.MinInt64), int64(-1); !IsError(Int(lhs).Modulo(Int(rhs))) { t.Errorf("Expected modulo %d and %d result in overflow.", lhs, rhs) } } @@ -474,25 +474,25 @@ func TestIntMultiply(t *testing.T) { if !IsError(Int(1).Multiply(Double(-4.0))) { t.Error("Multiplication permitted without express type-conversion.") } - if lhs, rhs := math.MaxInt64/2, 3; !IsError(Int(lhs).Multiply(Int(rhs))) { + if lhs, rhs := int64(math.MaxInt64/2), int64(3); !IsError(Int(lhs).Multiply(Int(rhs))) { t.Errorf("Expected multiplying %d and %d to result in overflow.", lhs, rhs) } - if lhs, rhs := math.MinInt64/2, 3; !IsError(Int(lhs).Multiply(Int(rhs))) { + if lhs, rhs := int64(math.MinInt64/2), int64(3); !IsError(Int(lhs).Multiply(Int(rhs))) { t.Errorf("Expected multiplying %d and %d to result in overflow.", lhs, rhs) } - if lhs, rhs := math.MaxInt64/2, 2; !Int(lhs).Multiply(Int(rhs)).Equal(Int(math.MaxInt64 - 1)).(Bool) { - t.Errorf("Expected multiplying %d and %d to yield %d", lhs, rhs, math.MaxInt64-1) + if lhs, rhs := int64(math.MaxInt64/2), int64(2); !Int(lhs).Multiply(Int(rhs)).Equal(Int(int64(math.MaxInt64 - 1))).(Bool) { + t.Errorf("Expected multiplying %d and %d to yield %d", lhs, rhs, int64(math.MaxInt64-1)) } - if lhs, rhs := math.MinInt64/2, 2; !Int(lhs).Multiply(Int(rhs)).Equal(Int(math.MinInt64)).(Bool) { - t.Errorf("Expected multiplying %d and %d to yield %d", lhs, rhs, math.MinInt64) + if lhs, rhs := int64(math.MinInt64/2), int64(2); !Int(lhs).Multiply(Int(rhs)).Equal(Int(int64(math.MinInt64))).(Bool) { + t.Errorf("Expected multiplying %d and %d to yield %d", lhs, rhs, int64(math.MinInt64)) } - if lhs, rhs := math.MaxInt64/2, -2; !Int(lhs).Multiply(Int(rhs)).Equal(Int(math.MinInt64 + 2)).(Bool) { - t.Errorf("Expected multiplying %d and %d to yield %d", lhs, rhs, math.MinInt64+2) + if lhs, rhs := int64(math.MaxInt64/2), int64(-2); !Int(lhs).Multiply(Int(rhs)).Equal(Int(int64(math.MinInt64 + 2))).(Bool) { + t.Errorf("Expected multiplying %d and %d to yield %d", lhs, rhs, int64(math.MinInt64+2)) } - if lhs, rhs := (math.MinInt64+2)/2, -2; !Int(lhs).Multiply(Int(rhs)).Equal(Int(math.MaxInt64 - 1)).(Bool) { - t.Errorf("Expected multiplying %d and %d to yield %d", lhs, rhs, math.MaxInt64-1) + if lhs, rhs := int64((math.MinInt64+2)/2), int64(-2); !Int(lhs).Multiply(Int(rhs)).Equal(Int(int64(math.MaxInt64 - 1))).(Bool) { + t.Errorf("Expected multiplying %d and %d to yield %d", lhs, rhs, int64(math.MaxInt64-1)) } - if lhs, rhs := math.MinInt64, -1; !IsError(Int(lhs).Multiply(Int(rhs))) { + if lhs, rhs := int64(math.MinInt64), int64(-1); !IsError(Int(lhs).Multiply(Int(rhs))) { t.Errorf("Expected multiplying %d and %d result in overflow.", lhs, rhs) } } @@ -501,11 +501,11 @@ func TestIntNegate(t *testing.T) { if !Int(1).Negate().Equal(Int(-1)).(Bool) { t.Error("Negating int value did not succeed") } - if v := math.MinInt64; !IsError(Int(v).Negate()) { + if v := int64(math.MinInt64); !IsError(Int(v).Negate()) { t.Errorf("Expected negating %d to result in overflow.", v) } - if v := math.MaxInt64; !Int(v).Negate().Equal(Int(math.MinInt64 + 1)).(Bool) { - t.Errorf("Expected negating %d to yield %d", v, math.MinInt64+1) + if v := int64(math.MaxInt64); !Int(v).Negate().Equal(Int(int64(math.MinInt64 + 1))).(Bool) { + t.Errorf("Expected negating %d to yield %d", v, int64(math.MinInt64+1)) } } @@ -516,16 +516,16 @@ func TestIntSubtract(t *testing.T) { if !IsError(Int(1).Subtract(Uint(1))) { t.Error("Subtraction permitted without express type-conversion.") } - if lhs, rhs := math.MaxInt64, -1; !IsError(Int(lhs).Subtract(Int(rhs))) { + if lhs, rhs := int64(math.MaxInt64), int64(-1); !IsError(Int(lhs).Subtract(Int(rhs))) { t.Errorf("Expected subtracting %d and %d to result in overflow.", lhs, rhs) } - if lhs, rhs := math.MinInt64, 1; !IsError(Int(lhs).Subtract(Int(rhs))) { + if lhs, rhs := int64(math.MinInt64), int64(1); !IsError(Int(lhs).Subtract(Int(rhs))) { t.Errorf("Expected subtracting %d and %d to result in overflow.", lhs, rhs) } - if lhs, rhs := math.MaxInt64-1, -1; !Int(lhs).Subtract(Int(rhs)).Equal(Int(math.MaxInt64)).(Bool) { - t.Errorf("Expected subtracting %d and %d to yield %d", lhs, rhs, math.MaxInt64) + if lhs, rhs := int64(math.MaxInt64-1), int64(-1); !Int(lhs).Subtract(Int(rhs)).Equal(Int(int64(math.MaxInt64))).(Bool) { + t.Errorf("Expected subtracting %d and %d to yield %d", lhs, rhs, int64(math.MaxInt64)) } - if lhs, rhs := math.MinInt64+1, 1; !Int(lhs).Subtract(Int(rhs)).Equal(Int(math.MinInt64)).(Bool) { - t.Errorf("Expected subtracting %d and %d to yield %d", lhs, rhs, math.MinInt64) + if lhs, rhs := int64(math.MinInt64+1), int64(1); !Int(lhs).Subtract(Int(rhs)).Equal(Int(int64(math.MinInt64))).(Bool) { + t.Errorf("Expected subtracting %d and %d to yield %d", lhs, rhs, int64(math.MinInt64)) } } diff --git a/ext/lists.go b/ext/lists.go index b27ddf2..3541875 100644 --- a/ext/lists.go +++ b/ext/lists.go @@ -626,7 +626,7 @@ func estimateListsRange(estimator checker.CostEstimator, target *checker.AstNode if target != nil || len(args) != 1 { return nil } - return estimateAllocatingListCall(1, checker.FixedSizeEstimate(nodeAsIntValue(args[0], math.MaxUint))) + return estimateAllocatingListCall(1, checker.FixedSizeEstimate(nodeAsIntValue(args[0], math.MaxUint64))) } // estimateListReverse computes an O(n) reverse operation with a cost factor of 1. @@ -644,7 +644,7 @@ func estimateListFlatten(estimator checker.CostEstimator, target *checker.AstNod } depth := uint64(1) if len(args) == 1 { - depth = nodeAsIntValue(args[0], math.MaxUint) + depth = nodeAsIntValue(args[0], math.MaxUint64) } return estimateAllocatingListCall(float64(depth), estimateSize(estimator, *target)) }