mirror of
https://github.com/cosinekitty/astronomy.git
synced 2026-05-19 14:27:52 -04:00
Refactored demo tests.
I refactored the unit tests for all the demo programs to follow a different pattern that makes it simpler to add more demo tests in the future. The main thing is that correct output and generated output are now in separate directories `correct` and `test`. I have moved the test scripts from `test/test` to `./demotest` in all the langauge demo directories. This makes it simpler to clean up any stale generated files before each test run by `rm -f test/*.txt`. I stumbled across this while making the Java demo tests, and it was a better solution, so now all the other languages are consistent with the Java demo tests. In the C demo tests, I also decided to compile all the binary executables into a subdirectory `bin` that can be cleaned out before each run, to make sure there are no stale executables from an earlier run.
This commit is contained in:
@@ -1,73 +1,74 @@
|
||||
#!/bin/bash
|
||||
Fail()
|
||||
{
|
||||
echo "FATAL(demo/python/test/test): $1"
|
||||
echo "FATAL(demo/python/demotest): $1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
rm -f test/{jupiter_moons,camera,constellation,moonphase,positions,riseset,seasons,culminate,horizon,lunar_eclipse,lunar_angles,galactic,triangulate,gravity,stars_near_moon}.txt
|
||||
rm -f test/*.txt
|
||||
mkdir -p test
|
||||
|
||||
echo "Testing example: jupiter_moons.py"
|
||||
./jupiter_moons.py 2021-04-16T00:26:18Z > test/jupiter_moons.txt || Fail "Error testing jupiter_moons.py."
|
||||
diff test/jupiter_moons.txt test/jupiter_moons_correct.txt || Fail "Error comparing jupiter_moons.py output."
|
||||
diff {correct,test}/jupiter_moons.txt || Fail "Error comparing jupiter_moons.py output."
|
||||
|
||||
echo "Testing example: camera.py"
|
||||
./camera.py 29 -81 2021-03-22T02:45:00Z > test/camera.txt || Fail "Error testing camera.py."
|
||||
diff test/camera.txt test/camera_correct.txt || Fail "Error comparing camera.py output."
|
||||
diff {correct,test}/camera.txt || Fail "Error comparing camera.py output."
|
||||
|
||||
echo "Testing example: constellation.py"
|
||||
./constellation.py 2021-06-01T00:00:00Z > test/constellation.txt || Fail "Error testing constellation.py."
|
||||
diff test/constellation.txt test/constellation_correct.txt || Fail "Error comparing constellation.py output."
|
||||
diff {correct,test}/constellation.txt || Fail "Error comparing constellation.py output."
|
||||
|
||||
echo "Testing example: moonphase.py"
|
||||
./moonphase.py 2019-06-15T09:15:32.987Z > test/moonphase.txt || Fail "Error running moonphase.py."
|
||||
diff test/moonphase.txt test/moonphase_correct.txt || Fail "Error comparing moonphase.py output."
|
||||
diff {correct,test}/moonphase.txt || Fail "Error comparing moonphase.py output."
|
||||
|
||||
echo "Testing example: riseset.py"
|
||||
./riseset.py +45.6 -90.7 2018-11-30T17:55:07.234Z > test/riseset.txt || Fail "Error running riseset.py."
|
||||
diff test/riseset.txt test/riseset_correct.txt || Fail "Error comparing riseset.py output."
|
||||
diff {correct,test}/riseset.txt || Fail "Error comparing riseset.py output."
|
||||
|
||||
echo "Testing example: positions.py"
|
||||
./positions.py +45.6 -90.7 2018-11-30T17:55:07.234Z > test/positions.txt || Fail "Error running positions.py."
|
||||
diff test/positions.txt test/positions_correct.txt || Fail "Error comparing positions.py output."
|
||||
diff {correct,test}/positions.txt || Fail "Error comparing positions.py output."
|
||||
|
||||
echo "Testing example: seasons.py"
|
||||
./seasons.py 2019 > test/seasons.txt || Fail "Error running seasons.py."
|
||||
diff test/seasons.txt test/seasons_correct.txt || Fail "Error comparing seasons.py output."
|
||||
diff {correct,test}/seasons.txt || Fail "Error comparing seasons.py output."
|
||||
|
||||
echo "Testing example: culminate.py"
|
||||
./culminate.py +30 -90 2015-02-28T00:00:00Z > test/culminate.txt || Fail "Error running culminate.py."
|
||||
diff test/culminate.txt test/culminate_correct.txt || Fail "Error comparing culminate.py output."
|
||||
diff {correct,test}/culminate.txt || Fail "Error comparing culminate.py output."
|
||||
|
||||
echo "Testing example: horizon.py"
|
||||
./horizon.py +25.5 -85.3 2016-12-25T12:30:45Z > test/horizon.txt || Fail "Error running horizon.py."
|
||||
diff test/horizon.txt test/horizon_correct.txt || Fail "Error comparing horizon.py output."
|
||||
diff {correct,test}/horizon.txt || Fail "Error comparing horizon.py output."
|
||||
|
||||
echo "Testing example: lunar_eclipse.py"
|
||||
./lunar_eclipse.py 1988-01-01 > test/lunar_eclipse.txt || Fail "Error running lunar_eclipse.py."
|
||||
diff test/lunar_eclipse.txt test/lunar_eclipse_correct.txt || Fail "Error comparing lunar_eclipse.py output."
|
||||
diff {correct,test}/lunar_eclipse.txt || Fail "Error comparing lunar_eclipse.py output."
|
||||
|
||||
echo "Testing example: lunar_angles.py"
|
||||
./lunar_angles.py 2021-05-15 > test/lunar_angles.txt || Fail "Error running lunar_angles.py."
|
||||
diff test/lunar_angles.txt test/lunar_angles_correct.txt || Fail "Error comparing lunar_angles.py output."
|
||||
diff {correct,test}/lunar_angles.txt || Fail "Error comparing lunar_angles.py output."
|
||||
|
||||
echo "Testing example: galactic.py"
|
||||
./galactic.py 38.92056 -77.0658 22.793498 197.070510 2025-04-06T00:00:00Z > test/galactic.txt || Fail "Error running galactic.py."
|
||||
diff test/galactic.txt test/galactic_correct.txt || Fail "Error comparing galactic.py output."
|
||||
diff {correct,test}/galactic.txt || Fail "Error comparing galactic.py output."
|
||||
|
||||
echo "Testing example: triangulate.py"
|
||||
./triangulate.py 48.16042 24.49986 2019 18 7 48.27305 24.36401 662 83 12 > test/triangulate.txt || Fail "Error running triangulate.py."
|
||||
diff test/triangulate.txt test/triangulate_correct.txt || Fail "Error comparing triangulate.py output."
|
||||
diff {correct,test}/triangulate.txt || Fail "Error comparing triangulate.py output."
|
||||
|
||||
echo "Testing example: gravity.py"
|
||||
for latitude in {0..90}; do
|
||||
./gravity.py ${latitude} 0 >> test/gravity.txt || Fail "Error running gravity.py."
|
||||
done
|
||||
diff test/gravity.txt test/gravity_correct.txt || Fail "Error comparing gravity.py output."
|
||||
diff {correct,test}/gravity.txt || Fail "Error comparing gravity.py output."
|
||||
|
||||
echo "Testing example: stars_near_moon.py"
|
||||
./stars_near_moon.py 30 -80 2021-11-08T23:00:00Z >> test/stars_near_moon.txt || Fail "Error running stars_near_moon.py"
|
||||
diff test/stars_near_moon.txt test/stars_near_moon_correct.txt || Fail "Error comparing stars_near_moon output."
|
||||
./stars_near_moon.py 30 -80 2021-11-08T23:00:00Z > test/stars_near_moon.txt || Fail "Error running stars_near_moon.py"
|
||||
diff {correct,test}/stars_near_moon.txt || Fail "Error comparing stars_near_moon output."
|
||||
|
||||
echo "PASS: Python examples"
|
||||
exit 0
|
||||
Reference in New Issue
Block a user