1#!/bin/bash
2##
3## Name:     test.sh
4## Purpose:  Run test suites for IMath library.
5##
6## Copyright (C) 2002-2007 Michael J. Fromberger. All Rights Reserved.
7##
8
9set -o pipefail
10
11if [ ! -f ../imtest ] ; then
12  echo "I can't find the imath test driver 'imtest', did you build it?"
13  echo "I can't proceed with the unit tests until you do so, sorry."
14  exit 2
15fi
16
17echo "-- Running all available unit tests"
18if ../imtest *.tc | (grep -v 'OK'||true) ; then
19    echo "ALL PASSED"
20else
21    echo "FAILED"
22    exit 1
23fi
24
25echo ""
26echo "-- Running test to compute 1024 decimal digits of pi"
27if [ ! -f ../pi ] ; then
28  echo "I can't find the pi computing program, did you build it?"
29  echo "I can't proceed with the pi test until you do so, sorry."
30  exit 1
31fi
32
33tempfile="/tmp/pi.1024.$$"
34
35../pi 1024 | tr -d '\r\n' > ${tempfile}
36if cmp -s ${tempfile} ./pi1024.txt ; then
37  echo "  PASSED 1024 digits"
38else
39  echo "  FAILED"
40  echo "Obtained:"
41  cat ${tempfile}
42  echo "Expected:"
43  cat ./pi1024.txt
44fi
45rm -f ${tempfile}
46
47tempfile="/tmp/pi.1698.$$"
48
49echo "-- Running test to compute 1698 hexadecimal digits of pi"
50
51../pi 1698 16 | tr -d '\r\n' > ${tempfile}
52if cmp -s ${tempfile} ./pi1698-16.txt ; then
53  echo "  PASSED 1698 digits"
54else
55  echo "  FAILED"
56  echo "Obtained:"
57  cat ${tempfile}
58  echo "Expected:"
59  cat ./pi1698-16.txt
60fi
61rm -f ${tempfile}
62
63tempfile="/tmp/pi.1500.$$"
64
65echo "-- Running test to compute 1500 decimal digits of pi"
66
67../pi 1500 10 | tr -d '\r\n' > ${tempfile}
68if cmp -s ${tempfile} ./pi1500-10.txt ; then
69  echo "  PASSED 1500 digits"
70else
71  echo "  FAILED"
72  echo "Obtained:"
73  cat ${tempfile}
74  echo "Expected:"
75  cat ./pi1500-10.txt
76fi
77rm -f ${tempfile}
78
79echo "-- Running regression tests"
80
81for bug in bug-swap ; do
82    ../${bug}
83done
84
85exit 0
86