| 1 |
From: Reinhard Tartler <[email protected]> |
| 2 |
Date: Fri, 27 Mar 2026 17:00:10 -0400 |
| 3 |
Subject: fix: update integer test cases to use int64 for boundary conditions |
| 4 |
|
| 5 |
Fixes: #971 |
| 6 |
Signed-off-by: Reinhard Tartler <[email protected]> |
| 7 |
--- |
| 8 |
common/types/int_test.go | 56 ++++++++++++++++++++++++------------------------ |
| 9 |
ext/lists.go | 4 ++-- |
| 10 |
2 files changed, 30 insertions(+), 30 deletions(-) |
| 11 |
|
| 12 |
diff --git a/common/types/int_test.go b/common/types/int_test.go |
| 13 |
index 560c3df..2bf2d73 100644 |
| 14 |
--- a/common/types/int_test.go |
| 15 |
+++ b/common/types/int_test.go |
| 16 |
@@ -39,17 +39,17 @@ func TestIntAdd(t *testing.T) { |
| 17 |
if !IsError(Int(-1).Add(String("-1"))) { |
| 18 |
t.Error("Adding non-int to int was not an error.") |
| 19 |
} |
| 20 |
|
| 21 |
+ if lhs, rhs := int64(math.MaxInt64), int64(1); !IsError(Int(lhs).Add(Int(rhs))) { |
| 22 |
t.Errorf("Expected adding %d and %d to result in overflow.", lhs, rhs) |
| 23 |
} |
| 24 |
|
| 25 |
+ if lhs, rhs := int64(math.MinInt64), int64(-1); !IsError(Int(lhs).Add(Int(rhs))) { |
| 26 |
t.Errorf("Expected adding %d and %d to result in overflow.", lhs, rhs) |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
+ if lhs, rhs := int64(math.MaxInt64-1), int64(1); !Int(lhs).Add(Int(rhs)).Equal(Int(int64(math.MaxInt64))).(Bool) { |
| 31 |
+ t.Errorf("Expected adding %d and %d to yield %d", lhs, rhs, int64(math.MaxInt64)) |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
+ if lhs, rhs := int64(math.MinInt64+1), int64(-1); !Int(lhs).Add(Int(rhs)).Equal(Int(int64(math.MinInt64))).(Bool) { |
| 36 |
+ t.Errorf("Expected adding %d and %d to yield %d", lhs, rhs, int64(math.MinInt64)) |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
@@ -383,7 +383,7 @@ func TestIntDivide(t *testing.T) { |
| 41 |
if !IsError(Int(1).Divide(Double(-1))) { |
| 42 |
t.Error("Division permitted without express type-conversion.") |
| 43 |
} |
| 44 |
|
| 45 |
+ if lhs, rhs := int64(math.MinInt64), int64(-1); !IsError(Int(lhs).Divide(Int(rhs))) { |
| 46 |
t.Errorf("Expected dividing %d and %d result in overflow.", lhs, rhs) |
| 47 |
} |
| 48 |
} |
| 49 |
@@ -462,7 +462,7 @@ func TestIntModulo(t *testing.T) { |
| 50 |
if !IsError(Int(21).Modulo(uintZero)) { |
| 51 |
t.Error("Modulus permitted between different types without type conversion.") |
| 52 |
} |
| 53 |
|
| 54 |
+ if lhs, rhs := int64(math.MinInt64), int64(-1); !IsError(Int(lhs).Modulo(Int(rhs))) { |
| 55 |
t.Errorf("Expected modulo %d and %d result in overflow.", lhs, rhs) |
| 56 |
} |
| 57 |
} |
| 58 |
@@ -474,25 +474,25 @@ func TestIntMultiply(t *testing.T) { |
| 59 |
if !IsError(Int(1).Multiply(Double(-4.0))) { |
| 60 |
t.Error("Multiplication permitted without express type-conversion.") |
| 61 |
} |
| 62 |
|
| 63 |
+ if lhs, rhs := int64(math.MaxInt64/2), int64(3); !IsError(Int(lhs).Multiply(Int(rhs))) { |
| 64 |
t.Errorf("Expected multiplying %d and %d to result in overflow.", lhs, rhs) |
| 65 |
} |
| 66 |
|
| 67 |
+ if lhs, rhs := int64(math.MinInt64/2), int64(3); !IsError(Int(lhs).Multiply(Int(rhs))) { |
| 68 |
t.Errorf("Expected multiplying %d and %d to result in overflow.", lhs, rhs) |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
+ if lhs, rhs := int64(math.MaxInt64/2), int64(2); !Int(lhs).Multiply(Int(rhs)).Equal(Int(int64(math.MaxInt64 - 1))).(Bool) { |
| 73 |
+ t.Errorf("Expected multiplying %d and %d to yield %d", lhs, rhs, int64(math.MaxInt64-1)) |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
+ if lhs, rhs := int64(math.MinInt64/2), int64(2); !Int(lhs).Multiply(Int(rhs)).Equal(Int(int64(math.MinInt64))).(Bool) { |
| 78 |
+ t.Errorf("Expected multiplying %d and %d to yield %d", lhs, rhs, int64(math.MinInt64)) |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
+ if lhs, rhs := int64(math.MaxInt64/2), int64(-2); !Int(lhs).Multiply(Int(rhs)).Equal(Int(int64(math.MinInt64 + 2))).(Bool) { |
| 83 |
+ t.Errorf("Expected multiplying %d and %d to yield %d", lhs, rhs, int64(math.MinInt64+2)) |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
+ if lhs, rhs := int64((math.MinInt64+2)/2), int64(-2); !Int(lhs).Multiply(Int(rhs)).Equal(Int(int64(math.MaxInt64 - 1))).(Bool) { |
| 88 |
+ t.Errorf("Expected multiplying %d and %d to yield %d", lhs, rhs, int64(math.MaxInt64-1)) |
| 89 |
} |
| 90 |
|
| 91 |
+ if lhs, rhs := int64(math.MinInt64), int64(-1); !IsError(Int(lhs).Multiply(Int(rhs))) { |
| 92 |
t.Errorf("Expected multiplying %d and %d result in overflow.", lhs, rhs) |
| 93 |
} |
| 94 |
} |
| 95 |
@@ -501,11 +501,11 @@ func TestIntNegate(t *testing.T) { |
| 96 |
if !Int(1).Negate().Equal(Int(-1)).(Bool) { |
| 97 |
t.Error("Negating int value did not succeed") |
| 98 |
} |
| 99 |
|
| 100 |
+ if v := int64(math.MinInt64); !IsError(Int(v).Negate()) { |
| 101 |
t.Errorf("Expected negating %d to result in overflow.", v) |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
+ if v := int64(math.MaxInt64); !Int(v).Negate().Equal(Int(int64(math.MinInt64 + 1))).(Bool) { |
| 106 |
+ t.Errorf("Expected negating %d to yield %d", v, int64(math.MinInt64+1)) |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
@@ -516,16 +516,16 @@ func TestIntSubtract(t *testing.T) { |
| 111 |
if !IsError(Int(1).Subtract(Uint(1))) { |
| 112 |
t.Error("Subtraction permitted without express type-conversion.") |
| 113 |
} |
| 114 |
|
| 115 |
+ if lhs, rhs := int64(math.MaxInt64), int64(-1); !IsError(Int(lhs).Subtract(Int(rhs))) { |
| 116 |
t.Errorf("Expected subtracting %d and %d to result in overflow.", lhs, rhs) |
| 117 |
} |
| 118 |
|
| 119 |
+ if lhs, rhs := int64(math.MinInt64), int64(1); !IsError(Int(lhs).Subtract(Int(rhs))) { |
| 120 |
t.Errorf("Expected subtracting %d and %d to result in overflow.", lhs, rhs) |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
+ if lhs, rhs := int64(math.MaxInt64-1), int64(-1); !Int(lhs).Subtract(Int(rhs)).Equal(Int(int64(math.MaxInt64))).(Bool) { |
| 125 |
+ t.Errorf("Expected subtracting %d and %d to yield %d", lhs, rhs, int64(math.MaxInt64)) |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
+ if lhs, rhs := int64(math.MinInt64+1), int64(1); !Int(lhs).Subtract(Int(rhs)).Equal(Int(int64(math.MinInt64))).(Bool) { |
| 130 |
+ t.Errorf("Expected subtracting %d and %d to yield %d", lhs, rhs, int64(math.MinInt64)) |
| 131 |
} |
| 132 |
} |
| 133 |
diff --git a/ext/lists.go b/ext/lists.go |
| 134 |
index b27ddf2..3541875 100644 |
| 135 |
--- a/ext/lists.go |
| 136 |
+++ b/ext/lists.go |
| 137 |
@@ -626,7 +626,7 @@ func estimateListsRange(estimator checker.CostEstimator, target *checker.AstNode |
| 138 |
if target != nil || len(args) != 1 { |
| 139 |
return nil |
| 140 |
} |
| 141 |
|
| 142 |
+ return estimateAllocatingListCall(1, checker.FixedSizeEstimate(nodeAsIntValue(args[0], math.MaxUint64))) |
| 143 |
} |
| 144 |
|
| 145 |
// estimateListReverse computes an O(n) reverse operation with a cost factor of 1. |
| 146 |
@@ -644,7 +644,7 @@ func estimateListFlatten(estimator checker.CostEstimator, target *checker.AstNod |
| 147 |
} |
| 148 |
depth := uint64(1) |
| 149 |
if len(args) == 1 { |
| 150 |
|
| 151 |
+ depth = nodeAsIntValue(args[0], math.MaxUint64) |
| 152 |
} |
| 153 |
return estimateAllocatingListCall(float64(depth), estimateSize(estimator, *target)) |
| 154 |
} |