| 120 | |
| 121 | template <typename Encoder, typename DfTest> |
| 122 | void TestOrdinalEncoderMixed() { |
| 123 | Encoder encoder; |
| 124 | auto sol = std::vector<std::int32_t>{0, 3, 1}; |
| 125 | |
| 126 | { |
| 127 | auto df = |
| 128 | DfTest::Make(DfTest::MakeInts(2, 1, 3, 0), DfTest::MakeStrs("cbd", "bbd", "dbd", "ab")); |
| 129 | auto orig_dict = df.View(); |
| 130 | |
| 131 | auto new_df = DfTest::Make(DfTest::MakeInts(2, 0, 1), DfTest::MakeStrs("cbd", "ab", "bbd")); |
| 132 | auto new_dict = new_df.View(); |
| 133 | |
| 134 | encoder.Recode(orig_dict, new_dict, new_df.MappingView()); |
| 135 | ASSERT_EQ(new_df.Mapping().size(), 6); |
| 136 | for (std::size_t i = 0; i < new_df.Mapping().size(); ++i) { |
| 137 | ASSERT_EQ(new_df.Mapping()[i], sol[i % sol.size()]); |
| 138 | } |
| 139 | } |
| 140 | { |
| 141 | auto df = |
| 142 | DfTest::Make(DfTest::MakeStrs("cbd", "bbd", "dbd", "ab"), DfTest::MakeInts(2, 1, 3, 0)); |
| 143 | auto orig_dict = df.View(); |
| 144 | |
| 145 | auto new_df = DfTest::Make(DfTest::MakeStrs("cbd", "ab", "bbd"), DfTest::MakeInts(2, 0, 1)); |
| 146 | auto new_dict = new_df.View(); |
| 147 | |
| 148 | encoder.Recode(orig_dict, new_dict, new_df.MappingView()); |
| 149 | ASSERT_EQ(new_df.Mapping().size(), 6); |
| 150 | for (std::size_t i = 0; i < new_df.Mapping().size(); ++i) { |
| 151 | ASSERT_EQ(new_df.Mapping()[i], sol[i % sol.size()]); |
| 152 | } |
| 153 | } |
| 154 | { |
| 155 | auto df = |
| 156 | DfTest::Make(DfTest::MakeStrs("cbd", "bbd", "dbd", "ab"), DfTest::MakeInts(2, 1, 3, 0), |
| 157 | DfTest::MakeStrs("cbd", "bbd", "dbd", "ab")); |
| 158 | auto orig_dict = df.View(); |
| 159 | |
| 160 | auto new_df = DfTest::Make(DfTest::MakeStrs("cbd", "ab", "bbd"), DfTest::MakeInts(2, 0), |
| 161 | DfTest::MakeStrs("cbd", "ab", "bbd")); |
| 162 | auto new_dict = new_df.View(); |
| 163 | |
| 164 | encoder.Recode(orig_dict, new_dict, new_df.MappingView()); |
| 165 | ASSERT_EQ(new_df.Mapping().size(), 8); |
| 166 | for (std::size_t i = 0; i < 3; ++i) { |
| 167 | ASSERT_EQ(new_df.Mapping()[i], sol[i]); |
| 168 | } |
| 169 | for (std::size_t i = 3, k = 0; i < 5; ++i, ++k) { |
| 170 | ASSERT_EQ(new_df.Mapping()[i], sol[k]); |
| 171 | } |
| 172 | for (std::size_t i = 5, k = 0; i < 8; ++i, ++k) { |
| 173 | ASSERT_EQ(new_df.Mapping()[i], sol[k]); |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | template <typename Encoder, typename DfTest> |
| 179 | void TestOrdinalEncoderEmpty() { |
nothing calls this directly
no test coverage detected