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
|
# 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
|
## Return a random sample from an array
|
||||||
result = src[rng.random_unsafe(uint32 src.len)]
|
result = src[rng.random_unsafe(uint32 src.len)]
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ type
|
||||||
HighHammingWeight
|
HighHammingWeight
|
||||||
Long01Sequence
|
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
|
case gen
|
||||||
of Uniform:
|
of Uniform:
|
||||||
result = rng.random_unsafe(T)
|
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":
|
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"
|
requires "https://github.com/alehander42/nim-quicktest >= 0.18.0", "https://github.com/status-im/nim-ttmath"
|
||||||
|
putEnv("TEST_LANG", "cpp")
|
||||||
switch("define", "release")
|
switch("define", "release")
|
||||||
test "uint256_ttmath", "cpp"
|
test "", "tests/test_uint256_ttmath"
|
||||||
|
|
||||||
task test, "Run all tests":
|
task test, "Run all tests":
|
||||||
exec "nimble test_internal"
|
exec "nimble test_internal"
|
||||||
|
|
|
@ -34,4 +34,6 @@ import
|
||||||
|
|
||||||
import
|
import
|
||||||
test_io,
|
test_io,
|
||||||
test_conversion
|
test_conversion,
|
||||||
|
t_randomized_divmod
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ echo "t_randomized_divmod xoshiro512** seed: ", seed
|
||||||
|
|
||||||
proc test_divmod(bits: static int, iters: int, gen: RandomGen) =
|
proc test_divmod(bits: static int, iters: int, gen: RandomGen) =
|
||||||
for _ in 0 ..< iters:
|
for _ in 0 ..< iters:
|
||||||
let a = rng.random_elem(Stuint[bits], gen)
|
let a = rng.random_elem(StUint[bits], gen)
|
||||||
let b = rng.random_elem(Stuint[bits], gen)
|
let b = rng.random_elem(StUint[bits], gen)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
let (q, r) = divmod(a, b)
|
let (q, r) = divmod(a, b)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import ../stint, ttmath
|
import ../stint, ttmath/ttmath
|
||||||
export ttmath
|
export ttmath
|
||||||
|
|
||||||
template asSt*(val: UInt): auto =
|
template asSt*(val: UInt): auto =
|
||||||
|
|
Loading…
Reference in New Issue