#!/bin/sh
#
#	RunTest - test jday and j2d
#
#	Compare $1 with $2 - should be equal
#
CheckDATE() {
	if [ "$1" = "$2" ]; then
		echo "$1 - OK"
	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() {
echo -n "./jday $1 -> "
JD=`./jday $1 | sed -e "s/  *//"`
CheckDATE "$JD" "$2"
}

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

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

TestJ2D "2299160.499988" "1582/10/04 23:59:59"
TestJ2D "2299160.500000" "1582/10/15 00:00:00"
