[wpimath] Move struct/proto classes to separate files (#5918)

Also add unit tests.
This commit is contained in:
PJ Reiniger
2023-11-21 13:11:57 -05:00
committed by GitHub
parent 80d7ad58ea
commit 35744a036e
141 changed files with 3360 additions and 1379 deletions

View File

@@ -0,0 +1,28 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <gtest/gtest.h>
#include "frc/geometry/Transform3d.h"
using namespace frc;
namespace {
using StructType = wpi::Struct<frc::Transform3d>;
const Transform3d kExpectedData{
Transform3d{Translation3d{0.3504_m, 22.9_m, 3.504_m},
Rotation3d{Quaternion{0.3504, 35.04, 2.29, 0.3504}}}};
} // namespace
TEST(Transform3dStructTest, Roundtrip) {
uint8_t buffer[StructType::kSize];
std::memset(buffer, 0, StructType::kSize);
StructType::Pack(buffer, kExpectedData);
Transform3d unpacked_data = StructType::Unpack(buffer);
EXPECT_EQ(kExpectedData.Translation(), unpacked_data.Translation());
EXPECT_EQ(kExpectedData.Rotation(), unpacked_data.Rotation());
}