James Kuszmaul | 18008f8 | 2023-02-23 20:52:50 -0800 | [diff] [blame] | 1 | #include "y2023/localizer/map_expander_lib.h" |
| 2 | |
| 3 | #include "gtest/gtest.h" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 4 | |
James Kuszmaul | 18008f8 | 2023-02-23 20:52:50 -0800 | [diff] [blame] | 5 | #include "aos/testing/flatbuffer_eq.h" |
| 6 | |
| 7 | namespace y2023::localizer::testing { |
| 8 | class 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 Kuszmaul | 98c798d | 2024-04-24 15:58:09 -0700 | [diff] [blame^] | 21 | |
| 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. |
| 24 | TEST_F(MapExpanderTest, DISABLED_BackAndForthConsistent) { |
James Kuszmaul | 18008f8 | 2023-02-23 20:52:50 -0800 | [diff] [blame] | 25 | // 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 Kuszmaul | 98c798d | 2024-04-24 15:58:09 -0700 | [diff] [blame^] | 50 | TEST_F(MapExpanderTest, DISABLED_ExpandMap) { |
James Kuszmaul | 18008f8 | 2023-02-23 20:52:50 -0800 | [diff] [blame] | 51 | 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 |