#!/bin/sh
# autopkgtest check: run simple example in the tutorial on the website. This
# works by writing a Java program and putting apfloat.jar in the classpath.
# (C) 2002-2019 Mikko Tommila
#     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 the square root of 2.
cat <<EOF > Rac2_100
1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641572
EOF

# Create the Java code that will run. 
cat <<EOF > Test.java
import org.apfloat.Apfloat;
import org.apfloat.ApfloatMath;

public class Test
{
    public static void main(String[] args)
    {
        Apfloat x = new Apfloat(2, 100);
        System.out.println(ApfloatMath.sqrt(x));
    }
}
EOF

#Building and running.
export CLASSPATH=".:/usr/share/java/apfloat.jar"
javac Test.java
java Test > outRac2

diff Rac2_100 outRac2

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

