From 1f6a12b02d2e0ab983d6c673b57dc13364ca1f1d Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 1 May 2023 16:37:42 +0800 Subject: [PATCH] test: add group cases fast mode test --- test/group/group_info.cc | 48 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/test/group/group_info.cc b/test/group/group_info.cc index c5fda49..34f31a9 100644 --- a/test/group/group_info.cc +++ b/test/group/group_info.cc @@ -68,4 +68,50 @@ TEST(Group, group_info) { pool.boot().join(); } -// TODO: add group_info FAST mode +TEST(Group, group_info_fast_invalid) { + GroupCase::speed_up(); // switch into fast mode + + SHOULD_PANIC(GroupCase::parse(GroupCase::info_t { + .type_id = TYPE_ID_LIMIT, + .group_id = 0, + .group_index = 0, + })) + + SHOULD_PANIC(GroupCase::parse(GroupCase::info_t { + .type_id = 0, + .group_id = static_cast(GroupType(0).group_num()), + .group_index = 0, + })) + + SHOULD_PANIC(GroupCase::parse(GroupCase::info_t { + .type_id = 0, + .group_id = 0, + .group_index = Group(0, 0).size(), + })) +} + +TEST(Group, group_info_fast) { + auto test = [](GroupType group_type) { + for (uint32_t group_id = 0; group_id < group_type.group_num(); ++group_id) { + auto cases = CommonCode::convert(Group(group_type, group_id).cases()); + std::sort(cases.begin(), cases.end()); + + for (uint32_t group_index = 0; group_index < cases.size(); ++group_index) { + auto info = GroupCase::info_t { + .type_id = static_cast(group_type.unwrap()), + .group_id = static_cast(group_id), + .group_index = group_index, + }; + EXPECT_EQ(cases[group_index], GroupCase::parse(info)); + EXPECT_EQ(info, GroupCase::encode(cases[group_index])); + } + } + }; + + auto pool = TinyPool(); + GroupCase::speed_up(); // entry fast mode + for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) { + pool.submit(test, GroupType(type_id)); + } + pool.boot().join(); +}