Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Feb 3, 2024
1 parent 3989f24 commit 42f0f19
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 94 deletions.
4 changes: 0 additions & 4 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7827,10 +7827,6 @@ void XgDoTests(void)
assert(xg_str_unescape(L"\\\\abc") == L"\\abc");
assert(xg_str_unescape(L"\\x11T") == L"\021T");
assert(xg_str_unescape(L"\\021T") == L"\021T");

// パターンの単体テスト。
BOOL XgPatternsUnitTest(void);
XgPatternsUnitTest();
#endif
}

Expand Down
90 changes: 0 additions & 90 deletions XWordGiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,96 +536,6 @@ VOID XgSortAndUniquePatterns(patterns_t& patterns)
patterns.erase(last, patterns.end());
}

// パターンの単体テスト。
BOOL XgPatternsUnitTest(void)
{
#ifdef NDEBUG
return TRUE;
#else
auto input = L"PAT1.txt";
auto output = L"PAT2.txt";

// パターンを読み込む。
patterns_t patterns;
if (!XgLoadPatterns(input, patterns)) {
//assert(0);
return FALSE;
}

// ソートして一意化する。
XgSortAndUniquePatterns(patterns);

patterns_t temp_pats;
if (1) {
for (const auto& pat : patterns) {
if (XgIsPatternDividedByBlocks(pat))
continue;
auto transposed = XgTransposePattern(pat);
auto flip_h = XgFlipPatternH(pat);
auto flip_v = XgFlipPatternV(pat);
auto flip_hv = XgFlipPatternH(flip_v);
temp_pats.erase(
std::remove_if(temp_pats.begin(), temp_pats.end(), [&](const XG_PATDATA& pat2) noexcept {
return transposed.text == pat2.text ||
flip_h.text == pat2.text ||
flip_v.text == pat2.text ||
flip_hv.text == pat2.text;
}),
temp_pats.end()
);
temp_pats.push_back(pat);
}
patterns = std::move(temp_pats);
} else {
// 反転・転置したパターンも追加する。
for (const auto& pat : patterns) {
if (XgIsPatternDividedByBlocks(pat))
continue;
auto transposed = XgTransposePattern(pat);
auto flip_h = XgFlipPatternH(pat);
auto flip_v = XgFlipPatternV(pat);
auto flip_hv = XgFlipPatternH(flip_v);
temp_pats.push_back(pat);
temp_pats.push_back(transposed);
temp_pats.push_back(flip_h);
temp_pats.push_back(flip_v);
temp_pats.push_back(flip_hv);
}
patterns = std::move(temp_pats);

std::map<LONG, LONG> map;
for (const auto& pat : patterns) {
map[MAKELONG(pat.num_columns, pat.num_rows)]++;
}

if (FILE *fp = fopen("a.txt", "w"))
{
for (auto& pair : map) {
fprintf(fp, "%u\t%u\t%ld\n", LOWORD(pair.first), HIWORD(pair.first), pair.second);
}
fclose(fp);
}
}

// ソートして一意化する。
XgSortAndUniquePatterns(patterns);

// 概要を出力。
std::unordered_map<XG_Size, int> histogram;
for (auto& pat : patterns) {
const XG_Size siz = { pat.num_rows, pat.num_columns };
histogram[siz]++;
}
for (auto& pair : histogram) {
auto& siz = pair.first;
DOUTW(L"%d x %d: %d\n", siz.m_j, siz.m_i, pair.second);
}

// パターンを書き込む。
return XgSavePatterns(output, patterns);
#endif
}

//////////////////////////////////////////////////////////////////////////////

// 候補があるか?
Expand Down

0 comments on commit 42f0f19

Please sign in to comment.