From 5a2b0c4f7b9b3c510833595faa6beaca803683c0 Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Thu, 3 Oct 2024 17:53:26 +0800 Subject: [PATCH] Test. --- tests/cpp/common/test_compressed_iterator.cc | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/cpp/common/test_compressed_iterator.cc b/tests/cpp/common/test_compressed_iterator.cc index 93243c0b336e..41280dde7fa7 100644 --- a/tests/cpp/common/test_compressed_iterator.cc +++ b/tests/cpp/common/test_compressed_iterator.cc @@ -1,9 +1,25 @@ +/** + * Copyright 2017-2024, XGBoost contributors + */ #include "../../../src/common/compressed_iterator.h" #include "gtest/gtest.h" #include -namespace xgboost { -namespace common { +namespace xgboost::common { +TEST(CompressedIterator, Size) { + bst_idx_t n = 2048; + { + bst_idx_t n_symbols = 256; + auto n_bytes = CompressedBufferWriter::CalculateBufferSize(n, n_symbols); + ASSERT_EQ(n_bytes, 2052); + } + { + bst_idx_t n_symbols = 64; + auto n_bytes = CompressedBufferWriter::CalculateBufferSize(n, n_symbols); + ASSERT_EQ(n_bytes, 1540); + } +} + TEST(CompressedIterator, Test) { ASSERT_TRUE(detail::SymbolBits(256) == 8); ASSERT_TRUE(detail::SymbolBits(150) == 8); @@ -50,6 +66,4 @@ TEST(CompressedIterator, Test) { } } } - -} // namespace common -} // namespace xgboost +} // namespace xgboost::common