enable randomized divmod tests
This commit is contained in:
parent
c5955f7e97
commit
7fc30a8f1c
|
@ -118,7 +118,7 @@ func random_unsafe*[T: SomeInteger](rng: var RngState, inclRange: Slice[T]): T =
|
|||
# Containers
|
||||
# ------------------------------------------------------------
|
||||
|
||||
func sample_unsafe*[T](rng: var RngState, src: openarray[T]): T =
|
||||
func sample_unsafe*[T](rng: var RngState, src: openArray[T]): T =
|
||||
## Return a random sample from an array
|
||||
result = src[rng.random_unsafe(uint32 src.len)]
|
||||
|
||||
|
@ -206,7 +206,7 @@ type
|
|||
HighHammingWeight
|
||||
Long01Sequence
|
||||
|
||||
func random_elem*(rng: var RngState, T: typedesc, gen: RandomGen): T {.inline, noInit.} =
|
||||
func random_elem*(rng: var RngState, T: typedesc, gen: RandomGen): T {.inline, noinit.} =
|
||||
case gen
|
||||
of Uniform:
|
||||
result = rng.random_unsafe(T)
|
||||
|
|
|
@ -30,8 +30,9 @@ task test_public_api, "Run all tests - prod implementation (StUint[64] = uint64"
|
|||
|
||||
task test_uint256_ttmath, "Run random tests Uint256 vs TTMath":
|
||||
requires "https://github.com/alehander42/nim-quicktest >= 0.18.0", "https://github.com/status-im/nim-ttmath"
|
||||
switch("define", "release")
|
||||
test "uint256_ttmath", "cpp"
|
||||
putEnv("TEST_LANG", "cpp")
|
||||
switch("define", "release")
|
||||
test "", "tests/test_uint256_ttmath"
|
||||
|
||||
task test, "Run all tests":
|
||||
exec "nimble test_internal"
|
||||
|
|
|
@ -34,4 +34,6 @@ import
|
|||
|
||||
import
|
||||
test_io,
|
||||
test_conversion
|
||||
test_conversion,
|
||||
t_randomized_divmod
|
||||
|
||||
|
|
|
@ -25,15 +25,15 @@ echo "t_randomized_divmod xoshiro512** seed: ", seed
|
|||
|
||||
proc test_divmod(bits: static int, iters: int, gen: RandomGen) =
|
||||
for _ in 0 ..< iters:
|
||||
let a = rng.random_elem(Stuint[bits], gen)
|
||||
let b = rng.random_elem(Stuint[bits], gen)
|
||||
let a = rng.random_elem(StUint[bits], gen)
|
||||
let b = rng.random_elem(StUint[bits], gen)
|
||||
|
||||
try:
|
||||
let (q, r) = divmod(a, b)
|
||||
doAssert a == q*b + r
|
||||
except DivByZeroDefect:
|
||||
doAssert b.isZero()
|
||||
|
||||
|
||||
template test(bits: static int) =
|
||||
test "(q, r) = divmod(a, b) <=> a = q*b + r (" & $bits & " bits)":
|
||||
test_divmod(bits, Iters, Uniform)
|
||||
|
@ -43,4 +43,4 @@ template test(bits: static int) =
|
|||
suite "Randomized division and modulo checks":
|
||||
test(128)
|
||||
test(256)
|
||||
test(512)
|
||||
test(512)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import ../stint, ttmath
|
||||
import ../stint, ttmath/ttmath
|
||||
export ttmath
|
||||
|
||||
template asSt*(val: UInt): auto =
|
||||
|
|
Loading…
Reference in New Issue