#!/bin/bash
Fail()
{
    echo "FATAL($0): $1"
    exit 1
}

TestDemo()
{
    echo "Testing Kotlin demo: $1"
    ./rundemo $* > test/$1.txt || Fail "Error running demo: $1"
    diff {correct,test}/$1.txt || Fail "Incorrect output: $1"
}

echo "Kotlin demos: starting"
rm -rf build test
mkdir -p test
./gradlew jar || Fail "Error building Kotlin demo application."

TestDemo solar_time +38.88 -77.03 2023-02-12T17:00:00Z
TestDemo constellation 2021-06-01T00:00:00Z
TestDemo jupiter_moons 2021-04-16T00:26:18Z
TestDemo lunar_eclipse 1988-01-01T00:00:00Z
TestDemo moonphase 2019-06-15T09:15:32.987Z
TestDemo positions +45.6 -90.7 2018-11-30T17:55:07.234Z
TestDemo riseset +45.6 -90.7 2018-11-30T17:55:07.234Z
TestDemo seasons 2019

echo "Kotlin demos: PASS"
exit 0
