Skip to content

Commit 06a55c2

Browse files
committed
add failing tests for addition and subtraction
1 parent 991743d commit 06a55c2

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

tests/tester.nim

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ test "empty limbs when uninitialized (https://github.com/def-/nim-bigints/issues
118118
# logic around sign might also play a role
119119
var
120120
zeroEmpty: BigInt # should be treated as zero, same with -zeroEmpty
121+
result: BigInt
121122
let
122123
zeroInt32: int32 = 0
123124
oneInt32: int32 = 1
125+
bigOne: BigInt = initBigInt(@[0.uint32, 1])
124126

125127
# unsignedCmp(a: BigInt, b: int32) has [0]; used by public cmp and <
126128
# 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
153155
check zeroEmpty == zero # error: fixed
154156
check -zeroEmpty == zero # error: fixed
155157

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

Comments
 (0)