source: zzuf/trunk/test/check-flag-r @ 4268

Last change on this file since 4268 was 4268, checked in by Sam Hocevar, 11 years ago

Rename check-memory to check-flag-M and check-rng to check-flag-r.

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/bin/sh
2#
3#  check-flag-r - zzuf RNG statistic tests
4#  Copyright (c) 2008-2010 Sam Hocevar <sam@hocevar.net>
5#                All Rights Reserved
6#
7#  This program is free software. It comes without any warranty, to
8#  the extent permitted by applicable law. You can redistribute it
9#  and/or modify it under the terms of the Do What The Fuck You Want
10#  To Public License, Version 2, as published by Sam Hocevar. See
11#  http://sam.zoy.org/wtfpl/COPYING for more details.
12#
13
14. "$(dirname "$0")/functions.inc"
15
16checkflip()
17{
18    r=$1
19    expect=$2
20    s2=$seed
21    mib=20
22    rmax=-1
23    rmin=-1
24    rtot=0
25    new_test "$mib MiB of zeroes, ratio $r"
26    for x in 0 1 2 3 4; do
27        ret=`dd if=/dev/zero bs=1048576 count=$mib 2>/dev/null | $ZZUF -s $s2 -r $r | "$ZZERO"`
28        if [ "$rmax" = -1 -o "$ret" -gt "$rmax" ]; then rmax=$ret; fi
29        if [ "$rmin" = -1 -o "$ret" -lt "$rmin" ]; then rmin=$ret; fi
30        rtot=`expr $rtot + $ret || true`
31        echo " try $x .......... $ret"
32        s2=`expr $s2 + 1`
33    done
34    rmean=`expr '(' $rtot + 2 ')' / 5 || true`
35    delta=`expr $rmean - $expect || true`
36    printf " expected $expect min/avg/max $rmin/$rmean/$rmax .........."
37    if [ "$delta" -gt -5 -a "$delta" -lt 5 ]; then
38        pass_test " ok"
39    elif [ $(($rmean * 8)) -lt $(($expect * 7)) \
40               -o $(($rmean * 7)) -gt $(($expect * 8)) ]; then
41        fail_test " FAILED"
42    else
43        pass_test " ok"
44    fi
45}
46
47start_test "zzuf -r test"
48
49# if X flips are performed on N bits set to 0, the average number of bits
50# set to 1 is: N / 2 * (1 - pow(1 - 2 / N, X)
51checkflip 0.000000001 0
52checkflip 0.00000001  1
53checkflip 0.0000001  16
54checkflip 0.000001  167
55checkflip 0.00001  1677
56checkflip 0.0001  16775
57checkflip 0.001  167604
58checkflip 0.01  1661055
59checkflip 0.1  15205967
60
61stop_test
62
Note: See TracBrowser for help on using the repository browser.