Browse Source

test: split `group` test suites from `cases`

master
Dnomd343 2 weeks ago
parent
commit
5642c4f28d
  1. 17
      src/core_test/CMakeLists.txt
  2. 1
      src/core_test/cases/all_cases.cc
  3. 1
      src/core_test/cases/basic_ranges.cc
  4. 39
      src/core_test/cases/helper/cases.h
  5. 1
      src/core_test/cases/ranges.cc
  6. 1
      src/core_test/cases/ranges_union.cc
  7. 8
      src/core_test/codec/common_code.cc
  8. 0
      src/core_test/group/group_legacy.cc
  9. 0
      src/core_test/group/group_pro.cc
  10. 0
      src/core_test/group/group_union.cc
  11. 25
      src/core_test/group/helper/cases.h
  12. 2
      src/core_test/group/helper/group_impl.cc
  13. 17
      src/core_test/helper/expect.h

17
src/core_test/CMakeLists.txt

@ -28,10 +28,6 @@ set(KLSK_TEST_CASES_SRC
cases/ranges_union.cc
cases/basic_ranges.cc
cases/all_cases.cc
cases/group_union.cc
cases/group_legacy.cc
cases/helper/group_impl.cc
cases/group_pro.cc
)
add_executable(test_klotski_cases ${KLSK_TEST_CASES_SRC})
@ -40,6 +36,19 @@ add_test(NAME klotski_cases COMMAND test_klotski_cases)
# ------------------------------------------------------------------------------------ #
set(KLSK_TEST_GROUP_SRC
group/group_union.cc
group/group_legacy.cc
group/group_pro.cc
group/helper/group_impl.cc
)
add_executable(test_klotski_group ${KLSK_TEST_GROUP_SRC})
target_link_libraries(test_klotski_group PRIVATE ${KLSK_TEST_DEPS} test_helper)
add_test(NAME klotski_group COMMAND test_klotski_group)
# ------------------------------------------------------------------------------------ #
set(KLSK_TEST_FFI_SRC
ffi/all_cases.cc
)

1
src/core_test/cases/all_cases.cc

@ -2,6 +2,7 @@
#include "helper/hash.h"
#include "helper/cases.h"
#include "helper/expect.h"
#include "helper/fixture.h"
#include "utility/exposer.h"

1
src/core_test/cases/basic_ranges.cc

@ -3,6 +3,7 @@
#include "group/group.h"
#include "helper/hash.h"
#include "helper/cases.h"
#include "helper/expect.h"
#include "helper/fixture.h"
#include "utility/exposer.h"

39
src/core_test/cases/helper/cases.h

@ -1,13 +1,10 @@
#pragma once
#include <array>
#include <algorithm>
#include "group/group.h"
#include "helper/concurrent.h"
// ----------------------------------------------------------------------------------------- //
// TODO: move to `.cc` file
using klotski::cases::Ranges;
using klotski::cases::AllCases;
using klotski::codec::CommonCode;
@ -20,41 +17,11 @@ using klotski::cases::ALL_CASES_NUM_;
using klotski::cases::BASIC_RANGES_NUM;
using klotski::cases::BASIC_RANGES_NUM_;
// TODO: move to global helper
/// All valid klotski heads.
constexpr auto Heads = std::to_array({
0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14
});
// TODO: add NonHeads -> {3, 7, 11, 15}
// ----------------------------------------------------------------------------------------- //
/// Assert that Ranges are sorted and unique.
#define EXPECT_SORTED_AND_UNIQUE(R) \
EXPECT_TRUE(std::ranges::is_sorted(R.begin(), R.end())); \
EXPECT_EQ(std::ranges::adjacent_find(R.begin(), R.end()), R.end()) // no duplicates
/// Assert that two ordered arrays are in a containment relationship.
#define EXPECT_SUBSET(R1, R2) \
EXPECT_TRUE(std::ranges::includes(R1.begin(), R1.end(), R2.begin(), R2.end()))
/// Assert that all CommonCodes generated from head and Ranges are valid.
#define EXPECT_COMMON_CODES(head, ranges) \
for (const auto range : ranges) \
EXPECT_TRUE(CommonCode::check(static_cast<uint64_t>(head) << 32 | range))
// ----------------------------------------------------------------------------------------- //
/// Get the type_id upper limit.
uint32_t group_union_num();
/// Get the group_id upper limit.
uint32_t group_num(uint32_t type_id);
/// Get cases contained in the specified type_id.
const std::vector<CommonCode>& group_union_cases(uint32_t type_id);
/// Get cases contained in the specified type_id and group_id.
const std::vector<CommonCode>& group_cases(uint32_t type_id, uint32_t group_id);
// ----------------------------------------------------------------------------------------- //

1
src/core_test/cases/ranges.cc

@ -1,6 +1,7 @@
#include <gtest/gtest.h>
#include "helper/cases.h"
#include "helper/expect.h"
#include "helper/block_num.h"
#include "group/group.h"

1
src/core_test/cases/ranges_union.cc

@ -2,6 +2,7 @@
#include "helper/hash.h"
#include "helper/cases.h"
#include "helper/expect.h"
#include "ranges/ranges.h"
constexpr std::string_view ALL_CASES_MD5 = "3888e9fab8d3cbb50908b12b147cfb23";

8
src/core_test/codec/common_code.cc

@ -10,6 +10,14 @@
#include "short_code/short_code.h"
#include "common_code/common_code.h"
// TODO: add constexpr test
// TODO: add std::hash test
// TODO: test `std::is_default_constructible`
// TODO: test `std::is_copy_assignable` and `std::is_copy_constructible`
// TODO: test `std::is_move_assignable` and `std::is_move_constructible`
using klotski::codec::RawCode;
using klotski::codec::ShortCode;
using klotski::codec::CommonCode;

0
src/core_test/cases/group_legacy.cc → src/core_test/group/group_legacy.cc

0
src/core_test/cases/group_pro.cc → src/core_test/group/group_pro.cc

0
src/core_test/cases/group_union.cc → src/core_test/group/group_union.cc

25
src/core_test/group/helper/cases.h

@ -0,0 +1,25 @@
#pragma once
#include "group/group.h"
// TODO: move to `.cc` file
using klotski::cases::AllCases;
using klotski::codec::CommonCode;
// ----------------------------------------------------------------------------------------- //
// TODO: using global test helper
/// Get the type_id upper limit.
uint32_t group_union_num();
/// Get the group_id upper limit.
uint32_t group_num(uint32_t type_id);
/// Get cases contained in the specified type_id.
const std::vector<CommonCode>& group_union_cases(uint32_t type_id);
/// Get cases contained in the specified type_id and group_id.
const std::vector<CommonCode>& group_cases(uint32_t type_id, uint32_t group_id);
// ----------------------------------------------------------------------------------------- //

2
src/core_test/cases/helper/group_impl.cc → src/core_test/group/helper/group_impl.cc

@ -1,5 +1,7 @@
#include "cases.h"
#include <algorithm>
#include "helper/block_num.h"
// TODO: multi-threads builder

17
src/core_test/helper/expect.h

@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <algorithm>
#include <gtest/gtest.h>
// ----------------------------------------------------------------------------------------- //
@ -16,3 +17,19 @@ std::string ostream_capture(T obj) {
#define EXPECT_OSTREAM(obj, expect) EXPECT_EQ(ostream_capture(obj), expect)
// ----------------------------------------------------------------------------------------- //
/// Assert that Ranges are sorted and unique.
#define EXPECT_SORTED_AND_UNIQUE(R) \
EXPECT_TRUE(std::ranges::is_sorted(R.begin(), R.end())); \
EXPECT_EQ(std::ranges::adjacent_find(R.begin(), R.end()), R.end()) // no duplicates
/// Assert that two ordered arrays are in a containment relationship.
#define EXPECT_SUBSET(R1, R2) \
EXPECT_TRUE(std::ranges::includes(R1.begin(), R1.end(), R2.begin(), R2.end()))
/// Assert that all CommonCodes generated from head and Ranges are valid.
#define EXPECT_COMMON_CODES(head, ranges) \
for (const auto range : ranges) \
EXPECT_TRUE(CommonCode::check(static_cast<uint64_t>(head) << 32 | range))
// ----------------------------------------------------------------------------------------- //

Loading…
Cancel
Save