Skip to content

Commit

Permalink
look
Browse files Browse the repository at this point in the history
  • Loading branch information
srimanachanta committed Nov 22, 2023
1 parent 1a21927 commit 5d931ff
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,57 @@
*/

#include "gtest/gtest.h"
#include "photon.pb.h"
#include "photon/targeting/MultiTargetPNPResult.h"

// TODO
TEST(MultiTargetPNPResultTest, Equality) {}
TEST(MultiTargetPNPResultTest, Equality) {
photon::MultiTargetPNPResult a;
photon::MultiTargetPNPResult b;

// TODO
TEST(MultiTargetPNPResultTest, Inequality) {}
EXPECT_EQ(a, b);

photon::PNPResult pnpRes{
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1, 0};

photon::MultiTargetPNPResult a1{pnpRes, {1, 2, 3, 4}};
photon::MultiTargetPNPResult b1{pnpRes, {1, 2, 3, 4}};

EXPECT_EQ(a1, b1);
}

TEST(MultiTargetPNPResultTest, Roundtrip) {
photon::MultiTargetPNPResult result;

google::protobuf::Arena arena;
google::protobuf::Message* proto =
wpi::Protobuf<photon::MultiTargetPNPResult>::New(&arena);
wpi::Protobuf<photon::MultiTargetPNPResult>::Pack(proto, result);

photon::MultiTargetPNPResult unpacked_data =
wpi::Protobuf<photon::MultiTargetPNPResult>::Unpack(*proto);

EXPECT_EQ(result, unpacked_data);

photon::PNPResult pnpRes{
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1, 0};

photon::MultiTargetPNPResult result1{pnpRes, {1, 2, 3, 4}};

proto = wpi::Protobuf<photon::MultiTargetPNPResult>::New(&arena);
wpi::Protobuf<photon::MultiTargetPNPResult>::Pack(proto, result1);

photon::MultiTargetPNPResult unpacked_data1 =
wpi::Protobuf<photon::MultiTargetPNPResult>::Unpack(*proto);

EXPECT_EQ(result1, unpacked_data1);
}
55 changes: 51 additions & 4 deletions photon-targeting/src/test/native/cpp/targeting/PNPResultTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,57 @@
*/

#include "gtest/gtest.h"
#include "photon.pb.h"
#include "photon/targeting/PNPResult.h"

// TODO
TEST(PNPResultTest, Equality) {}
TEST(PNPResultTest, Equality) {
photon::PNPResult a;
photon::PNPResult b;

// TODO
TEST(PNPResultTest, Inequality) {}
EXPECT_EQ(a, b);

photon::PNPResult a1{frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1, 0};
photon::PNPResult b1{frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1, 0};

EXPECT_EQ(a1, b1);
}

TEST(PNPResultTest, Roundtrip) {
photon::PNPResult result;

google::protobuf::Arena arena;
google::protobuf::Message* proto =
wpi::Protobuf<photon::PNPResult>::New(&arena);
wpi::Protobuf<photon::PNPResult>::Pack(proto, result);

photon::PNPResult unpacked_data =
wpi::Protobuf<photon::PNPResult>::Unpack(*proto);

EXPECT_EQ(result, unpacked_data);

photon::PNPResult result1{
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1, 0};

proto = wpi::Protobuf<photon::PNPResult>::New(&arena);
wpi::Protobuf<photon::PNPResult>::Pack(proto, result1);

photon::PNPResult unpacked_data2 =
wpi::Protobuf<photon::PNPResult>::Unpack(*proto);

EXPECT_EQ(result1, unpacked_data2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,137 @@
*/

#include "gtest/gtest.h"
#include "photon.pb.h"
#include "photon/targeting/PhotonPipelineResult.h"
#include "photon/targeting/PhotonTrackedTarget.h"

// TODO
TEST(PhotonPipelineResultTest, Equality) {}
TEST(PhotonPipelineResultTest, Equality) {
photon::PhotonPipelineResult a{12_ms, {}};
photon::PhotonPipelineResult b{12_ms, {}};

EXPECT_EQ(a, b);

wpi::SmallVector<photon::PhotonTrackedTarget, 2> targets{
photon::PhotonTrackedTarget{
3.0,
-4.0,
9.0,
4.0,
1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
-1,
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}},
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}}},
photon::PhotonTrackedTarget{
3.0,
-4.0,
9.1,
6.7,
-1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
-1,
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}},
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6},
std::pair{7, 8}}}};

photon::PhotonPipelineResult a1{12_ms, targets};
photon::PhotonPipelineResult b1{12_ms, targets};

EXPECT_EQ(a1, b1);

photon::PNPResult pnpRes{
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1, 0};

photon::MultiTargetPNPResult multitagRes{pnpRes, {1, 2, 3, 4}};

photon::PhotonPipelineResult a2{12_ms, targets, multitagRes};
photon::PhotonPipelineResult b2{12_ms, targets, multitagRes};

EXPECT_EQ(a2, b2);
}

// TODO
TEST(PhotonPipelineResultTest, Inequality) {}
TEST(PhotonPipelineResultTest, Roundtrip) {
photon::PhotonPipelineResult result{12_ms, {}};

google::protobuf::Arena arena;
google::protobuf::Message* proto =
wpi::Protobuf<photon::PhotonPipelineResult>::New(&arena);
wpi::Protobuf<photon::PhotonPipelineResult>::Pack(proto, result);

photon::PhotonPipelineResult unpacked_data =
wpi::Protobuf<photon::PhotonPipelineResult>::Unpack(*proto);

EXPECT_EQ(result, unpacked_data);

wpi::SmallVector<photon::PhotonTrackedTarget, 2> targets{
photon::PhotonTrackedTarget{
3.0,
-4.0,
9.0,
4.0,
1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
-1,
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}},
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}}},
photon::PhotonTrackedTarget{
3.0,
-4.0,
9.1,
6.7,
-1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
-1,
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}},
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6},
std::pair{7, 8}}}};

photon::PhotonPipelineResult result2{12_ms, targets};

proto = wpi::Protobuf<photon::PhotonPipelineResult>::New(&arena);
wpi::Protobuf<photon::PhotonPipelineResult>::Pack(proto, result2);

photon::PhotonPipelineResult unpacked_data2 =
wpi::Protobuf<photon::PhotonPipelineResult>::Unpack(*proto);

EXPECT_EQ(result2, unpacked_data2);

photon::PNPResult pnpRes{
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1, 0};

photon::MultiTargetPNPResult multitagRes{pnpRes, {1, 2, 3, 4}};

photon::PhotonPipelineResult result3{12_ms, targets, multitagRes};

proto = wpi::Protobuf<photon::PhotonPipelineResult>::New(&arena);
wpi::Protobuf<photon::PhotonPipelineResult>::Pack(proto, result3);

photon::PhotonPipelineResult unpacked_data3 =
wpi::Protobuf<photon::PhotonPipelineResult>::Unpack(*proto);

EXPECT_EQ(result3, unpacked_data3);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,63 @@
*/

#include "gtest/gtest.h"
#include "photon.pb.h"
#include "photon/targeting/PhotonTrackedTarget.h"

// TODO
TEST(PhotonTrackedTargetTest, Equality) {}
TEST(PhotonTrackedTargetTest, Equality) {
photon::PhotonTrackedTarget a{
3.0,
4.0,
9.0,
-5.0,
-1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
-1,
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}},
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}}};

// TODO
TEST(PhotonTrackedTargetTest, Inequality) {}
photon::PhotonTrackedTarget b{
3.0,
4.0,
9.0,
-5.0,
-1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
-1,
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}},
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}}};

EXPECT_EQ(a, b);
}

TEST(PhotonTrackedTargetTest, Roundtrip) {
photon::PhotonTrackedTarget target{
3.0,
4.0,
9.0,
-5.0,
-1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
-1,
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}},
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}}};

google::protobuf::Arena arena;
google::protobuf::Message* proto =
wpi::Protobuf<photon::PhotonTrackedTarget>::New(&arena);
wpi::Protobuf<photon::PhotonTrackedTarget>::Pack(proto, target);

photon::PhotonTrackedTarget unpacked_data =
wpi::Protobuf<photon::PhotonTrackedTarget>::Unpack(*proto);

EXPECT_EQ(target, unpacked_data);
}

0 comments on commit 5d931ff

Please sign in to comment.