From efc59ae6fcc6fc81ca62c0bf7ddfb45f9d9b6fbd Mon Sep 17 00:00:00 2001 From: Don Cross Date: Sat, 30 Apr 2022 21:01:11 -0400 Subject: [PATCH] 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. --- demo/c/build | 4 +- .../camera_correct.txt => correct/camera.txt} | 0 .../culminate.txt} | 0 .../galactic.txt} | 0 .../gravity.txt} | 0 .../horizon.txt} | 0 .../lunar_eclipse.txt} | 0 .../moonphase.txt} | 0 .../positions.txt} | 0 .../positions2.txt} | 0 .../riseset.txt} | 0 .../seasons.txt} | 0 .../triangulate.txt} | 0 .../worldmap.txt} | 0 demo/c/demotest | 70 +++++++++++++++++++ demo/c/lrbuild | 4 +- demo/c/raytrace/build | 2 + demo/c/run_worldmap | 8 ++- demo/c/test/test | 70 ------------------- .../camera_correct.txt => correct/camera.txt} | 0 .../culminate.txt} | 0 .../gravity.txt} | 0 .../horizon.txt} | 0 .../lunar_eclipse.txt} | 0 .../moonphase.txt} | 0 .../positions.txt} | 0 .../riseset.txt} | 0 .../seasons.txt} | 0 .../triangulate.txt} | 0 demo/csharp/{test/test => demotest} | 25 +++---- .../calendar.txt} | 0 demo/nodejs/calendar/package.json | 2 +- demo/nodejs/calendar/run | 1 + .../camera_correct.txt => correct/camera.txt} | 0 .../culminate.txt} | 0 .../equator_of_date.txt} | 0 .../equatorial.txt} | 0 .../gravity.txt} | 0 .../horizon.txt} | 0 .../lunar_eclipse.txt} | 0 .../moonphase.txt} | 0 .../positions.txt} | 0 .../riseset.txt} | 0 .../seasons.txt} | 0 .../triangulate.txt} | 0 demo/nodejs/{test/test => demotest} | 29 ++++---- .../camera_correct.txt => correct/camera.txt} | 0 .../constellation.txt} | 0 .../culminate.txt} | 0 .../galactic.txt} | 0 .../gravity.txt} | 0 .../horizon.txt} | 0 .../jupiter_moons.txt} | 0 .../lunar_angles.txt} | 0 .../lunar_eclipse.txt} | 0 .../moonphase.txt} | 0 .../positions.txt} | 0 .../riseset.txt} | 0 .../seasons.txt} | 0 .../stars_near_moon.txt} | 0 .../triangulate.txt} | 0 demo/python/{test/test => demotest} | 37 +++++----- generate/run | 8 +-- 63 files changed, 136 insertions(+), 124 deletions(-) rename demo/c/{test/camera_correct.txt => correct/camera.txt} (100%) rename demo/c/{test/culminate_correct.txt => correct/culminate.txt} (100%) rename demo/c/{test/galactic_correct.txt => correct/galactic.txt} (100%) rename demo/c/{test/gravity_correct.txt => correct/gravity.txt} (100%) rename demo/c/{test/horizon_correct.txt => correct/horizon.txt} (100%) rename demo/c/{test/lunar_eclipse_correct.txt => correct/lunar_eclipse.txt} (100%) rename demo/c/{test/moonphase_correct.txt => correct/moonphase.txt} (100%) rename demo/c/{test/positions_correct.txt => correct/positions.txt} (100%) rename demo/c/{test/positions2_correct.txt => correct/positions2.txt} (100%) rename demo/c/{test/riseset_correct.txt => correct/riseset.txt} (100%) rename demo/c/{test/seasons_correct.txt => correct/seasons.txt} (100%) rename demo/c/{test/triangulate_correct.txt => correct/triangulate.txt} (100%) rename demo/c/{test/worldmap_correct.txt => correct/worldmap.txt} (100%) create mode 100755 demo/c/demotest delete mode 100755 demo/c/test/test rename demo/csharp/{test/camera_correct.txt => correct/camera.txt} (100%) rename demo/csharp/{test/culminate_correct.txt => correct/culminate.txt} (100%) rename demo/csharp/{test/gravity_correct.txt => correct/gravity.txt} (100%) rename demo/csharp/{test/horizon_correct.txt => correct/horizon.txt} (100%) rename demo/csharp/{test/lunar_eclipse_correct.txt => correct/lunar_eclipse.txt} (100%) rename demo/csharp/{test/moonphase_correct.txt => correct/moonphase.txt} (100%) rename demo/csharp/{test/positions_correct.txt => correct/positions.txt} (100%) rename demo/csharp/{test/riseset_correct.txt => correct/riseset.txt} (100%) rename demo/csharp/{test/seasons_correct.txt => correct/seasons.txt} (100%) rename demo/csharp/{test/triangulate_correct.txt => correct/triangulate.txt} (100%) rename demo/csharp/{test/test => demotest} (58%) rename demo/nodejs/calendar/{test/calendar_correct.txt => correct/calendar.txt} (100%) rename demo/nodejs/{test/camera_correct.txt => correct/camera.txt} (100%) rename demo/nodejs/{test/culminate_correct.txt => correct/culminate.txt} (100%) rename demo/nodejs/{test/equator_of_date_correct.txt => correct/equator_of_date.txt} (100%) rename demo/nodejs/{test/equatorial_correct.txt => correct/equatorial.txt} (100%) rename demo/nodejs/{test/gravity_correct.txt => correct/gravity.txt} (100%) rename demo/nodejs/{test/horizon_correct.txt => correct/horizon.txt} (100%) rename demo/nodejs/{test/lunar_eclipse_correct.txt => correct/lunar_eclipse.txt} (100%) rename demo/nodejs/{test/moonphase_correct.txt => correct/moonphase.txt} (100%) rename demo/nodejs/{test/positions_correct.txt => correct/positions.txt} (100%) rename demo/nodejs/{test/riseset_correct.txt => correct/riseset.txt} (100%) rename demo/nodejs/{test/seasons_correct.txt => correct/seasons.txt} (100%) rename demo/nodejs/{test/triangulate_correct.txt => correct/triangulate.txt} (100%) rename demo/nodejs/{test/test => demotest} (58%) rename demo/python/{test/camera_correct.txt => correct/camera.txt} (100%) rename demo/python/{test/constellation_correct.txt => correct/constellation.txt} (100%) rename demo/python/{test/culminate_correct.txt => correct/culminate.txt} (100%) rename demo/python/{test/galactic_correct.txt => correct/galactic.txt} (100%) rename demo/python/{test/gravity_correct.txt => correct/gravity.txt} (100%) rename demo/python/{test/horizon_correct.txt => correct/horizon.txt} (100%) rename demo/python/{test/jupiter_moons_correct.txt => correct/jupiter_moons.txt} (100%) rename demo/python/{test/lunar_angles_correct.txt => correct/lunar_angles.txt} (100%) rename demo/python/{test/lunar_eclipse_correct.txt => correct/lunar_eclipse.txt} (100%) rename demo/python/{test/moonphase_correct.txt => correct/moonphase.txt} (100%) rename demo/python/{test/positions_correct.txt => correct/positions.txt} (100%) rename demo/python/{test/riseset_correct.txt => correct/riseset.txt} (100%) rename demo/python/{test/seasons_correct.txt => correct/seasons.txt} (100%) rename demo/python/{test/stars_near_moon_correct.txt => correct/stars_near_moon.txt} (100%) rename demo/python/{test/triangulate_correct.txt => correct/triangulate.txt} (100%) rename demo/python/{test/test => demotest} (53%) diff --git a/demo/c/build b/demo/c/build index 14f7af0d..37b10b76 100755 --- a/demo/c/build +++ b/demo/c/build @@ -13,9 +13,11 @@ else Fail "unrecognized command line option" fi +mkdir -p bin for name in gravity galactic camera moonphase positions linux_riseset riseset seasons culminate horizon lunar_eclipse triangulate; do + rm -f bin/${name} echo "Compiling ${name}.c" - gcc ${BUILDOPT} -Wall -Werror -o ${name} -I../../source/c ../../source/c/astronomy.c astro_demo_common.c ${name}.c -lm || + gcc ${BUILDOPT} -Wall -Werror -o bin/${name} -I../../source/c ../../source/c/astronomy.c astro_demo_common.c ${name}.c -lm || Fail "Error building ${name}.c" done diff --git a/demo/c/test/camera_correct.txt b/demo/c/correct/camera.txt similarity index 100% rename from demo/c/test/camera_correct.txt rename to demo/c/correct/camera.txt diff --git a/demo/c/test/culminate_correct.txt b/demo/c/correct/culminate.txt similarity index 100% rename from demo/c/test/culminate_correct.txt rename to demo/c/correct/culminate.txt diff --git a/demo/c/test/galactic_correct.txt b/demo/c/correct/galactic.txt similarity index 100% rename from demo/c/test/galactic_correct.txt rename to demo/c/correct/galactic.txt diff --git a/demo/c/test/gravity_correct.txt b/demo/c/correct/gravity.txt similarity index 100% rename from demo/c/test/gravity_correct.txt rename to demo/c/correct/gravity.txt diff --git a/demo/c/test/horizon_correct.txt b/demo/c/correct/horizon.txt similarity index 100% rename from demo/c/test/horizon_correct.txt rename to demo/c/correct/horizon.txt diff --git a/demo/c/test/lunar_eclipse_correct.txt b/demo/c/correct/lunar_eclipse.txt similarity index 100% rename from demo/c/test/lunar_eclipse_correct.txt rename to demo/c/correct/lunar_eclipse.txt diff --git a/demo/c/test/moonphase_correct.txt b/demo/c/correct/moonphase.txt similarity index 100% rename from demo/c/test/moonphase_correct.txt rename to demo/c/correct/moonphase.txt diff --git a/demo/c/test/positions_correct.txt b/demo/c/correct/positions.txt similarity index 100% rename from demo/c/test/positions_correct.txt rename to demo/c/correct/positions.txt diff --git a/demo/c/test/positions2_correct.txt b/demo/c/correct/positions2.txt similarity index 100% rename from demo/c/test/positions2_correct.txt rename to demo/c/correct/positions2.txt diff --git a/demo/c/test/riseset_correct.txt b/demo/c/correct/riseset.txt similarity index 100% rename from demo/c/test/riseset_correct.txt rename to demo/c/correct/riseset.txt diff --git a/demo/c/test/seasons_correct.txt b/demo/c/correct/seasons.txt similarity index 100% rename from demo/c/test/seasons_correct.txt rename to demo/c/correct/seasons.txt diff --git a/demo/c/test/triangulate_correct.txt b/demo/c/correct/triangulate.txt similarity index 100% rename from demo/c/test/triangulate_correct.txt rename to demo/c/correct/triangulate.txt diff --git a/demo/c/test/worldmap_correct.txt b/demo/c/correct/worldmap.txt similarity index 100% rename from demo/c/test/worldmap_correct.txt rename to demo/c/correct/worldmap.txt diff --git a/demo/c/demotest b/demo/c/demotest new file mode 100755 index 00000000..917b9026 --- /dev/null +++ b/demo/c/demotest @@ -0,0 +1,70 @@ +#!/bin/bash +Fail() +{ + echo "FATAL(demo/c/demotest): $1" + exit 1 +} + +rm -f test/*.txt +mkdir -p test +./build || Fail "Error building example programs." + +echo "Testing example: camera.c" +bin/camera 29 -81 2021-03-22T02:45:00Z > test/camera.txt || Fail "Error testing camera.c." +diff {correct,test}/camera.txt || Fail "Error comparing camera.c output." + +echo "Testing example: moonphase.c" +bin/moonphase 2019-06-15T09:15:32.987Z > test/moonphase.txt || Fail "Error testing moonphase.c." +diff {correct,test}/moonphase.txt || Fail "Error comparing moonphase.c output." + +echo "Testing example: positions.c" +bin/positions +45.6 -90.7 2018-11-30T17:55:07.234Z > test/positions.txt || Fail "Error testing positions.c." +diff {correct,test}/positions.txt || Fail "Error comparing positions.c output." + +# Another test to check for a problem I found with putting "60" in the seconds field. +bin/positions 20.8 -75.2 2020-07-09T08:30:00Z > test/positions2.txt || Fail "Error in second call to positions.c." +diff {correct,test}/positions2.txt || Fail "Error comparing positions.c output #2." + +echo "Testing example: riseset.c" +bin/riseset 45 -90 2019-06-14T21:45:25Z > test/riseset.txt || Fail "Error testing riseset.c." +diff {correct,test}/riseset.txt || Fail "Error comparing riseset.c output." + +echo "Testing example: seasons.c" +bin/seasons 2020 > test/seasons.txt || Fail "Error testing seasons.c." +diff {correct,test}/seasons.txt || Fail "Error comparing seasons.c output." + +echo "Testing example: culminate.c" +bin/culminate +30 -90 2015-02-28T00:00:00Z > test/culminate.txt || Fail "Error testing culminate.c." +diff {correct,test}/culminate.txt || Fail "Error comparing culminate.c output." + +echo "Testing example: horizon.c" +bin/horizon +25.5 -85.3 2016-12-25T12:30:45Z > test/horizon.txt || Fail "Error testing horizon.c." +diff {correct,test}/horizon.txt || Fail "Error comparing horizon.c output." + +echo "Testing example: lunar_eclipse.c" +bin/lunar_eclipse 1988-01-01T00:00:00Z > test/lunar_eclipse.txt || Fail "Error running lunar_eclipse.c." +diff {correct,test}/lunar_eclipse.txt || Fail "Error comparing lunar_eclipse.c output." + +echo "Testing example: galactic.c" +bin/galactic 38.92056 -77.0658 22.793498 197.070510 2025-04-06T00:00:00Z > test/galactic.txt || Fail "Error running galactic.c." +diff {correct,test}/galactic.txt || Fail "Error comparing galactic.c output." + +echo "Testing example: triangulate.c" +bin/triangulate 48.16042 24.49986 2019 18 7 48.27305 24.36401 662 83 12 > test/triangulate.txt || Fail "Error running triangulate.c." +diff {correct,test}/triangulate.txt || Fail "Error comparing triangulate.c output." + +echo "Testing example: gravity.c" +for latitude in {0..90}; do + bin/gravity ${latitude} 0 >> test/gravity.txt || Fail "Error running gravity.c." +done +diff {correct,test}/gravity.txt || Fail "Error comparing gravity.c output." + +cd raytrace || Fail "error changing to raytrace directory" +./build || Fail "build raytracer" +./run || Fail "run raytracer" +cd .. + +./run_worldmap || Fail "error in run_worldmap" + +echo "PASS: C examples" +exit 0 diff --git a/demo/c/lrbuild b/demo/c/lrbuild index ebdd9249..8e5e9fce 100755 --- a/demo/c/lrbuild +++ b/demo/c/lrbuild @@ -13,9 +13,11 @@ else Fail "unrecognized command line option" fi +mkdir -p bin for name in linux_riseset ; do + rm -r bin/${name} echo "Compiling ${name}.c" - gcc ${BUILDOPT} -Wall -Werror -o ${name} -I../../source/c ../../source/c/astronomy.c astro_demo_common.c ${name}.c -lm || + gcc ${BUILDOPT} -Wall -Werror -o bin/${name} -I../../source/c ../../source/c/astronomy.c astro_demo_common.c ${name}.c -lm || Fail "Error building ${name}.c" done diff --git a/demo/c/raytrace/build b/demo/c/raytrace/build index cbec2482..c703fa9f 100755 --- a/demo/c/raytrace/build +++ b/demo/c/raytrace/build @@ -6,6 +6,8 @@ else BUILDOPT='-O3' fi +rm -f raytrace + g++ -Wall -Werror -x c++ -std=c++11 -o raytrace $BUILDOPT \ -I.. -I../../../source/c \ *.cpp ../astro_demo_common.c ../../../source/c/astronomy.c diff --git a/demo/c/run_worldmap b/demo/c/run_worldmap index 16ab2ecf..a180fb18 100755 --- a/demo/c/run_worldmap +++ b/demo/c/run_worldmap @@ -8,7 +8,9 @@ fi echo "run_worldmap: building C++ code" -g++ -Wall -Werror -x c++ -std=c++11 -o worldmap $BUILDOPT \ +rm -f bin/worldmap +mkdir -p bin +g++ -Wall -Werror -x c++ -std=c++11 -o bin/worldmap $BUILDOPT \ -I./raytrace -I../../source/c \ worldmap.cpp astro_demo_common.c ../../source/c/astronomy.c raytrace/lodepng.cpp \ || exit $? @@ -16,9 +18,9 @@ g++ -Wall -Werror -x c++ -std=c++11 -o worldmap $BUILDOPT \ echo "run_worldmap: creating image" rm -f sun_moon_map.png test/worldmap.txt -time ./worldmap sun_moon_map.png 2022-04-09T16:05:35Z > test/worldmap.txt || exit $? +time bin/worldmap sun_moon_map.png 2022-04-09T16:05:35Z > test/worldmap.txt || exit $? more test/worldmap.txt || exit $? -if ! diff test/worldmap{,_correct}.txt; then +if ! diff {correct,test}/worldmap.txt; then echo "run_worldmap: FAIL - incorrect zenith location output." exit 1 fi diff --git a/demo/c/test/test b/demo/c/test/test deleted file mode 100755 index fa54681f..00000000 --- a/demo/c/test/test +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash -Fail() -{ - echo "FATAL(demo/c/test/test): $1" - exit 1 -} - -rm -f camera moonphase positions riseset seasons culminate horizon lunar_eclipse galactic triangulate gravity -rm -f test/{camera,moonphase,positions,positions2,riseset,seasons,culminate,horizon,lunar_eclipse,galactic,triangulate,gravity}.txt -./build || Fail "Error building example programs." - -echo "Testing example: camera.c" -./camera 29 -81 2021-03-22T02:45:00Z > test/camera.txt || Fail "Error testing camera.c." -diff test/camera.txt test/camera_correct.txt || Fail "Error comparing camera.c output." - -echo "Testing example: moonphase.c" -./moonphase 2019-06-15T09:15:32.987Z > test/moonphase.txt || Fail "Error testing moonphase.c." -diff test/moonphase.txt test/moonphase_correct.txt || Fail "Error comparing moonphase.c output." - -echo "Testing example: positions.c" -./positions +45.6 -90.7 2018-11-30T17:55:07.234Z > test/positions.txt || Fail "Error testing positions.c." -diff test/positions.txt test/positions_correct.txt || Fail "Error comparing positions.c output." - -# Another test to check for a problem I found with putting "60" in the seconds field. -./positions 20.8 -75.2 2020-07-09T08:30:00Z > test/positions2.txt || Fail "Error in second call to positions.c." -diff test/positions2.txt test/positions2_correct.txt || Fail "Error comparing positions.c output #2." - -echo "Testing example: riseset.c" -./riseset 45 -90 2019-06-14T21:45:25Z > test/riseset.txt || Fail "Error testing riseset.c." -diff test/riseset.txt test/riseset_correct.txt || Fail "Error comparing riseset.c output." - -echo "Testing example: seasons.c" -./seasons 2020 > test/seasons.txt || Fail "Error testing seasons.c." -diff test/seasons.txt test/seasons_correct.txt || Fail "Error comparing seasons.c output." - -echo "Testing example: culminate.c" -./culminate +30 -90 2015-02-28T00:00:00Z > test/culminate.txt || Fail "Error testing culminate.c." -diff test/culminate.txt test/culminate_correct.txt || Fail "Error comparing culminate.c output." - -echo "Testing example: horizon.c" -./horizon +25.5 -85.3 2016-12-25T12:30:45Z > test/horizon.txt || Fail "Error testing horizon.c." -diff test/horizon.txt test/horizon_correct.txt || Fail "Error comparing horizon.c output." - -echo "Testing example: lunar_eclipse.c" -./lunar_eclipse 1988-01-01T00:00:00Z > test/lunar_eclipse.txt || Fail "Error running lunar_eclipse.c." -diff test/lunar_eclipse.txt test/lunar_eclipse_correct.txt || Fail "Error comparing lunar_eclipse.c output." - -echo "Testing example: galactic.c" -./galactic 38.92056 -77.0658 22.793498 197.070510 2025-04-06T00:00:00Z > test/galactic.txt || Fail "Error running galactic.c." -diff test/galactic.txt test/galactic_correct.txt || Fail "Error comparing galactic.c output." - -echo "Testing example: triangulate.c" -./triangulate 48.16042 24.49986 2019 18 7 48.27305 24.36401 662 83 12 > test/triangulate.txt || Fail "Error running triangulate.c." -diff test/triangulate.txt test/triangulate_correct.txt || Fail "Error comparing triangulate.c output." - -echo "Testing example: gravity.c" -for latitude in {0..90}; do - ./gravity ${latitude} 0 >> test/gravity.txt || Fail "Error running gravity.c." -done -diff test/gravity.txt test/gravity_correct.txt || Fail "Error comparing gravity.c output." - -cd raytrace || Fail "error changing to raytrace directory" -./build || Fail "build raytracer" -./run || Fail "run raytracer" -cd .. - -./run_worldmap || Fail "error in run_worldmap" - -echo "PASS: C examples" -exit 0 diff --git a/demo/csharp/test/camera_correct.txt b/demo/csharp/correct/camera.txt similarity index 100% rename from demo/csharp/test/camera_correct.txt rename to demo/csharp/correct/camera.txt diff --git a/demo/csharp/test/culminate_correct.txt b/demo/csharp/correct/culminate.txt similarity index 100% rename from demo/csharp/test/culminate_correct.txt rename to demo/csharp/correct/culminate.txt diff --git a/demo/csharp/test/gravity_correct.txt b/demo/csharp/correct/gravity.txt similarity index 100% rename from demo/csharp/test/gravity_correct.txt rename to demo/csharp/correct/gravity.txt diff --git a/demo/csharp/test/horizon_correct.txt b/demo/csharp/correct/horizon.txt similarity index 100% rename from demo/csharp/test/horizon_correct.txt rename to demo/csharp/correct/horizon.txt diff --git a/demo/csharp/test/lunar_eclipse_correct.txt b/demo/csharp/correct/lunar_eclipse.txt similarity index 100% rename from demo/csharp/test/lunar_eclipse_correct.txt rename to demo/csharp/correct/lunar_eclipse.txt diff --git a/demo/csharp/test/moonphase_correct.txt b/demo/csharp/correct/moonphase.txt similarity index 100% rename from demo/csharp/test/moonphase_correct.txt rename to demo/csharp/correct/moonphase.txt diff --git a/demo/csharp/test/positions_correct.txt b/demo/csharp/correct/positions.txt similarity index 100% rename from demo/csharp/test/positions_correct.txt rename to demo/csharp/correct/positions.txt diff --git a/demo/csharp/test/riseset_correct.txt b/demo/csharp/correct/riseset.txt similarity index 100% rename from demo/csharp/test/riseset_correct.txt rename to demo/csharp/correct/riseset.txt diff --git a/demo/csharp/test/seasons_correct.txt b/demo/csharp/correct/seasons.txt similarity index 100% rename from demo/csharp/test/seasons_correct.txt rename to demo/csharp/correct/seasons.txt diff --git a/demo/csharp/test/triangulate_correct.txt b/demo/csharp/correct/triangulate.txt similarity index 100% rename from demo/csharp/test/triangulate_correct.txt rename to demo/csharp/correct/triangulate.txt diff --git a/demo/csharp/test/test b/demo/csharp/demotest similarity index 58% rename from demo/csharp/test/test rename to demo/csharp/demotest index 4b6c3988..4e05af3a 100755 --- a/demo/csharp/test/test +++ b/demo/csharp/demotest @@ -1,54 +1,55 @@ #!/bin/bash Fail() { - echo "FATAL(demo/csharp/test/test): $1" + echo "FATAL(demo/csharp/demotest): $1" exit 1 } rm -rf exe -rm -f test/{camera,moonphase,positions,riseset,seasons,culminate,horizon,lunar_eclipse,triangulate,gravity}.txt +rm -f test/*.txt +mkdir -p test dotnet build --output ${PWD}/exe || Fail "Error building ${PWD}/demo.sln" echo "Testing example: camera.cs" exe/camera 29 -81 2021-03-22T02:45:00Z > test/camera.txt || Fail "Error testing camera.cs." -diff test/camera.txt test/camera_correct.txt || Fail "Error comparing camera.cs output." +diff {correct,test}/camera.txt || Fail "Error comparing camera.cs output." echo "Testing example: moonphase.cs" exe/moonphase 2019-06-15T09:15:32.987Z > test/moonphase.txt || Fail "Error testing moonphase.cs" -diff test/moonphase.txt test/moonphase_correct.txt || Fail "Error comparing moonphase.cs output." +diff {correct,test}/moonphase.txt || Fail "Error comparing moonphase.cs output." echo "Testing example: positions.cs" exe/positions +45.6 -90.7 2018-11-30T17:55:07.234Z > test/positions.txt || Fail "Error testing positions.cs" -diff test/positions.txt test/positions_correct.txt || Fail "Error comparing positions.cs output." +diff {correct,test}/positions.txt || Fail "Error comparing positions.cs output." echo "Testing example: riseset.cs" exe/riseset 45 -90 2019-06-14T21:45:25Z > test/riseset.txt || Fail "Error testing riseset.cs" -diff test/riseset.txt test/riseset_correct.txt || Fail "Error comparing riseset.cs output." +diff {correct,test}/riseset.txt || Fail "Error comparing riseset.cs output." echo "Testing example: seasons.cs" exe/seasons 2020 > test/seasons.txt || Fail "Error testing seasons.cs" -diff test/seasons.txt test/seasons_correct.txt || Fail "Error comparing seasons.cs output." +diff {correct,test}/seasons.txt || Fail "Error comparing seasons.cs output." echo "Testing example: culminate.cs" exe/culminate +30 -90 2015-02-28T00:00:00Z > test/culminate.txt || Fail "Error testing culminate.cs." -diff test/culminate.txt test/culminate_correct.txt || Fail "Error comparing culminate.cs output." +diff {correct,test}/culminate.txt || Fail "Error comparing culminate.cs output." echo "Testing example: horizon.cs" exe/horizon +25.5 -85.3 2016-12-25T12:30:45Z > test/horizon.txt || Fail "Error testing horizon.cs" -diff test/horizon.txt test/horizon_correct.txt || Fail "Error comparing horizon.cs output." +diff {correct,test}/horizon.txt || Fail "Error comparing horizon.cs output." echo "Testing example: lunar_eclipse.cs" exe/lunar_eclipse 1988-01-01T00:00:00Z > test/lunar_eclipse.txt || Fail "Error running lunar_eclipse.cs." -diff test/lunar_eclipse.txt test/lunar_eclipse_correct.txt || Fail "Error comparing lunar_eclipse.cs output." +diff {correct,test}/lunar_eclipse.txt || Fail "Error comparing lunar_eclipse.cs output." echo "Testing example: triangulate.cs" exe/triangulate 48.16042 24.49986 2019 18 7 48.27305 24.36401 662 83 12 > test/triangulate.txt || Fail "Error running triangulate.cs." -diff test/triangulate.txt test/triangulate_correct.txt || Fail "Error comparing triangulate.cs output." +diff {correct,test}/triangulate.txt || Fail "Error comparing triangulate.cs output." echo "Testing example: gravity.cs" for latitude in {0..90}; do exe/gravity ${latitude} 0 >> test/gravity.txt || Fail "Error running gravity.cs." done -diff test/gravity.txt test/gravity_correct.txt || Fail "Error comparing gravity.cs output." +diff {correct,test}/gravity.txt || Fail "Error comparing gravity.cs output." echo "PASS: C# examples" exit 0 diff --git a/demo/nodejs/calendar/test/calendar_correct.txt b/demo/nodejs/calendar/correct/calendar.txt similarity index 100% rename from demo/nodejs/calendar/test/calendar_correct.txt rename to demo/nodejs/calendar/correct/calendar.txt diff --git a/demo/nodejs/calendar/package.json b/demo/nodejs/calendar/package.json index f0adadc3..fb5f7166 100644 --- a/demo/nodejs/calendar/package.json +++ b/demo/nodejs/calendar/package.json @@ -4,7 +4,7 @@ "description": "Demo of enumerating interesting astronomy events for a calendar.", "main": "index.js", "scripts": { - "test": "../../../generate/node_modules/typescript/bin/tsc && node dist/calendar.js > test/calendar.txt && diff test/calendar_correct.txt test/calendar.txt" + "test": "../../../generate/node_modules/typescript/bin/tsc && node dist/calendar.js > test/calendar.txt && diff correct/calendar.txt test/calendar.txt" }, "author": "Don Cross ", "license": "MIT", diff --git a/demo/nodejs/calendar/run b/demo/nodejs/calendar/run index 1e4a0fe0..b34a91f2 100755 --- a/demo/nodejs/calendar/run +++ b/demo/nodejs/calendar/run @@ -6,5 +6,6 @@ Fail() } cp ../../../source/js/astronomy.ts . || Fail "Error copying astronomy TypeScript code." +rm -f test/*.txt npm test || Fail "Error in unit test." exit 0 diff --git a/demo/nodejs/test/camera_correct.txt b/demo/nodejs/correct/camera.txt similarity index 100% rename from demo/nodejs/test/camera_correct.txt rename to demo/nodejs/correct/camera.txt diff --git a/demo/nodejs/test/culminate_correct.txt b/demo/nodejs/correct/culminate.txt similarity index 100% rename from demo/nodejs/test/culminate_correct.txt rename to demo/nodejs/correct/culminate.txt diff --git a/demo/nodejs/test/equator_of_date_correct.txt b/demo/nodejs/correct/equator_of_date.txt similarity index 100% rename from demo/nodejs/test/equator_of_date_correct.txt rename to demo/nodejs/correct/equator_of_date.txt diff --git a/demo/nodejs/test/equatorial_correct.txt b/demo/nodejs/correct/equatorial.txt similarity index 100% rename from demo/nodejs/test/equatorial_correct.txt rename to demo/nodejs/correct/equatorial.txt diff --git a/demo/nodejs/test/gravity_correct.txt b/demo/nodejs/correct/gravity.txt similarity index 100% rename from demo/nodejs/test/gravity_correct.txt rename to demo/nodejs/correct/gravity.txt diff --git a/demo/nodejs/test/horizon_correct.txt b/demo/nodejs/correct/horizon.txt similarity index 100% rename from demo/nodejs/test/horizon_correct.txt rename to demo/nodejs/correct/horizon.txt diff --git a/demo/nodejs/test/lunar_eclipse_correct.txt b/demo/nodejs/correct/lunar_eclipse.txt similarity index 100% rename from demo/nodejs/test/lunar_eclipse_correct.txt rename to demo/nodejs/correct/lunar_eclipse.txt diff --git a/demo/nodejs/test/moonphase_correct.txt b/demo/nodejs/correct/moonphase.txt similarity index 100% rename from demo/nodejs/test/moonphase_correct.txt rename to demo/nodejs/correct/moonphase.txt diff --git a/demo/nodejs/test/positions_correct.txt b/demo/nodejs/correct/positions.txt similarity index 100% rename from demo/nodejs/test/positions_correct.txt rename to demo/nodejs/correct/positions.txt diff --git a/demo/nodejs/test/riseset_correct.txt b/demo/nodejs/correct/riseset.txt similarity index 100% rename from demo/nodejs/test/riseset_correct.txt rename to demo/nodejs/correct/riseset.txt diff --git a/demo/nodejs/test/seasons_correct.txt b/demo/nodejs/correct/seasons.txt similarity index 100% rename from demo/nodejs/test/seasons_correct.txt rename to demo/nodejs/correct/seasons.txt diff --git a/demo/nodejs/test/triangulate_correct.txt b/demo/nodejs/correct/triangulate.txt similarity index 100% rename from demo/nodejs/test/triangulate_correct.txt rename to demo/nodejs/correct/triangulate.txt diff --git a/demo/nodejs/test/test b/demo/nodejs/demotest similarity index 58% rename from demo/nodejs/test/test rename to demo/nodejs/demotest index 4b90e81c..bcf266a2 100755 --- a/demo/nodejs/test/test +++ b/demo/nodejs/demotest @@ -1,61 +1,62 @@ #!/bin/bash Fail() { - echo "FATAL(demo/nodejs/test/test): $1" + echo "FATAL(demo/nodejs/demotest): $1" exit 1 } -rm -f test/{equatorial,equator_of_date,camera,moonphase,positions,riseset,seasons,culminate,horizon,lunar_eclipse,triangulate,gravity}.txt +rm -f test/*.txt +mkdir -p test echo "Testing example: equatorial.js" node equatorial.js 38.1256 -89.5544 215.7 23.5 2021-03-27T18:45:00Z > test/equatorial.txt || Fail "Error testing equatorial.js." -diff test/equatorial.txt test/equatorial_correct.txt || Fail "Error comparing equatorial.js output." +diff {correct,test}/equatorial.txt || Fail "Error comparing equatorial.js output." echo "Testing example: equator_of_date.js" node equator_of_date.js a 12 45 2021-07-06T00:00:00Z > test/equator_of_date.txt || Fail "Error testing equator_of_date.js" -diff test/equator_of_date.txt test/equator_of_date_correct.txt || Fail "Error comparing equator_of_date.js output." +diff {correct,test}/equator_of_date.txt || Fail "Error comparing equator_of_date.js output." echo "Testing example: camera.js" node camera.js 29 -81 2021-03-22T02:45:00Z > test/camera.txt || Fail "Error testing camera.js." -diff test/camera.txt test/camera_correct.txt || Fail "Error comparing camera.js output." +diff {correct,test}/camera.txt || Fail "Error comparing camera.js output." echo "Testing example: moonphase.js" node moonphase.js 2019-06-15T09:15:32.987Z > test/moonphase.txt || Fail "Error running moonphase.js." -diff test/moonphase.txt test/moonphase_correct.txt || Fail "Error comparing moonphase.js output." +diff {correct,test}/moonphase.txt || Fail "Error comparing moonphase.js output." echo "Testing example: positions.js" node positions.js +45.6 -90.7 2018-11-30T17:55:07.234Z > test/positions.txt || Fail "Error running positions.js." -diff test/positions.txt test/positions_correct.txt || Fail "Error comparing positions.js output." +diff {correct,test}/positions.txt || Fail "Error comparing positions.js output." echo "Testing example: riseset.js" node riseset.js +45.6 -90.7 2018-11-30T17:55:07.234Z > test/riseset.txt || Fail "Error running riseset.js." -diff test/riseset.txt test/riseset_correct.txt || Fail "Error comparing riseset.js output." +diff {correct,test}/riseset.txt || Fail "Error comparing riseset.js output." echo "Testing example: seasons.js" node seasons.js 2019 > test/seasons.txt || Fail "Error running seasons.js." -diff test/seasons.txt test/seasons_correct.txt || Fail "Error comparing seasons.js output." +diff {correct,test}/seasons.txt || Fail "Error comparing seasons.js output." echo "Testing example: culminate.js" node culminate +30 -90 2015-02-28T00:00Z > test/culminate.txt || Fail "Error running culminate.js." -diff test/culminate.txt test/culminate_correct.txt || Fail "Error comparing culminate.js output." +diff {correct,test}/culminate.txt || Fail "Error comparing culminate.js output." echo "Testing example: horizon.js" node horizon +25.5 -85.3 2016-12-25T12:30:45Z > test/horizon.txt || Fail "Error running horizon.js." -diff test/horizon.txt test/horizon_correct.txt || Fail "Error comparing horizon.js output." +diff {correct,test}/horizon.txt || Fail "Error comparing horizon.js output." echo "Testing example: lunar_eclipse.js" node lunar_eclipse.js 1988-01-01 > test/lunar_eclipse.txt || Fail "Error running lunar_eclipse.js." -diff test/lunar_eclipse.txt test/lunar_eclipse_correct.txt || Fail "Error comparing lunar_eclipse.js output." +diff {correct,test}/lunar_eclipse.txt || Fail "Error comparing lunar_eclipse.js output." echo "Testing example: triangulate.js" node triangulate.js 48.16042 24.49986 2019 18 7 48.27305 24.36401 662 83 12 > test/triangulate.txt || Fail "Error running triangulate.js." -diff test/triangulate.txt test/triangulate_correct.txt || Fail "Error comparing triangulate.js output." +diff {correct,test}/triangulate.txt || Fail "Error comparing triangulate.js output." echo "Testing example: gravity.js" for latitude in {0..90}; do node gravity.js ${latitude} 0 >> test/gravity.txt || Fail "Error running gravity.js." done -diff test/gravity.txt test/gravity_correct.txt || Fail "Error comparing gravity.js output." +diff {correct,test}/gravity.txt || Fail "Error comparing gravity.js output." cd calendar || Fail "Cannot change to calendar directory." ./run || exit 1 diff --git a/demo/python/test/camera_correct.txt b/demo/python/correct/camera.txt similarity index 100% rename from demo/python/test/camera_correct.txt rename to demo/python/correct/camera.txt diff --git a/demo/python/test/constellation_correct.txt b/demo/python/correct/constellation.txt similarity index 100% rename from demo/python/test/constellation_correct.txt rename to demo/python/correct/constellation.txt diff --git a/demo/python/test/culminate_correct.txt b/demo/python/correct/culminate.txt similarity index 100% rename from demo/python/test/culminate_correct.txt rename to demo/python/correct/culminate.txt diff --git a/demo/python/test/galactic_correct.txt b/demo/python/correct/galactic.txt similarity index 100% rename from demo/python/test/galactic_correct.txt rename to demo/python/correct/galactic.txt diff --git a/demo/python/test/gravity_correct.txt b/demo/python/correct/gravity.txt similarity index 100% rename from demo/python/test/gravity_correct.txt rename to demo/python/correct/gravity.txt diff --git a/demo/python/test/horizon_correct.txt b/demo/python/correct/horizon.txt similarity index 100% rename from demo/python/test/horizon_correct.txt rename to demo/python/correct/horizon.txt diff --git a/demo/python/test/jupiter_moons_correct.txt b/demo/python/correct/jupiter_moons.txt similarity index 100% rename from demo/python/test/jupiter_moons_correct.txt rename to demo/python/correct/jupiter_moons.txt diff --git a/demo/python/test/lunar_angles_correct.txt b/demo/python/correct/lunar_angles.txt similarity index 100% rename from demo/python/test/lunar_angles_correct.txt rename to demo/python/correct/lunar_angles.txt diff --git a/demo/python/test/lunar_eclipse_correct.txt b/demo/python/correct/lunar_eclipse.txt similarity index 100% rename from demo/python/test/lunar_eclipse_correct.txt rename to demo/python/correct/lunar_eclipse.txt diff --git a/demo/python/test/moonphase_correct.txt b/demo/python/correct/moonphase.txt similarity index 100% rename from demo/python/test/moonphase_correct.txt rename to demo/python/correct/moonphase.txt diff --git a/demo/python/test/positions_correct.txt b/demo/python/correct/positions.txt similarity index 100% rename from demo/python/test/positions_correct.txt rename to demo/python/correct/positions.txt diff --git a/demo/python/test/riseset_correct.txt b/demo/python/correct/riseset.txt similarity index 100% rename from demo/python/test/riseset_correct.txt rename to demo/python/correct/riseset.txt diff --git a/demo/python/test/seasons_correct.txt b/demo/python/correct/seasons.txt similarity index 100% rename from demo/python/test/seasons_correct.txt rename to demo/python/correct/seasons.txt diff --git a/demo/python/test/stars_near_moon_correct.txt b/demo/python/correct/stars_near_moon.txt similarity index 100% rename from demo/python/test/stars_near_moon_correct.txt rename to demo/python/correct/stars_near_moon.txt diff --git a/demo/python/test/triangulate_correct.txt b/demo/python/correct/triangulate.txt similarity index 100% rename from demo/python/test/triangulate_correct.txt rename to demo/python/correct/triangulate.txt diff --git a/demo/python/test/test b/demo/python/demotest similarity index 53% rename from demo/python/test/test rename to demo/python/demotest index 45c45314..479abd62 100755 --- a/demo/python/test/test +++ b/demo/python/demotest @@ -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 diff --git a/generate/run b/generate/run index 554934be..c10b8c78 100755 --- a/generate/run +++ b/generate/run @@ -131,13 +131,13 @@ echo "" echo "" echo "Testing example programs." cd ../demo/c || Fail "Cannot change directory to ../demo/c" -test/test || Fail "Error testing C examples" +./demotest || Fail "Error testing C examples" cd ../nodejs || Fail "Cannot change directory to ../nodejs" -test/test || Fail "Error testing nodejs examples." +./demotest || Fail "Error testing nodejs examples." cd ../python || Fail "Cannot change directory to ../python" -test/test || Fail "Error testing Python examples." +./demotest || Fail "Error testing Python examples." cd ../csharp || Fail "Cannot change directory to ../csharp" -test/test || Fail "Error testing C# examples." +./demotest || Fail "Error testing C# examples." cd ../java || Fail "Cannot change directory to ../java" ./demotest || Fail "Error testing Java examples."