diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-05-06 01:19:30 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-06 17:54:28 +0200 |
commit | 67322b0702836807e29265e86556ebf43bb9d510 (patch) | |
tree | 86d2e2099ecc377cf11ddcf9106c500969b1afbb /Tests/AK/TestBitCast.cpp | |
parent | fd0dbd1ebfbcbc29d46393061daa49dc7390caa7 (diff) | |
download | serenity-67322b0702836807e29265e86556ebf43bb9d510.zip |
Tests: Move AK tests to Tests/AK
Diffstat (limited to 'Tests/AK/TestBitCast.cpp')
-rw-r--r-- | Tests/AK/TestBitCast.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Tests/AK/TestBitCast.cpp b/Tests/AK/TestBitCast.cpp new file mode 100644 index 0000000000..baf270f9b6 --- /dev/null +++ b/Tests/AK/TestBitCast.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibTest/TestCase.h> + +#include <AK/BitCast.h> + +template<typename A, typename B> +void check_cast_both_ways(const A& a, const B& b) +{ + EXPECT_EQ((bit_cast<A, B>(b)), a); + EXPECT_EQ((bit_cast<B, A>(a)), b); +} + +TEST_CASE(double_int_conversion) +{ + check_cast_both_ways(static_cast<u64>(0), 0.0); + check_cast_both_ways(static_cast<u64>(1) << 63, -0.0); + check_cast_both_ways(static_cast<u64>(0x4172f58bc0000000), 19880124.0); +} |