diff options
author | Benjamin Barenblat <bbarenblat@gmail.com> | 2022-01-17 23:12:32 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbarenblat@gmail.com> | 2022-01-30 15:55:27 -0500 |
commit | d0e18bdb7924c71cdca8dd983711171d87ef28be (patch) | |
tree | 6be11aae0b7c8874e6507b75b4ef26d1353952c7 /src/astro_test.cc |
glplanet draws Earth like it currently appears from space, putting
nighttime areas in shadow and daytime areas in light. It’s modeled
after Xplanet (http://xplanet.sourceforge.net/), but whereas Xplanet is
entirely a CPU-resident program, glplanet draws using OpenGL. It’s thus
much less resource-intensive, particularly when using high-resolution
textures.
Diffstat (limited to 'src/astro_test.cc')
-rw-r--r-- | src/astro_test.cc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/astro_test.cc b/src/astro_test.cc new file mode 100644 index 0000000..2fc1cb8 --- /dev/null +++ b/src/astro_test.cc @@ -0,0 +1,64 @@ +// Copyright 2022 Benjamin Barenblat +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#include "src/astro.h" + +#include <gmock/gmock.h> +#include <gtest/gtest.h> + +#include <chrono> + +#include "third_party/date/include/date/tz.h" + +namespace glplanet { +namespace { + +using ::testing::DoubleNear; +using ::testing::Pair; + +TEST(SunEquatorialPositionTest, MeeusExercise25A) { + // October 13, 1992, at 00:00:00 TDT (T = -0.072'183'436) + constexpr auto t = + std::chrono::time_point<date::tai_clock, std::chrono::milliseconds>() + + std::chrono::days(34 * 365 + 8 /* leap days */) + + std::chrono::days(31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 11) + + std::chrono::hours(23) + std::chrono::minutes(59) + + std::chrono::milliseconds(27'816); + EXPECT_THAT(SunEquatorialPosition(t), Pair(DoubleNear(-2.82078673, 1e-8), + DoubleNear(-0.1358751, 1e-8))); +} + +TEST(ApparentSiderealTimeAtGreenwichTest, MeeusExercise12A) { + // April 10, 1987, at 00:00:00 UT (T = -0.127'296'372'348) + constexpr auto t = + std::chrono::time_point<date::tai_clock, std::chrono::milliseconds>() + + std::chrono::days(29 * 365 + 7 /* leap days */) + + std::chrono::days(31 + 28 + 31 + 8) + std::chrono::hours(23) + + std::chrono::minutes(59) + std::chrono::milliseconds(27'816); + EXPECT_THAT(ApparentSiderealTimeAtGreenwich(t), DoubleNear(-2.832805, 1e-6)); +} + +TEST(HighNoonLocationTest, MarchEquinox) { + // March 20, 2022 15:29:52.331 UT + constexpr auto t = + std::chrono::time_point<date::tai_clock, std::chrono::milliseconds>() + + std::chrono::days(64 * 365 + 16 /* leap days */) + + std::chrono::days(31 + 28 + 19) + std::chrono::hours(15) + + std::chrono::minutes(29) + std::chrono::milliseconds(24'515); + EXPECT_THAT(HighNoonLocation(t), + Pair(DoubleNear(-0.883655431852, 1e-10), DoubleNear(0.0, 1e-10))); +} + +} // namespace +} // namespace glplanet |