@@ -118,9 +118,11 @@ test "empty limbs when uninitialized (https://github.com/def-/nim-bigints/issues
118
118
# logic around sign might also play a role
119
119
var
120
120
zeroEmpty: BigInt # should be treated as zero, same with -zeroEmpty
121
+ result : BigInt
121
122
let
122
123
zeroInt32: int32 = 0
123
124
oneInt32: int32 = 1
125
+ bigOne: BigInt = initBigInt (@ [0 .uint32 , 1 ])
124
126
125
127
# unsignedCmp(a: BigInt, b: int32) has [0]; used by public cmp and <
126
128
# never reached in the following cases (no fatal), since it cannot be reached (see comment in code)
@@ -153,4 +155,50 @@ test "empty limbs when uninitialized (https://github.com/def-/nim-bigints/issues
153
155
check zeroEmpty == zero # error: fixed
154
156
check - zeroEmpty == zero # error: fixed
155
157
156
- # let's stop at comparison and fix it before passing to addition and multiplication
158
+ # proc unsignedAdditionInt(a: var BigInt, b: BigInt, c: int32)
159
+ check zeroEmpty + 1 .int32 == one # fatal[IndexError] in bigints.nim(181) unsignedAdditionInt
160
+ check - zeroEmpty + 1 .int32 == one # fatal[IndexError] in bigints.nim(245) unsignedSubtractionInt
161
+ check zeroEmpty + (- 1 ).int32 == - one # fatal[IndexError] in bigints.nim(245) unsignedSubtractionInt
162
+ check - zeroEmpty + (- 1 ).int32 == - one # fatal[IndexError] in bigints.nim(181) unsignedAdditionInt
163
+
164
+ # proc unsignedAddition(a: var BigInt, b, c: BigInt)
165
+ check zeroEmpty + one == one # ok
166
+ check one + zeroEmpty == one # ok
167
+ check - zeroEmpty + one == one # ok
168
+ check one + - zeroEmpty == one # ok
169
+ check zeroEmpty + zeroEmpty == zero # ok
170
+ check - zeroEmpty + zeroEmpty == zero # ok
171
+ check - zeroEmpty + - zeroEmpty == zero # ok
172
+ check zeroEmpty + - zeroEmpty == zero # ok
173
+ check bigOne + zeroEmpty == bigOne # ok
174
+ check bigOne + - zeroEmpty == bigOne # ok
175
+ check zeroEmpty + bigOne == bigOne # ok
176
+ check - zeroEmpty + bigOne == bigOne # ok
177
+ check - bigOne + zeroEmpty == - bigOne # ok
178
+ check - bigOne + - zeroEmpty == - bigOne # ok
179
+ check zeroEmpty + - bigOne == - bigOne # ok
180
+ check - zeroEmpty + - bigOne == - bigOne # ok
181
+
182
+ # proc unsignedSubtractionInt(a: var BigInt, b: BigInt, c: int32)
183
+ check zeroEmpty - 1 .int32 == - one # fatal[IndexError] in bigints.nim(245) unsignedSubtractionInt
184
+ check - zeroEmpty - 1 .int32 == - one # fatal[IndexError] in bigints.nim(181) unsignedAdditionInt
185
+ check zeroEmpty - (- 1 ).int32 == one # fatal[IndexError] in bigints.nim(181) unsignedAdditionInt
186
+ check - zeroEmpty - (- 1 ).int32 == one # fatal[IndexError] in bigints.nim(245) unsignedSubtractionInt
187
+
188
+ # proc unsignedSubtraction(a: var BigInt, b, c: BigInt)
189
+ check zeroEmpty - one == - one # ok
190
+ check one - zeroEmpty == one # ok
191
+ check - zeroEmpty - one == - one # ok
192
+ check one - - zeroEmpty == one # ok
193
+ check zeroEmpty - zeroEmpty == zero # ok
194
+ check - zeroEmpty - zeroEmpty == zero # ok
195
+ check - zeroEmpty - - zeroEmpty == zero # ok
196
+ check zeroEmpty - - zeroEmpty == zero # ok
197
+ check bigOne - zeroEmpty == bigOne # ok
198
+ check bigOne - - zeroEmpty == bigOne # ok
199
+ check zeroEmpty - bigOne == - bigOne # ok
200
+ check - zeroEmpty - bigOne == - bigOne # ok
201
+ check - bigOne - zeroEmpty == - bigOne # ok
202
+ check - bigOne - - zeroEmpty == - bigOne # ok
203
+ check zeroEmpty - - bigOne == bigOne # ok
204
+ check - zeroEmpty - - bigOne == bigOne # ok
0 commit comments