#!/bin/sh
#
# doTest
# Copyright (C) 1997 Norio Katayama
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# 10/15/96 katayama@rd.nacsis.ac.jp
# $Id: doTest,v 1.1.1.1 1998/08/28 11:28:16 katayama Exp $
#

createSRTree=../c-samples/createSRTree
searchSRTree=../c-samples/searchSRTree
storeSRTree=../c-samples/storeSRTree
removeSRTree=../c-samples/removeSRTree
checkSRTree=../c-samples/checkSRTree
printSRTree=../c-samples/printSRTree

echo "Creating SR-tree for 1000 points ... "
$createSRTree 16 sample.db test.dat > create.log
if [ $? != 0 ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Checking created SR-tree ... "
$checkSRTree test.dat
if [ $? != 0 ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Verifying created SR-tree ... "
$searchSRTree -v 16 sample.db test.dat > search.log
if [ $? != 0 ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Removing all points from SR-tree ... "
$removeSRTree 16 sample.db test.dat > remove.log
if [ $? != 0 ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Checking modified SR-tree ... "
$checkSRTree test.dat
if [ $? != 0 ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Verifying modified SR-tree ... "
res=`$printSRTree test.dat | grep 'Number of leaf points: 0'`
if [ "$res" = "" ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Restoring 1000 points to SR-tree ... "
$storeSRTree 16 sample.db test.dat > store.log
if [ $? != 0 ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Checking restored SR-tree ... "
$checkSRTree test.dat
if [ $? != 0 ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Verifying restored SR-tree ... "
$searchSRTree -v 16 sample.db test.dat > search.log
if [ $? != 0 ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Running nearest neighbor searches ... "
$searchSRTree -v -n 4 16 sample.db test.dat > search.log
if [ $? != 0 ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Verifying the result of the nearest neighbor searches ... "
sed -e '/^Searching/d' -e 's/:.*$//' < search.log > neighbor.log
cmp neighbor.log neighbor.db
if [ $? != 0 ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Running range searches ... "
$searchSRTree -v -w 0.1 16 sample.db test.dat > search.log
if [ $? != 0 ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Verifying the result of the range searches ... "
sed -e '/^Searching/d' < search.log > range.log
cmp range.log range.db
if [ $? != 0 ]; then
	echo "******** Test failed. ********"
	exit 1
fi
echo "done"

echo "Congratulations! All tests succeeded."
