Skip to content

Commit 649bbe2

Browse files
committed
[Test] Adds test cases.
1 parent 8b51f04 commit 649bbe2

3 files changed

Lines changed: 53 additions & 4 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,5 @@ by the way, in case we want adjust each feature-slot's hash-bucket size, we can
8888

8989
## TODO
9090
* Seperate classes' pybind codes, so when calling cpp interface, do not need linking/building pybind lib.
91-
* Makes `FeaHash::Hash2IndexDictBuild` more solid.
9291
* For discrete-feature, supports multi-hot encoding
9392
* `FeaHash::Hash2IndexDictBuild` should supports rebuild mode.

include/feather/FeaHash.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,15 @@ class FeaHash {
6868

6969
void SchemaLineRegister(const std::vector<std::string>& schema_line);
7070

71+
void Hash2IndexDictBuild();
72+
7173
//void Transfer();
7274

7375
protected:
7476
std::vector<int32_t> FeaVal2FeaHashBucket(FeaValue* fea_val, FeaSlot* fea_slot);
7577

7678
/// for example, bucket id could be 35, bucket code could be '00035'.
7779
std::vector<std::string> FeaVal2FeaHashBucketCode(FeaValue* fea_val, FeaSlot* fea_slot);
78-
79-
void Hash2IndexDictBuild();
80-
8180

8281
private:
8382
std::string conf_path;

test/cpp/cases/FeaHash_test.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)