#!/bin/bash

failed=False

for i in $(seq 10)
do
    echo Iteration $i
    numbers=$((($RANDOM%10000+1) * ($RANDOM%10000+1)))
    echo Generating $numbers numbers
    ../../lcgrng/trunk/lcgrng.py --numbers $numbers --range $RANDOM | sed -e 's/^/start /' -e 's/$/ end/' > input
    length=$(ls -l input | awk ' { print $5 }')
    echo Length is'  '$length
    ls -lh input
    echo Starting gprog copy
    ./gprog '--quit-when-done' --size-estimate "$length" < input > output

    input_md5=$(md5sum input | awk ' { print $1 }')
    output_md5=$(md5sum output | awk ' { print $1 }')
    if [ "$input_md5" = "$output_md5" ]
    then
        echo "Match!" 1>&2
    else
        echo "Mismatch!" 1>&2
        # we don't wait around to see how many succeeded, because we want the input file and output file, so we can compare them
        exit 1
        failed=True
    fi
    echo
done

if [ "$failed" = "True" ]
then
    echo Failed one or more tests 1>&2
    exit 1
fi

exit 0