refactor tests to get rid of duplication (#4358)

* refactor tests to get rid of duplication

* address review comments
This commit is contained in:
Rong Ou
2019-04-12 00:21:48 -07:00
committed by Philip Hyunsu Cho
parent 3078b5944d
commit f4521bf6aa
5 changed files with 50 additions and 67 deletions

View File

@@ -26,23 +26,7 @@ TEST(SparsePageDMatrix, MetaInfo) {
}
TEST(SparsePageDMatrix, RowAccess) {
// Create sufficiently large data to make two row pages
dmlc::TemporaryDirectory tempdir;
const std::string tmp_file = tempdir.path + "/big.libsvm";
CreateBigTestData(tmp_file, 12);
xgboost::DMatrix * dmat = xgboost::DMatrix::Load(
tmp_file + "#" + tmp_file + ".cache", true, false, "auto", 64UL);
EXPECT_TRUE(FileExists(tmp_file + ".cache.row.page"));
// Loop over the batches and count the records
int64_t batch_count = 0;
int64_t row_count = 0;
for (const auto &batch : dmat->GetRowBatches()) {
batch_count++;
row_count += batch.Size();
}
EXPECT_EQ(batch_count, 2);
EXPECT_EQ(row_count, dmat->Info().num_row_);
std::unique_ptr<xgboost::DMatrix> dmat = xgboost::CreateSparsePageDMatrix();
// Test the data read into the first row
auto &batch = *dmat->GetRowBatches().begin();
@@ -50,8 +34,6 @@ TEST(SparsePageDMatrix, RowAccess) {
ASSERT_EQ(first_row.size(), 3);
EXPECT_EQ(first_row[2].index, 2);
EXPECT_EQ(first_row[2].fvalue, 20);
delete dmat;
}
TEST(SparsePageDMatrix, ColAccess) {