summaryrefslogtreecommitdiff
path: root/Tests/AK/TestBitCast.cpp
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-05-06 01:19:30 -0700
committerAndreas Kling <kling@serenityos.org>2021-05-06 17:54:28 +0200
commit67322b0702836807e29265e86556ebf43bb9d510 (patch)
tree86d2e2099ecc377cf11ddcf9106c500969b1afbb /Tests/AK/TestBitCast.cpp
parentfd0dbd1ebfbcbc29d46393061daa49dc7390caa7 (diff)
downloadserenity-67322b0702836807e29265e86556ebf43bb9d510.zip
Tests: Move AK tests to Tests/AK
Diffstat (limited to 'Tests/AK/TestBitCast.cpp')
-rw-r--r--Tests/AK/TestBitCast.cpp23
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);
+}