-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for XKCD 3038 alt-text (#377)
See for context: <https://xkcd.com/3038/>. Presumably, the joke only works if the speed limit in question corresponds to a realistic speed limit for American roads, so we take the range to be from 25 MPH (many residential streets) to 75 MPH (some roads in places I have seen such as parts of MI or TX). To make this work, it was convenient to add unit definitions for `Arcminutes` and `Arcseconds`. These have various choices for unit symbol, but I decided to go with `am` and `as` because this will be the most consistent with users who form symbols for `mas` and `uas`. For the labels, in any case, I went with `'` and `"`. I could be persuaded to go with `''` for arcseconds, but I think `"` is likely to be better overall. We also now group all of our XKCD test cases into an `Xkcd` test family, because of course we do.
- Loading branch information
Showing
8 changed files
with
225 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2025 Aurora Operations, Inc. | ||
// | ||
// 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 | ||
// | ||
// http://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. | ||
|
||
#pragma once | ||
|
||
#include "au/units/arcminutes_fwd.hh" | ||
// Keep corresponding `_fwd.hh` file on top. | ||
|
||
#include "au/quantity.hh" | ||
#include "au/unit_symbol.hh" | ||
#include "au/units/degrees.hh" | ||
|
||
namespace au { | ||
|
||
// DO NOT follow this pattern to define your own units. This is for library-defined units. | ||
// Instead, follow instructions at (https://aurora-opensource.github.io/au/main/howto/new-units/). | ||
template <typename T> | ||
struct ArcminutesLabel { | ||
static constexpr const char label[] = "'"; | ||
}; | ||
template <typename T> | ||
constexpr const char ArcminutesLabel<T>::label[]; | ||
struct Arcminutes : decltype(Degrees{} / mag<60>()), ArcminutesLabel<void> { | ||
using ArcminutesLabel<void>::label; | ||
}; | ||
constexpr auto arcminute = SingularNameFor<Arcminutes>{}; | ||
constexpr auto arcminutes = QuantityMaker<Arcminutes>{}; | ||
|
||
namespace symbols { | ||
constexpr auto am = SymbolFor<Arcminutes>{}; | ||
} | ||
|
||
} // namespace au |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2025 Aurora Operations, Inc. | ||
// | ||
// 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 | ||
// | ||
// http://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. | ||
|
||
#pragma once | ||
|
||
namespace au { | ||
|
||
struct Arcminutes; | ||
|
||
} // namespace au |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2025 Aurora Operations, Inc. | ||
// | ||
// 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 | ||
// | ||
// http://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. | ||
|
||
#pragma once | ||
|
||
#include "au/units/arcseconds_fwd.hh" | ||
// Keep corresponding `_fwd.hh` file on top. | ||
|
||
#include "au/quantity.hh" | ||
#include "au/unit_symbol.hh" | ||
#include "au/units/degrees.hh" | ||
|
||
namespace au { | ||
|
||
// DO NOT follow this pattern to define your own units. This is for library-defined units. | ||
// Instead, follow instructions at (https://aurora-opensource.github.io/au/main/howto/new-units/). | ||
template <typename T> | ||
struct ArcsecondsLabel { | ||
static constexpr const char label[] = "\""; | ||
}; | ||
template <typename T> | ||
constexpr const char ArcsecondsLabel<T>::label[]; | ||
struct Arcseconds : decltype(Degrees{} / mag<3600>()), ArcsecondsLabel<void> { | ||
using ArcsecondsLabel<void>::label; | ||
}; | ||
constexpr auto arcsecond = SingularNameFor<Arcseconds>{}; | ||
constexpr auto arcseconds = QuantityMaker<Arcseconds>{}; | ||
|
||
namespace symbols { | ||
constexpr auto as = SymbolFor<Arcseconds>{}; | ||
} | ||
|
||
} // namespace au |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2025 Aurora Operations, Inc. | ||
// | ||
// 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 | ||
// | ||
// http://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. | ||
|
||
#pragma once | ||
|
||
namespace au { | ||
|
||
struct Arcseconds; | ||
|
||
} // namespace au |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2025 Aurora Operations, Inc. | ||
// | ||
// 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 | ||
// | ||
// http://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 "au/units/arcminutes.hh" | ||
|
||
#include "au/testing.hh" | ||
#include "au/units/degrees.hh" | ||
#include "gtest/gtest.h" | ||
|
||
namespace au { | ||
|
||
using ::testing::Eq; | ||
|
||
TEST(Arcminutes, HasExpectedLabel) { expect_label<Arcminutes>("'"); } | ||
|
||
TEST(Arcminutes, RelatesCorrectlyToDegrees) { EXPECT_THAT(arcminutes(120.0), Eq(degrees(2.0))); } | ||
|
||
TEST(Arcminutes, HasExpectedSymbol) { | ||
using symbols::am; | ||
EXPECT_THAT(5.f * am, SameTypeAndValue(arcminutes(5.f))); | ||
} | ||
|
||
} // namespace au |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2025 Aurora Operations, Inc. | ||
// | ||
// 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 | ||
// | ||
// http://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 "au/units/arcseconds.hh" | ||
|
||
#include "au/testing.hh" | ||
#include "au/units/degrees.hh" | ||
#include "gtest/gtest.h" | ||
|
||
namespace au { | ||
|
||
using ::testing::Eq; | ||
|
||
TEST(Arcseconds, HasExpectedLabel) { expect_label<Arcseconds>("\""); } | ||
|
||
TEST(Arcseconds, RelatesCorrectlyToDegrees) { EXPECT_THAT(arcseconds(7200.0), Eq(degrees(2.0))); } | ||
|
||
TEST(Arcseconds, HasExpectedSymbol) { | ||
using symbols::as; | ||
EXPECT_THAT(5.f * as, SameTypeAndValue(arcseconds(5.f))); | ||
} | ||
|
||
} // namespace au |