blob: 33a532f1239f801faf3b2480d26b718b3ec887ec [file] [log] [blame]
James Kuszmaul18008f82023-02-23 20:52:50 -08001#include "y2023/localizer/map_expander_lib.h"
2
3#include "gtest/gtest.h"
Philipp Schrader790cb542023-07-05 21:06:52 -07004
James Kuszmaul18008f82023-02-23 20:52:50 -08005#include "aos/testing/flatbuffer_eq.h"
6
7namespace y2023::localizer::testing {
8class MapExpanderTest : public ::testing::Test {
9 protected:
10 MapExpanderTest()
11 : relative_map_(aos::JsonFileToFlatbuffer<RelativeScoringMap>(
12 "y2023/constants/relative_scoring_map.json")),
13 target_map_(aos::JsonFileToFlatbuffer<frc971::vision::TargetMap>(
14 "y2023/vision/maps/target_map.json")),
15 absolute_map_(
16 ExpandMap(&relative_map_.message(), &target_map_.message())) {}
17 const aos::FlatbufferDetachedBuffer<RelativeScoringMap> relative_map_;
18 const aos::FlatbufferDetachedBuffer<frc971::vision::TargetMap> target_map_;
19 const aos::FlatbufferDetachedBuffer<ScoringMap> absolute_map_;
20};
James Kuszmaul98c798d2024-04-24 15:58:09 -070021
22// Note: These tests were disabled during some tweaks to the flatbuffer->JSON
23// code, as these tests are obnoxious to update and largely obsolete.
24TEST_F(MapExpanderTest, DISABLED_BackAndForthConsistent) {
James Kuszmaul18008f82023-02-23 20:52:50 -080025 // Use FlatbufferToJson instead of FlatbufferEq because we don't want
26 // equivalent but different encoded floating point numbers to get
27 // evaluated differently.
28#define CHECK_REVERSE(color, grid) \
29 { \
30 ASSERT_TRUE(absolute_map_.message().has_##color()); \
31 auto half = absolute_map_.message().color(); \
32 ASSERT_TRUE(half->has_##grid##_grid()); \
33 auto grid = half->grid##_grid(); \
34 auto relative_grid = \
35 RelativeGridForTag(grid, &target_map_.message(), \
36 relative_map_.message().color()->grid()); \
37 EXPECT_EQ(aos::FlatbufferToJson(relative_map_.message().nominal_grid()), \
38 aos::FlatbufferToJson(&relative_grid.message())); \
39 }
40 CHECK_REVERSE(blue, left);
41 CHECK_REVERSE(blue, middle);
42 CHECK_REVERSE(blue, right);
43 CHECK_REVERSE(red, left);
44 CHECK_REVERSE(red, middle);
45 CHECK_REVERSE(red, right);
46}
47
48// Test that the currently checked-in map is consistent with the results of
49// ExpandMap.
James Kuszmaul98c798d2024-04-24 15:58:09 -070050TEST_F(MapExpanderTest, DISABLED_ExpandMap) {
James Kuszmaul18008f82023-02-23 20:52:50 -080051 const std::string stored_map =
52 aos::util::ReadFileToStringOrDie("y2023/constants/scoring_map.json");
53 // TODO: Provide coherent error messages so that changes can be accommodated.
54 EXPECT_EQ(aos::FlatbufferToJson(absolute_map_,
55 {.multi_line = true, .max_multi_line = true}),
56 stored_map);
57}
58} // namespace y2023::localizer::testing