#!/bin/sh
# autopkgtest check: run a class of apfloat-samples.jar to compute digits of
# Pi. We do not need to build anything on user's machine.
# (C) 2020 Pierre Gruet
# Author: Pierre Gruet <pgt@debian.org>

set -e

SOURCEDIR=$(pwd)
WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR

# Create a file with the first 100 digits of Pi.
cat <<EOF > Pi100
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
EOF

# Getting the 100 first digits using apfloat, with 100 digits and
# Chudnovskys' binsplit then Gauss-Legendre methods, with radix 10.
java -cp /usr/share/java/apfloat-samples.jar org.apfloat.samples.Pi 100 0 10 2>&1 \
        | tail -n 2 | head -n 1 > outPiChudnovsky
        
java -cp /usr/share/java/apfloat-samples.jar org.apfloat.samples.Pi 100 2 10 2>&1 \
        | tail -n 2 | head -n 1 > outPiGaussLegendre
        
diff Pi100 outPiChudnovsky

if [ $? -ne 0 ]; then
  exit 1
fi

diff Pi100 outPiGaussLegendre

if [ $? -ne 0 ]; then
  exit 1
fi

