Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
parallel-slurm/tests/prng.bats
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (38 sloc)
978 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bats | |
# shellcheck disable=1083 | |
true | |
# shellcheck source=../parallel_opts.sh | |
. "${BATS_TEST_DIRNAME}/../examples/script_that_sometimes_fails.sh" | |
@test 'prng produces a uniform distribution with a single zero, and has entropy' { | |
# shellcheck disable=2034 | |
SLURM_NTASKS=5 | |
not_sorted=0 | |
for seed in {0..9} | |
do | |
result=() | |
num_zeros=0 | |
for ID in {0..4} | |
do | |
x=$(prng) | |
if (( x % SLURM_NTASKS == 0 )) | |
then | |
num_zeros=$(( num_zeros + 1 )) | |
fi | |
result[ID]=$x | |
done | |
echo "seed: $seed, prng: ${result[*]}, num_zeros: $num_zeros" | |
[[ $num_zeros -eq 1 ]] | |
# Verify it contains all the values / is a uniform distribution. | |
expected=( $(seq 0 4) ) | |
IFS=$'\n' sorted=($(sort <<<"${result[*]}")) | |
unset IFS | |
[[ "${sorted[*]}" = "${expected[*]}" ]] | |
if [[ "${sorted[*]}" != "${result[*]}" ]] | |
then | |
not_sorted=$(( not_sorted + 1)) | |
fi | |
done | |
# Check for entropy. | |
echo "not_sorted: $not_sorted" | |
[ $not_sorted -ge 6 ] | |
} |