Files
scylladb/test/boost/pretty_printers_test.cc
Kefu Chai a8254111ef utils: drop operator<< for pretty printers
since all callers of these operators have switched to fmt formatters.
let's drop them. the tests are updated accordingly.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2023-07-17 14:02:13 +08:00

56 lines
1.5 KiB
C++

/*
* Copyright (C) 2023-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#define BOOST_TEST_MODULE utils
#include <iterator>
#include <boost/test/unit_test.hpp>
#include "utils/pretty_printers.hh"
BOOST_AUTO_TEST_CASE(test_print_data_size) {
struct {
size_t n;
std::string_view formatted;
} sizes[] = {
{0ULL, "0 bytes"},
{1ULL, "1 byte"},
{42ULL, "42 bytes"},
{10'000ULL, "10kB"},
{10'000'000ULL, "10MB"},
{10'000'000'000ULL, "10GB"},
{10'000'000'000'000ULL, "10TB"},
{10'000'000'000'000'000ULL, "10PB"},
{10'000'000'000'000'000'000ULL, "10000PB"},
};
for (auto [n, expected] : sizes) {
std::string actual;
fmt::format_to(std::back_inserter(actual), "{}", utils::pretty_printed_data_size{n});
BOOST_CHECK_EQUAL(actual, expected);
}
}
BOOST_AUTO_TEST_CASE(test_print_throughput) {
struct {
size_t n;
float seconds;
std::string_view formatted;
} sizes[] = {
{0ULL, 0.F, "0 bytes/s"},
{42ULL, 0.F, "0 bytes/s"},
{42ULL, 1.F, "42 bytes/s"},
{42ULL, 0.5F, "84 bytes/s"},
{10'000'000ULL, 1.F, "10MB/s"},
{10'000'000ULL, 0.5F, "20MB/s"},
};
for (auto [n, seconds, expected] : sizes) {
std::string actual;
fmt::format_to(std::back_inserter(actual), "{}", utils::pretty_printed_throughput{n, std::chrono::duration<float>(seconds)});
BOOST_CHECK_EQUAL(actual, expected);
}
}