convenience features (#21)

This commit is contained in:
Sebastian Dine
2026-07-24 08:56:53 +02:00
committed by GitHub
parent ab0e3c5ae2
commit 7cf25d671f
22 changed files with 351 additions and 38 deletions
+1
View File
@@ -28,6 +28,7 @@ add_executable(ccm_core_tests
digibattle99_set_completion_tests.cpp
yugioh_set_completion_tests.cpp
pokemon_set_completion_tests.cpp
set_no_natural_tests.cpp
japanese_pokemon_en_catalog_tests.cpp
japanese_pokemon_set_source_tests.cpp
japanese_pokemon_card_preview_source_tests.cpp
+52
View File
@@ -98,6 +98,34 @@ TEST_SUITE("computePokemonSetCompletion") {
CHECK(rows[1].ownedUnique == 1);
}
TEST_CASE("orders packs by releaseDate then setName") {
PokemonSetCatalog west;
PokemonSetCatalogPack newer;
newer.setId = "sv01";
newer.setName = "Scarlet & Violet";
newer.cards = {{"1", "Sprigatito"}};
PokemonSetCatalogPack older;
older.setId = "base1";
older.setName = "Zoo Set"; // would sort after Scarlet by name
older.cards = {{"4", "Charizard"}};
west.packs.push_back(std::move(newer));
west.packs.push_back(std::move(older));
PokemonSetCatalog emptyAsia;
PokemonCard base = makeOwned(PokemonRegion::West, "base1", "4");
base.set.releaseDate = "1999/01/09";
PokemonCard sv = makeOwned(PokemonRegion::West, "sv01", "1");
sv.id = 2;
sv.set.releaseDate = "2023/03/31";
const auto rows = computePokemonSetCompletion({base, sv}, west, emptyAsia);
REQUIRE(rows.size() == 2);
CHECK(rows[0].setId == "base1");
CHECK(rows[0].releaseDate == "1999/01/09");
CHECK(rows[1].setId == "sv01");
CHECK(rows[1].releaseDate == "2023/03/31");
}
TEST_CASE("region filter isolates catalogs") {
const auto west = westCatalog();
const auto asia = asiaCatalog();
@@ -204,6 +232,30 @@ TEST_SUITE("pokemonChecklistForSet") {
CHECK(list[2].owned == false);
}
TEST_CASE("orders unpadded set numbers numerically") {
PokemonSetCatalog west;
PokemonSetCatalogPack pack;
pack.setId = "base1";
pack.setName = "Base";
// Insert out of order / in lex-favoring order to prove we re-sort.
pack.cards = {
{"100", "Lightning Energy"},
{"1", "Alakazam"},
{"10", "Mewtwo"},
{"2", "Blastoise"},
};
west.packs.push_back(std::move(pack));
PokemonSetCatalog emptyAsia;
const auto list = pokemonChecklistForSet({}, west, emptyAsia,
PokemonRegion::West, "base1");
REQUIRE(list.size() == 4);
CHECK(list[0].setNo == "1");
CHECK(list[1].setNo == "2");
CHECK(list[2].setNo == "10");
CHECK(list[3].setNo == "100");
}
TEST_CASE("asia card does not mark west checklist") {
const auto west = westCatalog();
const auto asia = asiaCatalog();
+40
View File
@@ -0,0 +1,40 @@
#include <doctest/doctest.h>
#include "ccm/util/SetNoNatural.hpp"
#include <algorithm>
#include <string>
#include <vector>
using ccm::compareSetNoNatural;
TEST_SUITE("compareSetNoNatural") {
TEST_CASE("orders pure digits numerically") {
CHECK(compareSetNoNatural("1", "2") < 0);
CHECK(compareSetNoNatural("2", "10") < 0);
CHECK(compareSetNoNatural("10", "100") < 0);
CHECK(compareSetNoNatural("2", "1") > 0);
CHECK(compareSetNoNatural("10", "2") > 0);
}
TEST_CASE("leading zeros tie numerically then lex") {
CHECK(compareSetNoNatural("001", "1") != 0);
CHECK(compareSetNoNatural("1", "001") > 0); // "001" < "1" lexicographically
CHECK(compareSetNoNatural("001", "002") < 0);
CHECK(compareSetNoNatural("001", "001") == 0);
}
TEST_CASE("alpha prefix then numeric run") {
CHECK(compareSetNoNatural("SWSH001", "SWSH002") < 0);
CHECK(compareSetNoNatural("SWSH10", "SWSH2") > 0);
CHECK(compareSetNoNatural("A10", "B2") < 0);
}
TEST_CASE("sorts base-set style list into numeric order") {
std::vector<std::string> nos{"1", "10", "100", "2", "20", "3"};
std::sort(nos.begin(), nos.end(), [](const std::string& a, const std::string& b) {
return compareSetNoNatural(a, b) < 0;
});
CHECK(nos == std::vector<std::string>{"1", "2", "3", "10", "20", "100"});
}
}