bookmarkfs/tests/lib_prng.at

40 lines
1 KiB
Text

dnl
dnl Copyright (C) 2025 CismonX <admin@cismon.net>
dnl
dnl Copying and distribution of this file, with or without modification,
dnl are permitted in any medium without royalty,
dnl provided the copyright notice and this notice are preserved.
dnl This file is offered as-is, without any warranty.
dnl
AT_SETUP([util lib: prng])
AT_KEYWORDS([lib prng])
# This test only serves as a basic sanity check.
#
# For reliable testing of PRNGs, see <https://prng.di.unimi.it/#quality>.
ATX_CHECK_LIB([
gen_num() {
check-util-lib prng -s$1 -n$2
}
seed=$(ath_fn_prng_seed)
count=32
num_1=$(gen_num $seed $count)
num_2=$(gen_num $seed $count)
num_3=$(gen_num $seed $count)
# Given the same seed, the results should be consistent.
if test "$num_1" != "$num_2" -o "$num_2" != "$num_3"; then
ATX_FAIL
fi
# Bad PRNG if we're getting duplicates too soon.
uniq_count=$(echo "$num_1" | sort | uniq | wc -l)
if test $uniq_count -ne $count; then
ATX_FAIL
fi
])
AT_CLEANUP