#!/bin/sh
#	$Id: RunTest,v 1.9 2005/10/06 22:30:13 hiram Exp $
#
#	RunTest - test jday and j2d
#
#	Compare $1 with $2 - should be equal
#
CheckDATE() {
	PF=0
	if [ "$1" = "$2" ]; then
		echo "$1 - OK"
		PF=1
	else
		echo "$1 - FAIL  ****************************"
	fi
}
#
#	Test one julian date, $1 is the "yyyy mm dd hh mm ss" string to test
#	and $2 is the expected result
#
TestJD() {
TestCount=`expr ${TestCount} + 1`
echo -n "./jday $1 -> "
JD=`./jday $1 | sed -e "s/  *//"`
CheckDATE "$JD" "$2"
TestSuccess=`expr ${TestSuccess} + ${PF}`
}

V1OUT=""
export V1OUT

#
#	Test one julian date, $1 is the "yyyy mm dd hh mm ss" string to test
#	and $2 is the expected result
#
TestJ2D() {
TestCount=`expr ${TestCount} + 1`
echo -n "./j2d ${V1OUT} $1 -> "
J2D=`./j2d ${V1OUT} $1`
CheckDATE "$J2D" "$2"
TestSuccess=`expr ${TestSuccess} + ${PF}`
}

TestCount=0
export TestCount
TestSuccess=0
export TestSuccess
PF=0
export PF

TestJD "-4712 1 1 12 0 0" "0.000000"
TestJD  "-d -4712-01-01 12:00:00" "0.000000"
TestJ2D "0.000000" "-4712-01-01 12:00:00"

TestJD "-1 12 31 12 0 0" "1721057.000000"
TestJD "-d -1-12-31 12:00:00" "1721057.000000"
TestJ2D "1721057.000000" "-1-12-31 12:00:00"

TestJD "0 1 1 12 0 0" "1721058.000000"
TestJ2D "1721058.000000" "0-01-01 12:00:00"

TestJD "0 2 29 12 0 0" "1721117.000000"
TestJ2D "1721117.000000" "0-02-29 12:00:00"

TestJD "0 3 1 12 0 0" "1721118.000000"
TestJ2D "1721118.000000" "0-03-01 12:00:00"

TestJD "0 12 31 12 0 0" "1721423.000000"
TestJ2D "1721423.000000" "0-12-31 12:00:00"

TestJD "1 1 1 12 0 0" "1721424.000000"
TestJ2D "1721424.000000" "1-01-01 12:00:00"

TestJD "1970 1 1 0 0 0" "2440587.500000"
TestJ2D "2440587.500000" "1970-01-01 00:00:00"

TestJD "-d 2000-08-18 05:25:27" "2451774.726007"
TestJ2D "2451774.726007" "2000-08-18 05:25:27"

TestJD "-d 1582-10-04 23:59:59" "2299160.499988"
TestJD "-d 1582-10-15 00:00:00" "2299160.500000"

#  echo "The following test used to demonstrate a bug in the rounding
#  of the seconds.  It no longer fails.  2002-11-11

V1OUT=""
TestJ2D "2299160.499988" "1582-10-04 23:59:59"
TestJ2D "2299160.500000" "1582-10-15 00:00:00"
V1OUT="-v1"
TestJ2D "2299160.499988" "1582/10/04 23:59:59"
TestJ2D "2299160.500000" "1582/10/15 00:00:00"

TestFail=`expr ${TestCount} - ${TestSuccess}`

echo "TEST COMPLETE: Test count: $TestCount, Test success: $TestSuccess, Test failed: $TestFail"

if [ 0 -eq ${TestFail} ]; then
	echo "OK - ALL TESTS PASSED OK"
	exit 0
else
	echo "ERROR:  There are test failures.  Please investigate"
	exit 255
fi


syntax highlighted by Code2HTML, v. 0.9.1