MCPcopy Create free account
hub / github.com/dmlc/xgboost / TestOrdinalEncoderInts

Function TestOrdinalEncoderInts

tests/cpp/encoder/test_ordinal.h:83–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81
82template <typename Encoder, typename DfTest>
83void TestOrdinalEncoderInts() {
84 Encoder encoder;
85 auto sol = std::vector<std::int32_t>{0, 3, 1};
86
87 {
88 auto df = DfTest::Make(DfTest::MakeInts(2, 1, 3, 0));
89 auto orig_dict = df.View();
90
91 auto new_df = DfTest::Make(DfTest::MakeInts(2, 0, 1));
92 auto new_dict = new_df.View();
93
94 encoder.Recode(orig_dict, new_dict, new_df.MappingView());
95 ASSERT_EQ(new_df.Mapping(), sol);
96 }
97 {
98 // Test error message.
99 auto df = DfTest::Make(DfTest::MakeInts(2, 1, 3, 0));
100 auto orig_dict = df.View();
101
102 auto new_df = DfTest::Make(DfTest::MakeInts(2, 0, 5));
103 auto new_dict = new_df.View();
104 ASSERT_THAT([&] { encoder.Recode(orig_dict, new_dict, new_df.MappingView()); },
105 ::testing::ThrowsMessage<std::logic_error>(::testing::HasSubstr("`5`")));
106 }
107 {
108 auto df = DfTest::Make(DfTest::MakeInts(0), DfTest::MakeInts(0, 1));
109 auto orig_dict = df.View();
110
111 auto new_df = DfTest::Make(DfTest::MakeInts(0), DfTest::MakeInts(0, 1));
112 auto new_dict = new_df.View();
113
114 encoder.Recode(orig_dict, new_dict, new_df.MappingView());
115 auto mapping = new_df.Mapping();
116 std::vector<std::int32_t> sol{0, 0, 1};
117 ASSERT_EQ(mapping, sol);
118 }
119}
120
121template <typename Encoder, typename DfTest>
122void TestOrdinalEncoderMixed() {

Callers

nothing calls this directly

Calls 3

RecodeMethod · 0.80
MappingViewMethod · 0.80
ViewMethod · 0.45

Tested by

no test coverage detected