@@ -206,4 +206,55 @@ TEST(TEST_FeaHash, FeaRegister) {
206206}
207207
208208
209+ TEST (TEST_FeaHash, SchemaLineRegister) {
210+ feather::FeaHash feahash_;
211+ std::vector<std::string> test1_schema = {" test1" , " 100" , " 5" , " 0" };
212+ std::vector<std::string> test2_schema = {" test2" , " 101" , " 128" , " 2" };
213+ std::vector<std::string> test3_schema = {" test3" , " 102" , " 1" , " 1" };
214+ std::vector<std::string> test4_schema = {" test4" , " 103" , " 1024" , " 0" };
215+
216+ feahash_.SchemaLineRegister (test1_schema);
217+ ASSERT_THAT (feahash_.GetFeaBucketCodeLength (), test1_schema[2 ].size ());
218+ ASSERT_THAT (feahash_.GetSlot (" test1" )->GetSlotID (), std::stoi (test1_schema[1 ]));
219+ ASSERT_THAT (feahash_.GetSlot (" test1" )->GetBucketSize (), std::stoi (test1_schema[2 ]));
220+
221+ feahash_.SchemaLineRegister (test2_schema);
222+ ASSERT_THAT (feahash_.GetFeaBucketCodeLength (), test2_schema[2 ].size ());
223+ ASSERT_THAT (feahash_.GetSlot (" test2" )->GetBucketSize (), std::stoi (test2_schema[2 ]));
224+
225+ feahash_.SchemaLineRegister (test3_schema);
226+ ASSERT_THAT (feahash_.GetFeaBucketCodeLength (), test2_schema[2 ].size ());
227+
228+ feahash_.SchemaLineRegister (test4_schema);
229+ ASSERT_THAT (feahash_.GetFeaBucketCodeLength (), test4_schema[2 ].size ());
230+ }
231+
232+
233+ TEST (TEST_FeaHash, FeaHash2FeaIndex) {
234+ feather::FeaHash feahash_;
235+ std::vector<std::string> test1_schema = {" test1" , " 100" , " 5" , " 0" };
236+ std::vector<std::string> test2_schema = {" test2" , " 101" , " 128" , " 2" };
237+ std::vector<std::string> test3_schema = {" test3" , " 102" , " 1" , " 1" };
238+ std::vector<std::string> test4_schema = {" test4" , " 103" , " 1024" , " 0" };
239+ feahash_.SchemaLineRegister (test2_schema);
240+ feahash_.SchemaLineRegister (test4_schema);
241+ feahash_.SchemaLineRegister (test3_schema);
242+ feahash_.SchemaLineRegister (test1_schema);
243+ feahash_.Hash2IndexDictBuild ();
244+
245+ ASSERT_THAT (feahash_.GetFeaBucketCodeLength (), 4 );
246+
247+ ASSERT_THAT (feahash_.FeaHash2FeaIndex (1000000 ), " 1" );
248+ ASSERT_THAT (feahash_.FeaHash2FeaIndex (1000004 ), " 5" );
249+ ASSERT_THAT (feahash_.FeaHash2FeaIndex (1010000 ), std::to_string (5 + 1 ));
250+ ASSERT_THAT (feahash_.FeaHash2FeaIndex (1010031 ), std::to_string (5 + 32 ));
251+ ASSERT_THAT (feahash_.FeaHash2FeaIndex (1010127 ), std::to_string (5 + 128 ));
252+ ASSERT_THAT (feahash_.FeaHash2FeaIndex (1020000 ), std::to_string (5 + 128 + 1 ));
253+ ASSERT_THAT (feahash_.FeaHash2FeaIndex (1030000 ), std::to_string (5 + 128 + 1 + 1 ));
254+ ASSERT_THAT (feahash_.FeaHash2FeaIndex (1030001 ), std::to_string (5 + 128 + 1 + 2 ));
255+ ASSERT_THAT (feahash_.FeaHash2FeaIndex (1030511 ), std::to_string (5 + 128 + 1 + 512 ));
256+ ASSERT_THAT (feahash_.FeaHash2FeaIndex (1031023 ), std::to_string (5 + 128 + 1 + 1024 ));
257+ }
258+
259+
209260#endif
0 commit comments