From c45619098059caffa9298c91de29fca1b4c3a727 Mon Sep 17 00:00:00 2001 From: andri lim Date: Tue, 22 Oct 2019 18:07:35 +0700 Subject: [PATCH] fixes operator precedence issue with nim 19.6 --- tests/test_int_comparison.nim | 12 ++++++------ tests/test_uint_comparison.nim | 10 +++++----- tests/test_uint_muldiv.nim | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/tests/test_int_comparison.nim b/tests/test_int_comparison.nim index 4a58e85..0ed354b 100644 --- a/tests/test_int_comparison.nim +++ b/tests/test_int_comparison.nim @@ -13,31 +13,31 @@ template chkLT(chk: untyped, a, b: string, bits: int) = chk fromHex(Stint[bits], a) < fromHex(Stint[bits], b) template chknotLT(chk: untyped, a, b: string, bits: int) = - chk not(fromHex(Stint[bits], b) < fromHex(Stint[bits], a)) + chk (not(fromHex(Stint[bits], b) < fromHex(Stint[bits], a))) template chkLTE(chk: untyped, a, b: string, bits: int) = chk fromHex(Stint[bits], a) <= fromHex(Stint[bits], b) template chknotLTE(chk: untyped, a, b: string, bits: int) = - chk not(fromHex(Stint[bits], b) <= fromHex(Stint[bits], a)) + chk (not(fromHex(Stint[bits], b) <= fromHex(Stint[bits], a))) template chkEQ(chk: untyped, a, b: string, bits: int) = chk fromHex(Stint[bits], a) == fromHex(Stint[bits], b) template chknotEQ(chk: untyped, a, b: string, bits: int) = - chk not(fromHex(Stint[bits], a) == fromHex(Stint[bits], b)) + chk (not(fromHex(Stint[bits], a) == fromHex(Stint[bits], b))) template chkisZero(chk: untyped, a: string, bits: int) = chk fromHex(Stint[bits], a).isZero() template chknotisZero(chk: untyped, a: string, bits: int) = - chk not fromHex(Stint[bits], a).isZero() + chk (not fromHex(Stint[bits], a).isZero()) template chkisNegative(chk: untyped, a: string, bits: int) = chk fromHex(Stint[bits], a).isNegative() template chknotisNegative(chk: untyped, a: string, bits: int) = - chk not fromHex(Stint[bits], a).isNegative() + chk (not fromHex(Stint[bits], a).isNegative()) template chkisOdd(chk: untyped, a: string, bits: int) = chk fromHex(Stint[bits], a).isOdd() @@ -49,7 +49,7 @@ template chkisEven(chk: untyped, a: string, bits: int) = chk fromHex(Stint[bits], a).isEven() 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 diff --git a/tests/test_uint_comparison.nim b/tests/test_uint_comparison.nim index f7c1232..4eedc61 100644 --- a/tests/test_uint_comparison.nim +++ b/tests/test_uint_comparison.nim @@ -13,25 +13,25 @@ template chkLT(chk: untyped, a, b: string, bits: int) = chk fromHex(Stuint[bits], a) < fromHex(Stuint[bits], b) template chknotLT(chk: untyped, a, b: string, bits: int) = - chk not(fromHex(Stuint[bits], b) < fromHex(Stuint[bits], a)) + chk (not(fromHex(Stuint[bits], b) < fromHex(Stuint[bits], a))) template chkLTE(chk: untyped, a, b: string, bits: int) = chk fromHex(Stuint[bits], a) <= fromHex(Stuint[bits], b) template chknotLTE(chk: untyped, a, b: string, bits: int) = - chk not(fromHex(Stuint[bits], b) <= fromHex(Stuint[bits], a)) + chk (not(fromHex(Stuint[bits], b) <= fromHex(Stuint[bits], a))) template chkEQ(chk: untyped, a, b: string, bits: int) = chk fromHex(Stuint[bits], a) == fromHex(Stuint[bits], b) template chknotEQ(chk: untyped, a, b: string, bits: int) = - chk not(fromHex(Stuint[bits], a) == fromHex(Stuint[bits], b)) + chk (not(fromHex(Stuint[bits], a) == fromHex(Stuint[bits], b))) template chkisZero(chk: untyped, a: string, bits: int) = chk fromHex(Stuint[bits], a).isZero() template chknotisZero(chk: untyped, a: string, bits: int) = - chk not fromHex(Stuint[bits], a).isZero() + chk (not fromHex(Stuint[bits], a).isZero()) template chkisOdd(chk: untyped, a: string, bits: int) = chk fromHex(Stuint[bits], a).isOdd() @@ -43,7 +43,7 @@ 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() + chk (not fromHex(Stuint[bits], a).isEven()) template ctTest(name: string, body: untyped) = body diff --git a/tests/test_uint_muldiv.nim b/tests/test_uint_muldiv.nim index 629f95c..e3a7257 100644 --- a/tests/test_uint_muldiv.nim +++ b/tests/test_uint_muldiv.nim @@ -9,6 +9,32 @@ import ../stint, unittest +template chkMul(chk: untyped, a, b, c: string, bits: int) = + chk (fromHex(Stuint[bits], a) * fromHex(Stuint[bits], b)) == fromHex(Stuint[bits], c) + +template chkDiv(chk: untyped, a, b, c: string, bits: int) = + chk (fromHex(Stuint[bits], a) div fromHex(Stuint[bits], b)) == fromHex(Stuint[bits], c) + +template chkMod(chk: untyped, a, b, c: string, bits: int) = + chk (fromHex(Stuint[bits], a) mod fromHex(Stuint[bits], b)) == fromHex(Stuint[bits], c) + +template chkDivMod(chk: untyped, a, b, c, d: string, bits: int) = + chk (fromHex(Stuint[bits], a) divmod fromHex(Stuint[bits], b)) == (fromHex(Stuint[bits], c), fromHex(Stuint[bits], d)) + +template testMuldiv(chk, tst: untyped) = + tst "operator `mul`": + chkMul(chk, "0", "3", "0", 8) + + #tst "operator `div`": + #tst "operator `mod`": + #tst "operator `divmod`": + +static: + testMuldiv(doAssert, ctTest) + +suite "Wider unsigned int muldiv coverage": + testMuldiv(check, test) + suite "Testing unsigned int multiplication implementation": test "Multiplication with result fitting in low half":