-
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.
Copy over core units library code (#10)
We decomposed this PR into commits for reviewability. The first commit simply copies the files over, and gets all the targets to build. The second commit fixes the bugs we found: - Can't assume `std::chrono::nanoseconds` uses `int64_t` - We were missing explicit specializations for cv-qualified `Quantity` - `isnan()` was never `constexpr`---why did this ever work before? - template template parameters need to say `class`, not `typename` The third and final commit clarifies which targets are for public consumption.
- Loading branch information
Showing
32 changed files
with
8,777 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Aurora Innovation, Inc. Proprietary and Confidential. Copyright 2022. | ||
|
||
#pragma once | ||
|
||
#include <chrono> | ||
|
||
#include "au/math.hh" | ||
|
||
namespace au { | ||
|
||
// Define 1:1 mapping between duration types of chrono library and our library. | ||
template <typename RepT, typename Period> | ||
struct CorrespondingQuantity<std::chrono::duration<RepT, Period>> { | ||
using Unit = decltype(Seconds{} * (mag<Period::num>() / mag<Period::den>())); | ||
using Rep = RepT; | ||
|
||
using ChronoDuration = std::chrono::duration<Rep, Period>; | ||
|
||
static constexpr Rep extract_value(ChronoDuration d) { return d.count(); } | ||
static constexpr ChronoDuration construct_from_value(Rep x) { return ChronoDuration{x}; } | ||
}; | ||
|
||
} // 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,37 @@ | ||
// Aurora Innovation, Inc. Proprietary and Confidential. Copyright 2022. | ||
|
||
#include "au/au.hh" | ||
|
||
#include "au/testing.hh" | ||
#include "gtest/gtest.h" | ||
|
||
using ::testing::StaticAssertTypeEq; | ||
|
||
using namespace std::chrono_literals; | ||
|
||
namespace au { | ||
|
||
TEST(DurationQuantity, InterconvertsWithExactlyEquivalentChronoDuration) { | ||
constexpr QuantityD<Seconds> from_chrono = std::chrono::duration<double>{1.23}; | ||
EXPECT_THAT(from_chrono, SameTypeAndValue(seconds(1.23))); | ||
|
||
constexpr auto val = std::chrono::nanoseconds::rep{456}; | ||
constexpr std::chrono::nanoseconds from_au = nano(seconds)(val); | ||
EXPECT_THAT(from_au.count(), SameTypeAndValue(val)); | ||
} | ||
|
||
TEST(DurationQuantity, InterconvertsWithIndirectlyEquivalentChronoDuration) { | ||
constexpr QuantityD<Seconds> from_chrono = as_quantity(1234ms); | ||
EXPECT_THAT(from_chrono, SameTypeAndValue(seconds(1.234))); | ||
} | ||
|
||
TEST(Conversions, SupportIntMHzToU32Hz) { | ||
constexpr QuantityU32<Hertz> freq = mega(hertz)(40); | ||
EXPECT_THAT(freq, SameTypeAndValue(hertz(40'000'000u))); | ||
} | ||
|
||
TEST(CommonUnit, HandlesPrefixesReasonably) { | ||
StaticAssertTypeEq<CommonUnitT<Kilo<Meters>, Meters>, Meters>(); | ||
} | ||
|
||
} // namespace au |
Oops, something went wrong.