#! ../src/ngraph -i

STATUS=0
check_val() {
    if [ "$1" = "nan" -o  "$1" = "undefined" ]
    then
	echo $1
    else
	get text -field printf:"%.13E $1"
    fi
}

set +e

new text
new io

while [ -n "$1" ]
do
    io::open "$1"

    while l=`get io -field gets`
    do
	eqn=${l%#*}
	val=`check_val ${l##*#}`

	RESULT=`dexpr "$eqn"`
	RESULT=`check_val $RESULT`

	if [ "$RESULT" != "$val" ]
	then
	    echo
	    echo error "$eqn"
	    echo '    expected:' "$val"
	    echo '      result:' "$RESULT"
	    echo '  difference:' `dexpr $RESULT-$val`
	    STATUS=1
	else
	    echo "OK. ($eqn)"
	fi
    done

    io::close
    shift
done

exit $STATUS
