forked from Mirrors/privacore-open-source-search-engine
More RdbIndex unit test
This commit is contained in:
@ -9,7 +9,119 @@ static bool addPosdbKey(RdbBuckets *buckets, int64_t termId, int64_t docId, int3
|
||||
buckets->addNode(0, key, NULL, 0);
|
||||
}
|
||||
|
||||
TEST(RdbIndexTest, GenerateFromBucketMultipleTermIdSingleDocId) {
|
||||
// 000
|
||||
TEST(RdbIndexTest, GenerateFromBucketSingleTermIdSingleDocIdSingleWordPos) {
|
||||
RdbBuckets buckets;
|
||||
buckets.set(Posdb::getFixedDataSize(), 1024 * 1024, "test-posdb", RDB_POSDB, "posdb", Posdb::getKeySize());
|
||||
|
||||
static const int64_t termId = 1;
|
||||
static const int64_t docId = 1;
|
||||
static const int32_t wordPos = 0;
|
||||
|
||||
addPosdbKey(&buckets, termId, docId, wordPos);
|
||||
|
||||
RdbIndex index;
|
||||
index.set("./", "test-posdbidx", Posdb::getFixedDataSize(), Posdb::getUseHalfKeys(), Posdb::getKeySize(), RDB_POSDB);
|
||||
index.generateIndex(0, &buckets);
|
||||
|
||||
auto docIds = index.getDocIds();
|
||||
EXPECT_EQ(1, docIds->size());
|
||||
EXPECT_EQ(docId, (*docIds.get())[0]);
|
||||
}
|
||||
|
||||
// 001
|
||||
TEST(RdbIndexTest, GenerateFromBucketSingleTermIdSingleDocIdMultipleWordPos) {
|
||||
RdbBuckets buckets;
|
||||
buckets.set(Posdb::getFixedDataSize(), 1024 * 1024, "test-posdb", RDB_POSDB, "posdb", Posdb::getKeySize());
|
||||
|
||||
static const int total_records = 10;
|
||||
static const int64_t termId = 1;
|
||||
static const int64_t docId = 1;
|
||||
|
||||
for (int i = 0; i < total_records; ++i) {
|
||||
addPosdbKey(&buckets, termId, docId, i);
|
||||
}
|
||||
|
||||
RdbIndex index;
|
||||
index.set("./", "test-posdbidx", Posdb::getFixedDataSize(), Posdb::getUseHalfKeys(), Posdb::getKeySize(), RDB_POSDB);
|
||||
index.generateIndex(0, &buckets);
|
||||
|
||||
auto docIds = index.getDocIds();
|
||||
EXPECT_EQ(1, docIds->size());
|
||||
EXPECT_EQ(docId, (*docIds.get())[0]);
|
||||
}
|
||||
|
||||
// 010
|
||||
TEST(RdbIndexTest, GenerateFromBucketSingleTermIdMultipleDocIdSingleWordPos) {
|
||||
RdbBuckets buckets;
|
||||
buckets.set(Posdb::getFixedDataSize(), 1024 * 1024, "test-posdb", RDB_POSDB, "posdb", Posdb::getKeySize());
|
||||
|
||||
static const int total_records = 10;
|
||||
static const int64_t termId = 1;
|
||||
static const int32_t wordPos = 0;
|
||||
|
||||
for (int i = 0; i < total_records; ++i) {
|
||||
addPosdbKey(&buckets, termId, i, wordPos);
|
||||
}
|
||||
|
||||
RdbIndex index;
|
||||
index.set("./", "test-posdbidx", Posdb::getFixedDataSize(), Posdb::getUseHalfKeys(), Posdb::getKeySize(), RDB_POSDB);
|
||||
index.generateIndex(0, &buckets);
|
||||
|
||||
auto docIds = index.getDocIds();
|
||||
EXPECT_EQ(total_records, docIds->size());
|
||||
for (int i = 0; i < total_records; ++i) {
|
||||
EXPECT_EQ(i, (*docIds.get())[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// 011
|
||||
TEST(RdbIndexTest, GenerateFromBucketSingleTermIdMultipleDocIdMultipleWordPos) {
|
||||
RdbBuckets buckets;
|
||||
buckets.set(Posdb::getFixedDataSize(), 1024 * 1024, "test-posdb", RDB_POSDB, "posdb", Posdb::getKeySize());
|
||||
|
||||
static const int total_records = 10;
|
||||
static const int64_t termId = 1;
|
||||
|
||||
for (int i = 0; i < total_records; ++i) {
|
||||
addPosdbKey(&buckets, termId, i, i);
|
||||
}
|
||||
|
||||
RdbIndex index;
|
||||
index.set("./", "test-posdbidx", Posdb::getFixedDataSize(), Posdb::getUseHalfKeys(), Posdb::getKeySize(), RDB_POSDB);
|
||||
index.generateIndex(0, &buckets);
|
||||
|
||||
auto docIds = index.getDocIds();
|
||||
EXPECT_EQ(total_records, docIds->size());
|
||||
for (int i = 0; i < total_records; ++i) {
|
||||
EXPECT_EQ(i, (*docIds.get())[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// 100
|
||||
TEST(RdbIndexTest, GenerateFromBucketMultipleTermIdSingleDocIdSingleWordPos) {
|
||||
RdbBuckets buckets;
|
||||
buckets.set(Posdb::getFixedDataSize(), 1024 * 1024, "test-posdb", RDB_POSDB, "posdb", Posdb::getKeySize());
|
||||
|
||||
static const int total_records = 10;
|
||||
static const int64_t docId = 1;
|
||||
static const int32_t wordPos = 1;
|
||||
|
||||
for (int i = 0; i < total_records; i++) {
|
||||
addPosdbKey(&buckets, i, docId, wordPos);
|
||||
}
|
||||
|
||||
RdbIndex index;
|
||||
index.set("./", "test-posdbidx", Posdb::getFixedDataSize(), Posdb::getUseHalfKeys(), Posdb::getKeySize(), RDB_POSDB);
|
||||
index.generateIndex(0, &buckets);
|
||||
|
||||
auto docIds = index.getDocIds();
|
||||
EXPECT_EQ(1, docIds->size());
|
||||
EXPECT_EQ(docId, (*docIds.get())[0]);
|
||||
}
|
||||
|
||||
// 101
|
||||
TEST(RdbIndexTest, GenerateFromBucketMultipleTermIdSingleDocIdMultipleWordPos) {
|
||||
RdbBuckets buckets;
|
||||
buckets.set(Posdb::getFixedDataSize(), 1024 * 1024, "test-posdb", RDB_POSDB, "posdb", Posdb::getKeySize());
|
||||
|
||||
@ -29,14 +141,16 @@ TEST(RdbIndexTest, GenerateFromBucketMultipleTermIdSingleDocId) {
|
||||
EXPECT_EQ(docId, (*docIds.get())[0]);
|
||||
}
|
||||
|
||||
TEST(RdbIndexTest, GenerateFromBucketSingleTermIdMultipleDocId) {
|
||||
// 110
|
||||
TEST(RdbIndexTest, GenerateFromBucketMultipleTermIdMultipleDocIdSingleWordPos) {
|
||||
RdbBuckets buckets;
|
||||
buckets.set(Posdb::getFixedDataSize(), 1024 * 1024, "test-posdb", RDB_POSDB, "posdb", Posdb::getKeySize());
|
||||
|
||||
static const int total_records = 10;
|
||||
static const int32_t wordPos = 0;
|
||||
|
||||
for (int i = 0; i < total_records; ++i) {
|
||||
addPosdbKey(&buckets, 1, i, i);
|
||||
addPosdbKey(&buckets, i, i, wordPos);
|
||||
}
|
||||
|
||||
RdbIndex index;
|
||||
@ -50,7 +164,8 @@ TEST(RdbIndexTest, GenerateFromBucketSingleTermIdMultipleDocId) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(RdbIndexTest, GenerateFromBucketMultipleTermIdMultipleDocId) {
|
||||
// 111
|
||||
TEST(RdbIndexTest, GenerateFromBucketMultipleTermIdMultipleDocIdMultipleWordPos) {
|
||||
RdbBuckets buckets;
|
||||
buckets.set(Posdb::getFixedDataSize(), 1024 * 1024, "test-posdb", RDB_POSDB, "posdb", Posdb::getKeySize());
|
||||
|
||||
|
Reference in New Issue
Block a user