cleanup tests

This commit is contained in:
jangko 2023-06-14 09:41:01 +07:00
parent 7b7db2a73a
commit 79ad349fb5
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
8 changed files with 152 additions and 285 deletions

View File

@ -9,7 +9,7 @@
import private/datatypes import private/datatypes
{.push raises: [IndexDefect], noinit, gcsafe.} {.push raises: [], noinit, gcsafe.}
# Serialization # Serialization
# ------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------

View File

@ -12,6 +12,7 @@ import
./private/uint_bitwise, ./private/uint_bitwise,
./private/uint_shift, ./private/uint_shift,
./private/uint_addsub, ./private/uint_addsub,
./private/uint_div,
./uintops ./uintops
export StInt export StInt
@ -34,6 +35,9 @@ func sign*(a: StInt): int =
func isNegative*(a: StInt): bool = func isNegative*(a: StInt): bool =
a.limbs[^1] >= signMask a.limbs[^1] >= signMask
func isPositive*(a: StInt): bool =
a.limbs[^1] < signMask
func clearMSB(a: var StInt) = func clearMSB(a: var StInt) =
a.limbs[^1] = a.limbs[^1] and clearSignMask a.limbs[^1] = a.limbs[^1] and clearSignMask
@ -260,3 +264,98 @@ func pow*[aBits, eBits](a: StInt[aBits], e: StInt[eBits]): StInt[aBits] =
result.negate result.negate
else: else:
result.imp = a.imp.pow(e.imp) result.imp = a.imp.pow(e.imp)
{.pop.}
# Division & Modulo
# --------------------------------------------------------
{.push raises: [], inline, noinit, gcsafe.}
func `div`*(n, d: StInt): StInt =
## Division operation for multi-precision unsigned uint
var tmp{.noinit.}: StInt
if n.isPositive:
if d.isPositive:
# pos / pos
result.imp = n.imp div d.imp
return
else:
# pos / neg
tmp = d.neg
result.imp = n.imp div tmp.imp
result.negate
return
let nneg = n.neg
if d.isNegative:
# neg / neg
tmp = d.neg
result.imp = nneg.imp div tmp.imp
return
# neg / pos
result.imp = nneg.imp div d.imp
result.negate
func `mod`*(x, y: StInt): StInt =
## Remainder operation for multi-precision unsigned uint
let
xIn = x.abs
yIn = y.abs
result.imp = xIn.imp mod yIn.imp
if x.isNegative:
result.negate
func divmodI(x, y: StInt): tuple[quot, rem: StInt] =
## Division and remainder operations for multi-precision uint
## with StInt operands
divRem(result.quot.limbs, result.rem.limbs, x.limbs, y.limbs)
func divmod*(n, d: StInt): tuple[quot, rem: StInt] =
## Division and remainder operations for multi-precision unsigned uint
var tmp{.noinit.}: StInt
if n.isPositive:
if d.isPositive:
# pos / pos
return divmodI(n, d)
else:
# pos / neg
tmp = d.neg
result = divmodI(n, tmp)
result.quot.negate
return
let nneg = n.neg
if d.isNegative:
# neg / neg
tmp = d.neg
result = divmodI(nneg, tmp)
result.rem.negate
return
# neg / pos
result = divmodI(nneg, d)
result.quot.negate
result.rem.negate
{.pop.}
# Multiplication
# --------------------------------------------------------
{.push raises: [], inline, noinit, gcsafe.}
func `*`*(a, b: StInt): StInt =
## Integer multiplication
let
av = a.abs
bv = b.abs
result.imp = av.imp * bv.imp
if a.isNegative xor b.isNegative:
result.negate
{.pop.}

View File

@ -7,6 +7,8 @@
# #
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
{. warning[UnusedImport]:off .}
import import
test_uint_addsub, test_uint_addsub,
test_uint_bitops2, test_uint_bitops2,
@ -26,7 +28,8 @@ import
test_int_bitwise, test_int_bitwise,
test_int_addsub, test_int_addsub,
test_int_endianness, test_int_endianness,
test_int_muldiv test_int_muldiv,
test_int_exp
#[ #[
import test_io, import test_io,

1
tests/config.nims Normal file
View File

@ -0,0 +1 @@
switch("warning", "BareExcept:off")

View File

@ -134,15 +134,10 @@ suite "Wider signed int bitwise coverage":
when defined(cpp): when defined(cpp):
import quicktest, ttmath_compat import quicktest, ttmath_compat
func high(T: typedesc[SomeUnsignedInt]): T = func high(T: typedesc[SomeUnsignedInt]): T =
not T(0) not T(0)
suite "Testing signed int bitwise operations": suite "Testing signed int bitwise operations":
const
hi = high(int64)
lo = low(int64)
itercount = 1000
test "Shift Left": test "Shift Left":
var y = 1.u256 var y = 1.u256
for i in 1..255: for i in 1..255:
@ -186,6 +181,11 @@ suite "Testing signed int bitwise operations":
check c == a check c == a
when defined(cpp): when defined(cpp):
const
hi = high(int64)
lo = low(int64)
itercount = 1000
quicktest "signed int `shl` vs ttmath", itercount do(x0: int64(min=lo, max=hi), quicktest "signed int `shl` vs ttmath", itercount do(x0: int64(min=lo, max=hi),
x1: int64(min=0, max=hi), x1: int64(min=0, max=hi),
x2: int64(min=0, max=hi), x2: int64(min=0, max=hi),

View File

@ -9,8 +9,6 @@
import ../stint, unittest, test_helpers import ../stint, unittest, test_helpers
import stew/byteutils
template testInitialization(chk, tst: untyped) = template testInitialization(chk, tst: untyped) =
tst "zero one": tst "zero one":
var a: StInt[128] var a: StInt[128]
@ -52,8 +50,8 @@ template testInitialization(chk, tst: untyped) =
zz.setBit(z.bits - 1) zz.setBit(z.bits - 1)
chk xx.imp == zz chk xx.imp == zz
#static: static:
# testInitialization(ctCheck, ctTest) testInitialization(ctCheck, ctTest)
suite "Signed integer initialization": suite "Signed integer initialization":
testInitialization(check, test) testInitialization(check, test)

View File

@ -1,5 +1,5 @@
# Stint # Stint
# Copyright 2018 Status Research & Development GmbH # Copyright 2018-2023 Status Research & Development GmbH
# Licensed under either of # Licensed under either of
# #
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
@ -26,32 +26,6 @@ template chkDivMod(chk: untyped, a, b, c, d: string, bits: int) =
template testMuldiv(chk, tst: untyped) = template testMuldiv(chk, tst: untyped) =
tst "operator `mul`": tst "operator `mul`":
chkMul(chk, "0", "3", "0", 8)
chkMul(chk, "1", "3", "3", 8)
chkMul(chk, "F0", "3", "D0", 8)
chkMul(chk, "FF", "FF", "1", 8)
chkMul(chk, "0", "3", "0", 16)
chkMul(chk, "1", "3", "3", 16)
chkMul(chk, "F0", "3", "2D0", 16)
chkMul(chk, "F000", "3", "D000", 16)
chkMul(chk, "FFFF", "FFFF", "1", 16)
chkMul(chk, "0", "3", "0", 32)
chkMul(chk, "1", "3", "3", 32)
chkMul(chk, "F0", "3", "2D0", 32)
chkMul(chk, "F000", "3", "2D000", 32)
chkMul(chk, "F0000000", "3", "D0000000", 32)
chkMul(chk, "FFFFFFFF", "FFFFFFFF", "1", 32)
chkMul(chk, "0", "3", "0", 64)
chkMul(chk, "1", "3", "3", 64)
chkMul(chk, "F0", "3", "2D0", 64)
chkMul(chk, "F000", "3", "2D000", 64)
chkMul(chk, "F0000000", "3", "2D0000000", 64)
chkMul(chk, "F000000000000000", "3", "D000000000000000", 64)
chkMul(chk, "FFFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFFF", "1", 64)
chkMul(chk, "0", "3", "0", 128) chkMul(chk, "0", "3", "0", 128)
chkMul(chk, "1", "3", "3", 128) chkMul(chk, "1", "3", "3", 128)
chkMul(chk, "F0", "3", "2D0", 128) chkMul(chk, "F0", "3", "2D0", 128)
@ -62,37 +36,6 @@ template testMuldiv(chk, tst: untyped) =
chkMul(chk, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "1", 128) chkMul(chk, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "1", 128)
tst "operator `div`": tst "operator `div`":
chkDiv(chk, "0", "3", "0", 8)
chkDiv(chk, "1", "3", "0", 8)
chkDiv(chk, "3", "3", "1", 8)
chkDiv(chk, "3", "1", "3", 8)
chkDiv(chk, "FF", "3", "0", 8)
chkDiv(chk, "0F", "FF", "F1", 8)
chkDiv(chk, "FF", "FF", "1", 8)
chkDiv(chk, "0", "3", "0", 16)
chkDiv(chk, "1", "3", "0", 16)
chkDiv(chk, "3", "3", "1", 16)
chkDiv(chk, "3", "1", "3", 16)
chkDiv(chk, "FF", "3", "55", 16)
chkDiv(chk, "0F", "FF", "0", 16)
chkDiv(chk, "FF", "FF", "1", 16)
chkDiv(chk, "FFFF", "3", "0", 16)
chkDiv(chk, "0F", "FFFF", "FFF1", 16)
chkDiv(chk, "FFFF", "FFFF", "1", 16)
chkDiv(chk, "0", "3", "0", 32)
chkDiv(chk, "1", "3", "0", 32)
chkDiv(chk, "3", "3", "1", 32)
chkDiv(chk, "3", "1", "3", 32)
chkDiv(chk, "FF", "3", "55", 32)
chkDiv(chk, "0F", "FF", "0", 32)
chkDiv(chk, "FF", "FF", "1", 32)
chkDiv(chk, "FFFF", "3", "5555", 32)
chkDiv(chk, "0F", "FFFFFFFF", "FFFFFFF1", 32)
chkDiv(chk, "FFFFFFFF", "FFFFFFFF", "1", 32)
chkDiv(chk, "0", "3", "0", 64) chkDiv(chk, "0", "3", "0", 64)
chkDiv(chk, "1", "3", "0", 64) chkDiv(chk, "1", "3", "0", 64)
chkDiv(chk, "3", "3", "1", 64) chkDiv(chk, "3", "3", "1", 64)
@ -116,33 +59,6 @@ template testMuldiv(chk, tst: untyped) =
chkDiv(chk, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "1", 128) chkDiv(chk, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "1", 128)
tst "operator `mod`": tst "operator `mod`":
chkMod(chk, "0", "3", "0", 8)
chkMod(chk, "1", "3", "1", 8)
chkMod(chk, "3", "3", "0", 8)
chkMod(chk, "3", "1", "0", 8)
chkMod(chk, "FF", "3", "FF", 8)
chkMod(chk, "FF", "4", "FF", 8)
chkMod(chk, "FF", "FF", "0", 8)
chkMod(chk, "0F", "FC", "3", 8)
chkMod(chk, "0", "3", "0", 16)
chkMod(chk, "1", "3", "1", 16)
chkMod(chk, "3", "3", "0", 16)
chkMod(chk, "3", "1", "0", 16)
chkMod(chk, "FFFF", "3", "FFFF", 16)
chkMod(chk, "FFFF", "4", "FFFF", 16)
chkMod(chk, "FFFF", "FFFF", "0", 16)
chkMod(chk, "0F", "FFFC", "3", 16)
chkMod(chk, "0", "3", "0", 32)
chkMod(chk, "1", "3", "1", 32)
chkMod(chk, "3", "3", "0", 32)
chkMod(chk, "3", "1", "0", 32)
chkMod(chk, "FFFFFFFF", "3", "FFFFFFFF", 32)
chkMod(chk, "FFFFFFFF", "4", "FFFFFFFF", 32)
chkMod(chk, "FFFFFFFF", "FFFFFFFF", "0", 32)
chkMod(chk, "0F", "FFFFFFFC", "3", 32)
chkMod(chk, "0", "3", "0", 64) chkMod(chk, "0", "3", "0", 64)
chkMod(chk, "1", "3", "1", 64) chkMod(chk, "1", "3", "1", 64)
chkMod(chk, "3", "3", "0", 64) chkMod(chk, "3", "3", "0", 64)
@ -162,33 +78,6 @@ template testMuldiv(chk, tst: untyped) =
chkMod(chk, "0F", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", "3", 128) chkMod(chk, "0F", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", "3", 128)
tst "operator `divmod`": tst "operator `divmod`":
chkDivMod(chk, "0", "3", "0", "0", 8)
chkDivMod(chk, "1", "3", "0", "1", 8)
chkDivMod(chk, "3", "3", "1", "0", 8)
chkDivMod(chk, "3", "1", "3", "0", 8)
chkDivMod(chk, "FF", "3", "0", "FF", 8)
chkDivMod(chk, "FF", "4", "0", "FF", 8)
chkDivMod(chk, "FF", "FF", "1", "0", 8)
chkDivMod(chk, "0F", "FC", "FD", "3", 8)
chkDivMod(chk, "0", "3", "0", "0", 16)
chkDivMod(chk, "1", "3", "0", "1", 16)
chkDivMod(chk, "3", "3", "1", "0", 16)
chkDivMod(chk, "3", "1", "3", "0", 16)
chkDivMod(chk, "FFFF", "3", "0", "FFFF", 16)
chkDivMod(chk, "FFFF", "4", "0", "FFFF", 16)
chkDivMod(chk, "FFFF", "FFFF", "1", "0", 16)
chkDivMod(chk, "0F", "FFFC", "FFFD", "3", 16)
chkDivMod(chk, "0", "3", "0", "0", 32)
chkDivMod(chk, "1", "3", "0", "1", 32)
chkDivMod(chk, "3", "3", "1", "0", 32)
chkDivMod(chk, "3", "1", "3", "0", 32)
chkDivMod(chk, "FFFFFFFF", "3", "0", "FFFFFFFF", 32)
chkDivMod(chk, "FFFFFFFF", "4", "0", "FFFFFFFF", 32)
chkDivMod(chk, "FFFFFFFF", "FFFFFFFF", "1", "0", 32)
chkDivMod(chk, "0F", "FFFFFFFC", "FFFFFFFD", "3", 32)
chkDivMod(chk, "0", "3", "0", "0", 64) chkDivMod(chk, "0", "3", "0", "0", 64)
chkDivMod(chk, "1", "3", "0", "1", 64) chkDivMod(chk, "1", "3", "0", "1", 64)
chkDivMod(chk, "3", "3", "1", "0", 64) chkDivMod(chk, "3", "3", "1", "0", 64)
@ -227,8 +116,8 @@ template testMuldiv(chk, tst: untyped) =
chkMod(chk, 2, -5, 2, 64) chkMod(chk, 2, -5, 2, 64)
chkMod(chk, -2, -5, -2, 64) chkMod(chk, -2, -5, -2, 64)
static: #static:
testMuldiv(ctCheck, ctTest) #testMuldiv(ctCheck, ctTest)
suite "Wider signed int muldiv coverage": suite "Wider signed int muldiv coverage":
testMuldiv(check, test) testMuldiv(check, test)
@ -318,19 +207,18 @@ suite "Testing signed int division and modulo implementation":
check: cast[int64](qr.quot) == -100'i64 div -13 check: cast[int64](qr.quot) == -100'i64 div -13
check: cast[int64](qr.rem) == -100'i64 mod -13 check: cast[int64](qr.rem) == -100'i64 mod -13
# test "Divmod(2^64, 3) returns the correct result": test "Divmod(2^64, 3) returns the correct result":
# let a = 1.stint(128) shl 64 let a = 1.stint(128) shl 64
# let b = 3.stint(128) let b = 3.stint(128)
# let qr = divmod(a, b) let qr = divmod(a, b)
# let q = cast[UintImpl[uint64]](qr.quot) let q = qr.quot
# let r = cast[UintImpl[uint64]](qr.rem) let r = qr.rem
# check: q.lo == 6148914691236517205'u64 check:
# check: q.hi == 0'u64 q == 6148914691236517205'u64.i128
# check: r.lo == 1'u64 r == 1'u64.i128
# check: r.hi == 0'u64
test "Divmod(1234567891234567890, 10) returns the correct result": test "Divmod(1234567891234567890, 10) returns the correct result":
let a = cast[StInt[64]](1234567891234567890'i64) let a = cast[StInt[64]](1234567891234567890'i64)
@ -343,4 +231,3 @@ suite "Testing signed int division and modulo implementation":
check: q == 123456789123456789'i64 check: q == 123456789123456789'i64
check: r == 0'i64 check: r == 0'i64

View File

@ -1,5 +1,5 @@
# Stint # Stint
# Copyright 2018 Status Research & Development GmbH # Copyright 2018-2023 Status Research & Development GmbH
# Licensed under either of # Licensed under either of
# #
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
@ -39,31 +39,13 @@ template chkIsOdd(chk: untyped, a: string, bits: int) =
template chkNotIsOdd(chk: untyped, a: string, bits: int) = template chkNotIsOdd(chk: untyped, a: string, bits: int) =
chk (not fromHex(StUint[bits], a).isOdd()) chk (not fromHex(StUint[bits], a).isOdd())
template chkIsEven(chk: untyped, a: string, bits: int) =
chk fromHex(StUint[bits], a).isEven()
template chkNotIsEven(chk: untyped, a: string, bits: int) =
chk (not fromHex(StUint[bits], a).isEven())
template testComparison(chk, tst: untyped) = template testComparison(chk, tst: untyped) =
tst "operator `LT`": tst "operator `LT`":
#[chkLT(chk, "0", "F", 8)
chkLT(chk, "F", "FF", 8)
chkLT(chk, "0", "F", 16)
chkLT(chk, "F", "FF", 16)
chkLT(chk, "FF", "FFF", 16)
chkLT(chk, "0", "F", 32)
chkLT(chk, "F", "FF", 32)
chkLT(chk, "FF", "FFF", 32)
chkLT(chk, "FFFF", "FFFFF", 32)
chkLT(chk, "0", "F", 64) chkLT(chk, "0", "F", 64)
chkLT(chk, "F", "FF", 64) chkLT(chk, "F", "FF", 64)
chkLT(chk, "FF", "FFF", 64) chkLT(chk, "FF", "FFF", 64)
chkLT(chk, "FFFF", "FFFFF", 64) chkLT(chk, "FFFF", "FFFFF", 64)
chkLT(chk, "FFFFF", "FFFFFFFF", 64)]# chkLT(chk, "FFFFF", "FFFFFFFF", 64)
chkLT(chk, "0", "F", 128) chkLT(chk, "0", "F", 128)
chkLT(chk, "F", "FF", 128) chkLT(chk, "F", "FF", 128)
@ -73,23 +55,11 @@ template testComparison(chk, tst: untyped) =
chkLT(chk, "FFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFF", 128) chkLT(chk, "FFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFF", 128)
tst "operator not `LT`": tst "operator not `LT`":
#[chkNotLT(chk, "0", "F", 8)
chkNotLT(chk, "F", "FF", 8)
chkNotLT(chk, "0", "F", 16)
chkNotLT(chk, "F", "FF", 16)
chkNotLT(chk, "FF", "FFF", 16)
chkNotLT(chk, "0", "F", 32)
chkNotLT(chk, "F", "FF", 32)
chkNotLT(chk, "FF", "FFF", 32)
chkNotLT(chk, "FFFF", "FFFFF", 32)
chkNotLT(chk, "0", "F", 64) chkNotLT(chk, "0", "F", 64)
chkNotLT(chk, "F", "FF", 64) chkNotLT(chk, "F", "FF", 64)
chkNotLT(chk, "FF", "FFF", 64) chkNotLT(chk, "FF", "FFF", 64)
chkNotLT(chk, "FFFF", "FFFFF", 64) chkNotLT(chk, "FFFF", "FFFFF", 64)
chkNotLT(chk, "FFFFF", "FFFFFFFF", 64)]# chkNotLT(chk, "FFFFF", "FFFFFFFF", 64)
chkNotLT(chk, "0", "F", 128) chkNotLT(chk, "0", "F", 128)
chkNotLT(chk, "F", "FF", 128) chkNotLT(chk, "F", "FF", 128)
@ -99,27 +69,12 @@ template testComparison(chk, tst: untyped) =
chkNotLT(chk, "FFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFF", 128) chkNotLT(chk, "FFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFF", 128)
tst "operator `LTE`": tst "operator `LTE`":
#[chkLTE(chk, "0", "F", 8)
chkLTE(chk, "F", "FF", 8)
chkLTE(chk, "F", "F", 8)
chkLTE(chk, "0", "F", 16)
chkLTE(chk, "F", "FF", 16)
chkLTE(chk, "FF", "FFF", 16)
chkLTE(chk, "FFF", "FFF", 16)
chkLTE(chk, "0", "F", 32)
chkLTE(chk, "F", "FF", 32)
chkLTE(chk, "FF", "FFF", 32)
chkLTE(chk, "FFFF", "FFFFF", 32)
chkLTE(chk, "FFFFF", "FFFFF", 32)
chkLTE(chk, "0", "F", 64) chkLTE(chk, "0", "F", 64)
chkLTE(chk, "F", "FF", 64) chkLTE(chk, "F", "FF", 64)
chkLTE(chk, "FF", "FFF", 64) chkLTE(chk, "FF", "FFF", 64)
chkLTE(chk, "FFFF", "FFFFF", 64) chkLTE(chk, "FFFF", "FFFFF", 64)
chkLTE(chk, "FFFFF", "FFFFFFFF", 64) chkLTE(chk, "FFFFF", "FFFFFFFF", 64)
chkLTE(chk, "FFFFFFFF", "FFFFFFFF", 64)]# chkLTE(chk, "FFFFFFFF", "FFFFFFFF", 64)
chkLTE(chk, "0", "F", 128) chkLTE(chk, "0", "F", 128)
chkLTE(chk, "F", "FF", 128) chkLTE(chk, "F", "FF", 128)
@ -130,23 +85,11 @@ template testComparison(chk, tst: untyped) =
chkLTE(chk, "FFFFFFFFFFFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFF", 128) chkLTE(chk, "FFFFFFFFFFFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFF", 128)
tst "operator not `LTE`": tst "operator not `LTE`":
#[chkNotLTE(chk, "0", "F", 8)
chkNotLTE(chk, "F", "FF", 8)
chkNotLTE(chk, "0", "F", 16)
chkNotLTE(chk, "F", "FF", 16)
chkNotLTE(chk, "FF", "FFF", 16)
chkNotLTE(chk, "0", "F", 32)
chkNotLTE(chk, "F", "FF", 32)
chkNotLTE(chk, "FF", "FFF", 32)
chkNotLTE(chk, "FFFF", "FFFFF", 32)
chkNotLTE(chk, "0", "F", 64) chkNotLTE(chk, "0", "F", 64)
chkNotLTE(chk, "F", "FF", 64) chkNotLTE(chk, "F", "FF", 64)
chkNotLTE(chk, "FF", "FFF", 64) chkNotLTE(chk, "FF", "FFF", 64)
chkNotLTE(chk, "FFFF", "FFFFF", 64) chkNotLTE(chk, "FFFF", "FFFFF", 64)
chkNotLTE(chk, "FFFFF", "FFFFFFFF", 64)]# chkNotLTE(chk, "FFFFF", "FFFFFFFF", 64)
chkNotLTE(chk, "0", "F", 128) chkNotLTE(chk, "0", "F", 128)
chkNotLTE(chk, "F", "FF", 128) chkNotLTE(chk, "F", "FF", 128)
@ -156,27 +99,12 @@ template testComparison(chk, tst: untyped) =
chkNotLTE(chk, "FFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFF", 128) chkNotLTE(chk, "FFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFF", 128)
tst "operator `EQ`": tst "operator `EQ`":
#[chkEQ(chk, "0", "0", 8)
chkEQ(chk, "FF", "FF", 8)
chkEQ(chk, "F", "F", 8)
chkEQ(chk, "0", "0", 16)
chkEQ(chk, "F", "F", 16)
chkEQ(chk, "FF", "FF", 16)
chkEQ(chk, "FFF", "FFF", 16)
chkEQ(chk, "0", "0", 32)
chkEQ(chk, "F", "F", 32)
chkEQ(chk, "FF", "FF", 32)
chkEQ(chk, "FFFF", "FFFF", 32)
chkEQ(chk, "FFFFF", "FFFFF", 32)
chkEQ(chk, "0", "0", 64) chkEQ(chk, "0", "0", 64)
chkEQ(chk, "F", "F", 64) chkEQ(chk, "F", "F", 64)
chkEQ(chk, "FF", "FF", 64) chkEQ(chk, "FF", "FF", 64)
chkEQ(chk, "FFFF", "FFFF", 64) chkEQ(chk, "FFFF", "FFFF", 64)
chkEQ(chk, "FFFFF", "FFFFF", 64) chkEQ(chk, "FFFFF", "FFFFF", 64)
chkEQ(chk, "FFFFFFFF", "FFFFFFFF", 64)]# chkEQ(chk, "FFFFFFFF", "FFFFFFFF", 64)
chkEQ(chk, "0", "0", 128) chkEQ(chk, "0", "0", 128)
chkEQ(chk, "F", "F", 128) chkEQ(chk, "F", "F", 128)
@ -186,23 +114,11 @@ template testComparison(chk, tst: untyped) =
chkEQ(chk, "FFFFFFFFFFFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFF", 128) chkEQ(chk, "FFFFFFFFFFFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFF", 128)
tst "operator not `EQ`": tst "operator not `EQ`":
#[chkNotEQ(chk, "0", "F", 8)
chkNotEQ(chk, "F", "FF", 8)
chkNotEQ(chk, "0", "F", 16)
chkNotEQ(chk, "F", "FF", 16)
chkNotEQ(chk, "FF", "FFF", 16)
chkNotEQ(chk, "0", "F", 32)
chkNotEQ(chk, "F", "FF", 32)
chkNotEQ(chk, "FF", "FFF", 32)
chkNotEQ(chk, "FFFF", "FFFFF", 32)
chkNotEQ(chk, "0", "F", 64) chkNotEQ(chk, "0", "F", 64)
chkNotEQ(chk, "F", "FF", 64) chkNotEQ(chk, "F", "FF", 64)
chkNotEQ(chk, "FF", "FFF", 64) chkNotEQ(chk, "FF", "FFF", 64)
chkNotEQ(chk, "FFFF", "FFFFF", 64) chkNotEQ(chk, "FFFF", "FFFFF", 64)
chkNotEQ(chk, "FFFFF", "FFFFFFFF", 64)]# chkNotEQ(chk, "FFFFF", "FFFFFFFF", 64)
chkNotEQ(chk, "0", "F", 128) chkNotEQ(chk, "0", "F", 128)
chkNotEQ(chk, "F", "FF", 128) chkNotEQ(chk, "F", "FF", 128)
@ -212,92 +128,56 @@ template testComparison(chk, tst: untyped) =
chkNotEQ(chk, "FFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFF", 128) chkNotEQ(chk, "FFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFF", 128)
tst "operator `isZero`": tst "operator `isZero`":
#[chkIsZero(chk, "0", 8) chkIsZero(chk, "0", 64)
chkIsZero(chk, "0", 16)
chkIsZero(chk, "0", 32)
chkIsZero(chk, "0", 64)]#
chkIsZero(chk, "0", 128) chkIsZero(chk, "0", 128)
chkIsZero(chk, "0", 256) chkIsZero(chk, "0", 256)
tst "operator not `isZero`": tst "operator not `isZero`":
#[chkNotIsZero(chk, "1", 8) chkNotIsZero(chk, "4", 64)
chkNotIsZero(chk, "2", 16)
chkNotIsZero(chk, "3", 32)
chkNotIsZero(chk, "4", 64)]#
chkNotIsZero(chk, "5", 128) chkNotIsZero(chk, "5", 128)
chkNotIsZero(chk, "6", 256) chkNotIsZero(chk, "6", 256)
tst "operator `isOdd`": tst "operator `isOdd`":
#[chkIsOdd(chk, "1", 8) chkIsOdd(chk, "1", 64)
chkIsOdd(chk, "1", 16)
chkIsOdd(chk, "1", 32)
chkIsOdd(chk, "1", 64)]#
chkIsOdd(chk, "1", 128) chkIsOdd(chk, "1", 128)
chkIsOdd(chk, "1", 256) chkIsOdd(chk, "1", 256)
#[chkIsOdd(chk, "FF", 8) chkIsOdd(chk, "FFFFFF", 64)
chkIsOdd(chk, "FFF", 16)
chkIsOdd(chk, "FFFFF", 32)
chkIsOdd(chk, "FFFFFF", 64)]#
chkIsOdd(chk, "FFFFFFFFFFFFFFF", 128) chkIsOdd(chk, "FFFFFFFFFFFFFFF", 128)
chkIsOdd(chk, "FFFFFFFFFFFFFFFFFF", 256) chkIsOdd(chk, "FFFFFFFFFFFFFFFFFF", 256)
tst "operator not `isOdd`": tst "operator not `isOdd`":
#[chkNotIsOdd(chk, "0", 8) chkNotIsOdd(chk, "0", 64)
chkNotIsOdd(chk, "0", 16)
chkNotIsOdd(chk, "0", 32)
chkNotIsOdd(chk, "0", 64)]#
chkNotIsOdd(chk, "0", 128) chkNotIsOdd(chk, "0", 128)
chkNotIsOdd(chk, "0", 256) chkNotIsOdd(chk, "0", 256)
#[chkNotIsOdd(chk, "4", 8) chkNotIsOdd(chk, "4", 64)
chkNotIsOdd(chk, "4", 16)
chkNotIsOdd(chk, "4", 32)
chkNotIsOdd(chk, "4", 64)]#
chkNotIsOdd(chk, "4", 128) chkNotIsOdd(chk, "4", 128)
chkNotIsOdd(chk, "4", 256) chkNotIsOdd(chk, "4", 256)
#[chkNotIsOdd(chk, "A", 8) chkNotIsOdd(chk, "FFFFFA", 64)
chkNotIsOdd(chk, "AAA", 16)
chkNotIsOdd(chk, "AAAA", 32)
chkNotIsOdd(chk, "FFFFFA", 64)]#
chkNotIsOdd(chk, "FFFFFFFFFFFFFFA", 128) chkNotIsOdd(chk, "FFFFFFFFFFFFFFA", 128)
chkNotIsOdd(chk, "FFFFFFFFFFFFFFFFFA", 256) chkNotIsOdd(chk, "FFFFFFFFFFFFFFFFFA", 256)
tst "operator `isEven`": tst "operator `isEven`":
#[chkNotIsOdd(chk, "0", 8) chkNotIsOdd(chk, "0", 64)
chkNotIsOdd(chk, "0", 16)
chkNotIsOdd(chk, "0", 32)
chkNotIsOdd(chk, "0", 64)]#
chkNotIsOdd(chk, "0", 128) chkNotIsOdd(chk, "0", 128)
chkNotIsOdd(chk, "0", 256) chkNotIsOdd(chk, "0", 256)
#[chkNotIsOdd(chk, "4", 8) chkNotIsOdd(chk, "4", 64)
chkNotIsOdd(chk, "4", 16)
chkNotIsOdd(chk, "4", 32)
chkNotIsOdd(chk, "4", 64)]#
chkNotIsOdd(chk, "4", 128) chkNotIsOdd(chk, "4", 128)
chkNotIsOdd(chk, "4", 256) chkNotIsOdd(chk, "4", 256)
#[chkNotIsOdd(chk, "A", 8) chkNotIsOdd(chk, "FFFFFA", 64)
chkNotIsOdd(chk, "AAA", 16)
chkNotIsOdd(chk, "AAAA", 32)
chkNotIsOdd(chk, "FFFFFA", 64)]#
chkNotIsOdd(chk, "FFFFFFFFFFFFFFA", 128) chkNotIsOdd(chk, "FFFFFFFFFFFFFFA", 128)
chkNotIsOdd(chk, "FFFFFFFFFFFFFFFFFA", 256) chkNotIsOdd(chk, "FFFFFFFFFFFFFFFFFA", 256)
tst "operator not `isEven`": tst "operator not `isEven`":
#[chkIsOdd(chk, "1", 8) chkIsOdd(chk, "1", 64)
chkIsOdd(chk, "1", 16)
chkIsOdd(chk, "1", 32)
chkIsOdd(chk, "1", 64)]#
chkIsOdd(chk, "1", 128) chkIsOdd(chk, "1", 128)
chkIsOdd(chk, "1", 256) chkIsOdd(chk, "1", 256)
#[chkIsOdd(chk, "FF", 8) chkIsOdd(chk, "FFFFFF", 64)
chkIsOdd(chk, "FFF", 16)
chkIsOdd(chk, "FFFFF", 32)
chkIsOdd(chk, "FFFFFF", 64)]#
chkIsOdd(chk, "FFFFFFFFFFFFFFF", 128) chkIsOdd(chk, "FFFFFFFFFFFFFFF", 128)
chkIsOdd(chk, "FFFFFFFFFFFFFFFFFF", 256) chkIsOdd(chk, "FFFFFFFFFFFFFFFFFF", 256)
@ -307,11 +187,10 @@ static:
suite "Wider unsigned int comparison coverage": suite "Wider unsigned int comparison coverage":
testComparison(check, test) testComparison(check, test)
#[
suite "Testing unsigned int comparison operators": suite "Testing unsigned int comparison operators":
let let
a = 10'i16.stuint(16) a = 10.stuint(64)
b = 15'i16.stuint(16) b = 15.stuint(64)
c = 150'u16 c = 150'u16
d = 4.stuint(128) shl 64 d = 4.stuint(128) shl 64
e = 4.stuint(128) e = 4.stuint(128)
@ -322,7 +201,7 @@ suite "Testing unsigned int comparison operators":
a < b a < b
not (a + b < b) not (a + b < b)
not (a + a + a < b + b) not (a + a + a < b + b)
not (a * b < cast[StUint[16]](c)) not (a * b < cast[StUint[64]](c))
e < d e < d
d < f d < f
@ -331,7 +210,7 @@ suite "Testing unsigned int comparison operators":
a <= b a <= b
not (a + b <= b) not (a + b <= b)
a + a + a <= b + b a + a + a <= b + b
a * b <= cast[StUint[16]](c) a * b <= cast[StUint[64]](c)
e <= d e <= d
d <= f d <= f
@ -340,7 +219,7 @@ suite "Testing unsigned int comparison operators":
b > a b > a
not (b > a + b) not (b > a + b)
not (b + b > a + a + a) not (b + b > a + a + a)
not (cast[StUint[16]](c) > a * b) not (cast[StUint[64]](c) > a * b)
d > e d > e
f > d f > d
@ -349,7 +228,7 @@ suite "Testing unsigned int comparison operators":
b >= a b >= a
not (b >= a + b) not (b >= a + b)
b + b >= a + a + a b + b >= a + a + a
cast[StUint[16]](c) >= a * b cast[StUint[64]](c) >= a * b
d >= e d >= e
f >= d f >= d
@ -360,4 +239,4 @@ suite "Testing unsigned int comparison operators":
b.isOdd b.isOdd
not b.isEven not b.isEven
# c.isEven # c.isEven
# not c.isOdd]# # not c.isOdd