cosmetics changes

This commit is contained in:
andri lim 2019-10-23 09:20:06 +07:00 committed by zah
parent e58eb117c8
commit 8cc9116d1e
14 changed files with 97 additions and 80 deletions

9
tests/test_helpers.nim Normal file
View File

@ -0,0 +1,9 @@
# this is some template to help mimicking unittest at compile time
# perhaps we can implement a real compile time unittest?
template ctCheck*(cond: untyped) =
doAssert(cond)
template ctTest*(name: string, body: untyped) =
body
echo "[OK] compile time ", name

View File

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest import ../stint, unittest, test_helpers
template chkAddition(chk, a, b, c, bits: untyped) = template chkAddition(chk, a, b, c, bits: untyped) =
block: block:
@ -39,10 +39,6 @@ template chkNegation(chk, a, b, bits: untyped) =
template chkAbs(chk, a, b, bits: untyped) = template chkAbs(chk, a, b, bits: untyped) =
chk stint(a, bits).abs() == stint(b, bits) chk stint(a, bits).abs() == stint(b, bits)
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
template testAddSub(chk, tst: untyped) = template testAddSub(chk, tst: untyped) =
tst "addition": tst "addition":
chkAddition(chk, 0'i8, 0'i8, 0'i8, 8) chkAddition(chk, 0'i8, 0'i8, 0'i8, 8)
@ -286,7 +282,7 @@ template testAddSub(chk, tst: untyped) =
chkAbs(chk, 9223372036854775807, 9223372036854775807, 128) chkAbs(chk, 9223372036854775807, 9223372036854775807, 128)
static: static:
testAddSub(doAssert, ctTest) testAddSub(ctCheck, ctTest)
suite "Wider signed int addsub coverage": suite "Wider signed int addsub coverage":
testAddSub(check, test) testAddSub(check, test)

View File

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest import ../stint, unittest, test_helpers
template chkNot(chk: untyped, a, b: distinct SomeInteger, bits: int) = template chkNot(chk: untyped, a, b: distinct SomeInteger, bits: int) =
chk stint(a, bits).not() == stint(b, bits) chk stint(a, bits).not() == stint(b, bits)
@ -30,10 +30,6 @@ template chkShl(chk: untyped, a: string, b: SomeInteger, c: string, bits: int) =
template chkShr(chk: untyped, a: string, b: SomeInteger, c: string, bits: int) = template chkShr(chk: untyped, a: string, b: SomeInteger, c: string, bits: int) =
chk (fromHex(Stint[bits], a) shr b) == fromHex(Stint[bits], c) chk (fromHex(Stint[bits], a) shr b) == fromHex(Stint[bits], c)
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
template testBitwise(chk, tst: untyped) = template testBitwise(chk, tst: untyped) =
# TODO: see issue #95 # TODO: see issue #95
@ -310,7 +306,7 @@ template testBitwise(chk, tst: untyped) =
chkShr(chk, "F000000000000000000000000000000000000000000000000000000000000000", 233, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF80000", 256) chkShr(chk, "F000000000000000000000000000000000000000000000000000000000000000", 233, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF80000", 256)
static: static:
testBitwise(doAssert, ctTest) testBitwise(ctCheck, ctTest)
suite "Wider signed int bitwise coverage": suite "Wider signed int bitwise coverage":
testBitwise(check, test) testBitwise(check, test)

View File

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest import ../stint, unittest, test_helpers
template chkLT(chk: untyped, a, b: string, bits: int) = template chkLT(chk: untyped, a, b: string, bits: int) =
chk fromHex(Stint[bits], a) < fromHex(Stint[bits], b) chk fromHex(Stint[bits], a) < fromHex(Stint[bits], b)
@ -51,10 +51,6 @@ template chkisEven(chk: untyped, a: string, bits: int) =
template chknotisEven(chk: untyped, a: string, bits: int) = template chknotisEven(chk: untyped, a: string, bits: int) =
chk (not fromHex(Stint[bits], a).isEven()) chk (not fromHex(Stint[bits], a).isEven())
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
template testComparison(chk, tst: untyped) = template testComparison(chk, tst: untyped) =
tst "operator `LT`": tst "operator `LT`":
chkLT(chk, "0", "F", 8) chkLT(chk, "0", "F", 8)
@ -377,7 +373,7 @@ template testComparison(chk, tst: untyped) =
chkIsOdd(chk, "FFFFFFFFFFFFFFFFFF", 256) chkIsOdd(chk, "FFFFFFFFFFFFFFFFFF", 256)
static: static:
testComparison(doAssert, ctTest) testComparison(ctCheck, ctTest)
suite "Wider signed int comparison coverage": suite "Wider signed int comparison coverage":
testComparison(check, test) testComparison(check, test)

View File

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest import ../stint, unittest, test_helpers
template chkMul(chk: untyped, a, b, c: string, bits: int) = template chkMul(chk: untyped, a, b, c: string, bits: int) =
chk (fromHex(Stint[bits], a) * fromHex(Stint[bits], b)) == fromHex(Stint[bits], c) chk (fromHex(Stint[bits], a) * fromHex(Stint[bits], b)) == fromHex(Stint[bits], c)
@ -21,10 +21,6 @@ template chkMod(chk: untyped, a, b, c: string, bits: int) =
template chkDivMod(chk: untyped, a, b, c, d: string, bits: int) = template chkDivMod(chk: untyped, a, b, c, d: string, bits: int) =
chk divmod(fromHex(Stint[bits], a), fromHex(Stint[bits], b)) == (fromHex(Stint[bits], c), fromHex(Stint[bits], d)) chk divmod(fromHex(Stint[bits], a), fromHex(Stint[bits], b)) == (fromHex(Stint[bits], c), fromHex(Stint[bits], d))
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
template testMuldiv(chk, tst: untyped) = template testMuldiv(chk, tst: untyped) =
tst "operator `mul`": tst "operator `mul`":
chkMul(chk, "0", "3", "0", 8) chkMul(chk, "0", "3", "0", 8)
@ -209,11 +205,11 @@ template testMuldiv(chk, tst: untyped) =
chkDivMod(chk, "0F", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD", "3", 128) chkDivMod(chk, "0F", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD", "3", 128)
static: static:
testMuldiv(doAssert, ctTest) testMuldiv(ctCheck, ctTest)
suite "Wider signed int muldiv coverage": suite "Wider signed int muldiv coverage":
testMuldiv(check, test) testMuldiv(check, test)
#[
suite "Testing signed int multiplication implementation": suite "Testing signed int multiplication implementation":
test "Multiplication with result fitting in low half": test "Multiplication with result fitting in low half":
@ -324,4 +320,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

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest, strutils, math import ../stint, unittest, strutils, math, test_helpers
template nativeStuint(chk, nint: untyped, bits: int) = template nativeStuint(chk, nint: untyped, bits: int) =
chk $(nint.stuint(bits)) == $(nint) chk $(nint.stuint(bits)) == $(nint)
@ -104,10 +104,6 @@ template chkDumpHex(chk: untyped, BE, LE: string, bits: int) =
chk dumpHex(x, bigEndian) == data chk dumpHex(x, bigEndian) == data
chk dumpHex(x, littleEndian) == LE chk dumpHex(x, littleEndian) == LE
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
template testIO(chk, tst: untyped) = template testIO(chk, tst: untyped) =
tst "[stuint] Creation from native ints": tst "[stuint] Creation from native ints":
nativeStuint(chk, 0, 8) nativeStuint(chk, 0, 8)
@ -559,6 +555,67 @@ template testIO(chk, tst: untyped) =
chkTruncateStint(chk, high(int64), int64, 64) chkTruncateStint(chk, high(int64), int64, 64)
chkTruncateStint(chk, low(int64), uint64, "0x8000000000000000", 64) chkTruncateStint(chk, low(int64), uint64, "0x8000000000000000", 64)
chkTruncateStint(chk, low(uint8), uint8, 128)
#chkTruncateStint(chk, low(int8), int8, 128) # TODO: bug #92
chkTruncateStint(chk, high(int8), uint8, 128)
chkTruncateStint(chk, high(int8), int8, 128)
#chkTruncateStint(chk, low(int8), uint8, "0x80", 128) # TODO: bug #92
chkTruncateStint(chk, low(uint8), uint16, 128)
#chkTruncateStint(chk, low(int8), int16, 128) # TODO: bug #92
chkTruncateStint(chk, high(int8), uint16, 128)
chkTruncateStint(chk, high(int8), int16, 128)
#chkTruncateStint(chk, low(int8), uint16, "0xFF80", 128) # TODO: bug #92
chkTruncateStint(chk, low(uint16), uint16, 128)
#chkTruncateStint(chk, low(int16), int16, 128) # TODO: bug #92
chkTruncateStint(chk, high(int16), uint16, 128)
chkTruncateStint(chk, high(int16), int16, 128)
#chkTruncateStint(chk, low(int16), uint16, "0x8000", 128) # TODO: bug #92
chkTruncateStint(chk, low(uint8), uint32, 128)
#chkTruncateStint(chk, low(int8), int32, 128) # TODO: bug #92
chkTruncateStint(chk, high(int8), uint32, 128)
chkTruncateStint(chk, high(int8), int32, 128)
#chkTruncateStint(chk, low(int8), uint32, "0xFFFFFF80", 128) # TODO: bug #92
chkTruncateStint(chk, low(uint16), uint32, 128)
#chkTruncateStint(chk, low(int16), int32, 128) # TODO: bug #92
chkTruncateStint(chk, high(int16), uint32, 128)
chkTruncateStint(chk, high(int16), int32, 128)
#chkTruncateStint(chk, low(int16), uint32, "0xFFFF8000", 128) # TODO: bug #92
chkTruncateStint(chk, low(uint32), uint32, 128)
#chkTruncateStint(chk, low(int32), int32, 128) # TODO: bug #92
chkTruncateStint(chk, high(int32), uint32, 128)
chkTruncateStint(chk, high(int32), int32, 128)
#chkTruncateStint(chk, low(int32), uint32, "0x80000000", 128) # TODO: bug #92
chkTruncateStint(chk, low(uint8), uint64, 128)
#chkTruncateStint(chk, low(int8), int64, 128) # TODO: bug #92
chkTruncateStint(chk, high(int8), uint64, 128)
chkTruncateStint(chk, high(int8), int64, 128)
#chkTruncateStint(chk, low(int8), uint64, "0xFFFFFFFFFFFFFF80", 128) # TODO: bug #92
chkTruncateStint(chk, low(uint16), uint64, 128)
#chkTruncateStint(chk, low(int16), int64, 128) # TODO: bug #92
chkTruncateStint(chk, high(int16), uint64, 128)
chkTruncateStint(chk, high(int16), int64, 128)
#chkTruncateStint(chk, low(int16), uint64, "0xFFFFFFFFFFFF8000", 128) # TODO: bug #92
chkTruncateStint(chk, low(uint32), uint64, 128)
#chkTruncateStint(chk, low(int32), int64, 128) # TODO: bug #92
chkTruncateStint(chk, high(int32), uint64, 128)
chkTruncateStint(chk, high(int32), int64, 128)
#chkTruncateStint(chk, low(int32), uint64, "0xFFFFFFFF80000000", 128) # TODO: bug #92
when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0):
chkTruncateStint(chk, low(uint64), uint64, 128)
#chkTruncateStint(chk, low(int64), int64, 128) # TODO: bug #92
chkTruncateStint(chk, high(int64), uint64, 128)
chkTruncateStint(chk, high(int64), int64, 128)
#chkTruncateStint(chk, low(int64), uint64, "0x8000000000000000", 128) # TODO: bug #92
tst "[stuint] parse - toString roundtrip": tst "[stuint] parse - toString roundtrip":
chkRoundTripBin(chk, chkRoundTripStuint, 8, 1) chkRoundTripBin(chk, chkRoundTripStuint, 8, 1)
@ -960,7 +1017,7 @@ template testIO(chk, tst: untyped) =
chkDumpHex(chk, "abcdef0012345678abcdef1122334455", "5544332211efcdab7856341200efcdab", 128) chkDumpHex(chk, "abcdef0012345678abcdef1122334455", "5544332211efcdab7856341200efcdab", 128)
static: static:
testIO(doAssert, ctTest) testIO(ctCheck, ctTest)
proc main() = proc main() =
# Nim GC protests we are using too much global variables # Nim GC protests we are using too much global variables

View File

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest import ../stint, unittest, test_helpers
template chkAddition(chk, a, b, c, bits: untyped) = template chkAddition(chk, a, b, c, bits: untyped) =
block: block:
@ -33,10 +33,6 @@ template chkInplaceSubstraction(chk, a, b, c, bits: untyped) =
x -= stuint(b, bits) x -= stuint(b, bits)
chk x == stuint(c, bits) chk x == stuint(c, bits)
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
template testAddSub(chk, tst: untyped) = template testAddSub(chk, tst: untyped) =
tst "addition": tst "addition":
chkAddition(chk, 0'u8, 0'u8, 0'u8, 8) chkAddition(chk, 0'u8, 0'u8, 0'u8, 8)
@ -203,7 +199,7 @@ template testAddSub(chk, tst: untyped) =
chkInplaceSubstraction(chk, high(uint64), high(uint64), 0'u64, 128) chkInplaceSubstraction(chk, high(uint64), high(uint64), 0'u64, 128)
static: static:
testAddSub(doAssert, ctTest) testAddSub(ctCheck, ctTest)
suite "Wider unsigned int addsub coverage": suite "Wider unsigned int addsub coverage":
testAddSub(check, test) testAddSub(check, test)

View File

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest import ../stint, unittest, test_helpers
template chkCountOnes(chk: untyped, bits: int) = template chkCountOnes(chk: untyped, bits: int) =
block: block:
@ -62,10 +62,6 @@ template chkTrailingZeros(chk: untyped, bits: int) =
x = x shl 1 x = x shl 1
chk x.trailingZeros == i chk x.trailingZeros == i
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
template testBitOps(chk, tst: untyped) = template testBitOps(chk, tst: untyped) =
tst "countOnes": tst "countOnes":
chk countOnes(0b01000100'u8.stuint(8)) == 2 chk countOnes(0b01000100'u8.stuint(8)) == 2
@ -218,7 +214,7 @@ template testBitOps(chk, tst: untyped) =
chkTrailingZeros(chk, 256) chkTrailingZeros(chk, 256)
static: static:
testBitOps(doAssert, ctTest) testBitOps(ctCheck, ctTest)
suite "Testing bitops2": suite "Testing bitops2":
testBitOps(check, test) testBitOps(check, test)

View File

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest import ../stint, unittest, test_helpers
template chkNot(chk: untyped, a, b: distinct SomeInteger, bits: int) = template chkNot(chk: untyped, a, b: distinct SomeInteger, bits: int) =
chk stuint(a, bits).not() == stuint(b, bits) chk stuint(a, bits).not() == stuint(b, bits)
@ -30,10 +30,6 @@ template chkShl(chk: untyped, a: string, b: SomeInteger, c: string, bits: int) =
template chkShr(chk: untyped, a: string, b: SomeInteger, c: string, bits: int) = template chkShr(chk: untyped, a: string, b: SomeInteger, c: string, bits: int) =
chk (fromHex(Stuint[bits], a) shr b) == fromHex(Stuint[bits], c) chk (fromHex(Stuint[bits], a) shr b) == fromHex(Stuint[bits], c)
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
template testBitwise(chk, tst: untyped) = template testBitwise(chk, tst: untyped) =
# TODO: see issue #95 # TODO: see issue #95
@ -311,7 +307,7 @@ template testBitwise(chk, tst: untyped) =
chkShr(chk, "F000000000000000000000000000000000000000000000000000000000000000", 233, "780000", 256) chkShr(chk, "F000000000000000000000000000000000000000000000000000000000000000", 233, "780000", 256)
static: static:
testBitwise(doAssert, ctTest) testBitwise(ctCheck, ctTest)
suite "Wider unsigned int bitwise coverage": suite "Wider unsigned int bitwise coverage":
testBitwise(check, test) testBitwise(check, test)

View File

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest import ../stint, unittest, test_helpers
template chkLT(chk: untyped, a, b: string, bits: int) = template chkLT(chk: untyped, a, b: string, bits: int) =
chk fromHex(Stuint[bits], a) < fromHex(Stuint[bits], b) chk fromHex(Stuint[bits], a) < fromHex(Stuint[bits], b)
@ -45,10 +45,6 @@ template chkisEven(chk: untyped, a: string, bits: int) =
template chknotisEven(chk: untyped, a: string, bits: int) = template chknotisEven(chk: untyped, a: string, bits: int) =
chk (not fromHex(Stuint[bits], a).isEven()) chk (not fromHex(Stuint[bits], a).isEven())
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
template testComparison(chk, tst: untyped) = template testComparison(chk, tst: untyped) =
tst "operator `LT`": tst "operator `LT`":
chkLT(chk, "0", "F", 8) chkLT(chk, "0", "F", 8)
@ -306,7 +302,7 @@ template testComparison(chk, tst: untyped) =
chkIsOdd(chk, "FFFFFFFFFFFFFFFFFF", 256) chkIsOdd(chk, "FFFFFFFFFFFFFFFFFF", 256)
static: static:
testComparison(doAssert, ctTest) testComparison(ctCheck, ctTest)
suite "Wider unsigned int comparison coverage": suite "Wider unsigned int comparison coverage":
testComparison(check, test) testComparison(check, test)

View File

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest, stew/byteutils import ../stint, unittest, stew/byteutils, test_helpers
template chkSwapBytes(chk: untyped, bits: int, hex: string) = template chkSwapBytes(chk: untyped, bits: int, hex: string) =
# dumpHex already do the job to swap the output if # dumpHex already do the job to swap the output if
@ -73,12 +73,8 @@ template testEndians(chkFunc, tst: untyped) =
chkEndians(chkFunc, tst, chkFromToLE) chkEndians(chkFunc, tst, chkFromToLE)
chkEndians(chkFunc, tst, chkFromToBE) chkEndians(chkFunc, tst, chkFromToBE)
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
static: static:
testEndians(doAssert, ctTest) testEndians(ctCheck, ctTest)
suite "Testing endians": suite "Testing endians":
test "Endians give sane results": test "Endians give sane results":

View File

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest, math import ../stint, unittest, math, test_helpers
template chkPow(chk: untyped, a, b, c: string, bits: int) = template chkPow(chk: untyped, a, b, c: string, bits: int) =
chk pow(fromHex(Stuint[bits], a), fromHex(Stuint[bits], b)) == fromHex(Stuint[bits], c) chk pow(fromHex(Stuint[bits], a), fromHex(Stuint[bits], b)) == fromHex(Stuint[bits], c)
@ -15,10 +15,6 @@ template chkPow(chk: untyped, a, b, c: string, bits: int) =
template chkPow(chk: untyped, a: string, b: SomeInteger, c: string, bits: int) = template chkPow(chk: untyped, a: string, b: SomeInteger, c: string, bits: int) =
chk pow(fromHex(Stuint[bits], a), b) == fromHex(Stuint[bits], c) chk pow(fromHex(Stuint[bits], a), b) == fromHex(Stuint[bits], c)
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
template testExp(chk, tst: untyped) = template testExp(chk, tst: untyped) =
tst "BigInt BigInt Pow": tst "BigInt BigInt Pow":
chkPow(chk, "F", "2", "E1", 8) chkPow(chk, "F", "2", "E1", 8)
@ -63,7 +59,7 @@ template testExp(chk, tst: untyped) =
chkPow(chk, "FFFFF", 3, "ffffd00002fffff", 128) chkPow(chk, "FFFFF", 3, "ffffd00002fffff", 128)
static: static:
testExp(doAssert, ctTest) testExp(ctCheck, ctTest)
suite "Wider unsigned int exp coverage": suite "Wider unsigned int exp coverage":
testExp(check, test) testExp(check, test)

View File

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest, math import ../stint, unittest, math, test_helpers
template chkAddmod(chk: untyped, a, b, m, c: string, bits: int) = template chkAddmod(chk: untyped, a, b, m, c: string, bits: int) =
chk addmod(fromHex(Stuint[bits], a), fromHex(Stuint[bits], b), fromHex(Stuint[bits], m)) == fromHex(Stuint[bits], c) chk addmod(fromHex(Stuint[bits], a), fromHex(Stuint[bits], b), fromHex(Stuint[bits], m)) == fromHex(Stuint[bits], c)
@ -21,10 +21,6 @@ template chkMulmod(chk: untyped, a, b, m, c: string, bits: int) =
template chkPowmod(chk: untyped, a, b, m, c: string, bits: int) = template chkPowmod(chk: untyped, a, b, m, c: string, bits: int) =
chk powmod(fromHex(Stuint[bits], a), fromHex(Stuint[bits], b), fromHex(Stuint[bits], m)) == fromHex(Stuint[bits], c) chk powmod(fromHex(Stuint[bits], a), fromHex(Stuint[bits], b), fromHex(Stuint[bits], m)) == fromHex(Stuint[bits], c)
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
template testModArith(chk, tst: untyped) = template testModArith(chk, tst: untyped) =
tst "addmod": tst "addmod":
chkAddMod(chk, "F", "F", "7", "2", 8) chkAddMod(chk, "F", "F", "7", "2", 8)
@ -141,7 +137,7 @@ template testModArith(chk, tst: untyped) =
chkPowMod(chk, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "3", "C", "3", 128) chkPowMod(chk, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "3", "C", "3", 128)
static: static:
testModArith(doAssert, ctTest) testModArith(ctCheck, ctTest)
suite "Wider unsigned Modular arithmetic coverage": suite "Wider unsigned Modular arithmetic coverage":
testModArith(check, test) testModArith(check, test)

View File

@ -7,7 +7,7 @@
# #
# 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.
import ../stint, unittest import ../stint, unittest, test_helpers
template chkMul(chk: untyped, a, b, c: string, bits: int) = template chkMul(chk: untyped, a, b, c: string, bits: int) =
chk (fromHex(Stuint[bits], a) * fromHex(Stuint[bits], b)) == fromHex(Stuint[bits], c) chk (fromHex(Stuint[bits], a) * fromHex(Stuint[bits], b)) == fromHex(Stuint[bits], c)
@ -21,10 +21,6 @@ template chkMod(chk: untyped, a, b, c: string, bits: int) =
template chkDivMod(chk: untyped, a, b, c, d: string, bits: int) = template chkDivMod(chk: untyped, a, b, c, d: string, bits: int) =
chk divmod(fromHex(Stuint[bits], a), fromHex(Stuint[bits], b)) == (fromHex(Stuint[bits], c), fromHex(Stuint[bits], d)) chk divmod(fromHex(Stuint[bits], a), fromHex(Stuint[bits], b)) == (fromHex(Stuint[bits], c), fromHex(Stuint[bits], d))
template ctTest(name: string, body: untyped) =
body
echo "[OK] compile time ", name
template testMuldiv(chk, tst: untyped) = template testMuldiv(chk, tst: untyped) =
tst "operator `mul`": tst "operator `mul`":
chkMul(chk, "0", "3", "0", 8) chkMul(chk, "0", "3", "0", 8)
@ -216,7 +212,7 @@ template testMuldiv(chk, tst: untyped) =
chkDivMod(chk, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "27", "6906906906906906906906906906906", "15", 128) chkDivMod(chk, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "27", "6906906906906906906906906906906", "15", 128)
static: static:
testMuldiv(doAssert, ctTest) testMuldiv(ctCheck, ctTest)
suite "Wider unsigned int muldiv coverage": suite "Wider unsigned int muldiv coverage":
testMuldiv(check, test) testMuldiv(check, test)