Skip to content
Permalink
7e9ce072b7
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
42 lines (38 sloc) 978 Bytes
#!/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 ]
}