Float utility

This commit is contained in:
Dan Paulat 2022-04-08 01:34:36 -05:00
parent 711993362c
commit 3fc6837f2a
5 changed files with 132 additions and 3 deletions

View file

@ -0,0 +1,50 @@
#include <scwx/util/float.hpp>
#include <gtest/gtest.h>
namespace scwx
{
namespace util
{
TEST(FloatTest, Decode32Positive1)
{
uint16_t msw = 0x3f80;
uint16_t lsw = 0x0000;
float x = DecodeFloat32(msw, lsw);
EXPECT_FLOAT_EQ(x, 1.0f);
}
TEST(FloatTest, Decode32Negative1)
{
uint16_t msw = 0xbf80;
uint16_t lsw = 0x0000;
float x = DecodeFloat32(msw, lsw);
EXPECT_FLOAT_EQ(x, -1.0f);
}
TEST(FloatTest, Decode32Positive12345678)
{
uint16_t msw = 0x4b3c;
uint16_t lsw = 0x614e;
float x = DecodeFloat32(msw, lsw);
EXPECT_FLOAT_EQ(x, 12345678.0f);
}
TEST(FloatTest, Decode16h0x5bb4)
{
uint16_t hex = 0x5bb4;
float x = DecodeFloat16(hex);
EXPECT_FLOAT_EQ(x, 123.25f);
}
} // namespace util
} // namespace scwx

View file

@ -15,7 +15,8 @@ set(SRC_AWIPS_TESTS source/scwx/awips/coded_location.test.cpp
set(SRC_COMMON_TESTS source/scwx/common/color_table.test.cpp)
set(SRC_QT_CONFIG_TESTS source/scwx/qt/config/radar_site.test.cpp)
set(SRC_QT_MANAGER_TESTS source/scwx/qt/manager/settings_manager.test.cpp)
set(SRC_UTIL_TESTS source/scwx/util/rangebuf.test.cpp
set(SRC_UTIL_TESTS source/scwx/util/float.test.cpp
source/scwx/util/rangebuf.test.cpp
source/scwx/util/streams.test.cpp
source/scwx/util/vectorbuf.test.cpp)
set(SRC_WSR88D_TESTS source/scwx/wsr88d/ar2v_file.test.cpp