xcdat/tests/test_compact_vector.cpp

42 lines
1 KiB
C++
Raw Permalink Normal View History

2021-06-25 22:12:17 +00:00
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <algorithm>
#include <random>
#include "doctest/doctest.h"
2021-06-26 14:48:29 +00:00
#include "test_common.hpp"
#include "xcdat/compact_vector.hpp"
2021-06-25 22:12:17 +00:00
2021-06-27 05:06:08 +00:00
TEST_CASE("Test compact_vector (zero)") {
2021-06-26 14:48:29 +00:00
std::vector<std::uint64_t> ints = {0, 0, 0, 0, 0};
xcdat::compact_vector cv(ints);
2021-06-25 22:12:17 +00:00
2021-06-26 14:48:29 +00:00
REQUIRE_EQ(cv.size(), ints.size());
2021-06-25 22:12:17 +00:00
2021-06-26 14:48:29 +00:00
for (std::uint64_t i = 0; i < ints.size(); i++) {
REQUIRE_EQ(cv[i], ints[i]);
2021-06-25 22:12:17 +00:00
}
}
2021-06-27 05:06:08 +00:00
TEST_CASE("Test compact_vector (tiny)") {
2021-06-25 22:12:17 +00:00
std::vector<std::uint64_t> ints = {2, 0, 14, 456, 32, 5544, 23};
xcdat::compact_vector cv(ints);
REQUIRE_EQ(cv.size(), ints.size());
for (std::uint64_t i = 0; i < ints.size(); i++) {
REQUIRE_EQ(cv[i], ints[i]);
}
}
2021-06-27 05:06:08 +00:00
TEST_CASE("Test compact_vector (random)") {
2021-06-26 14:48:29 +00:00
std::vector<std::uint64_t> ints = xcdat::test::make_random_ints(10000, 0, UINT16_MAX);
2021-06-25 22:12:17 +00:00
xcdat::compact_vector cv(ints);
REQUIRE_EQ(cv.size(), ints.size());
for (std::uint64_t i = 0; i < ints.size(); i++) {
REQUIRE_EQ(cv[i], ints[i]);
}
}