Files
Dreierpack-Manager/tests/modern_winners_read_tests.cpp
T

33 lines
2.3 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
#include "modern/content/statistics.hpp"
#include "modern/game/modern_state.hpp"
#include <iostream>
#include <stdexcept>
using namespace bmh::modern;
namespace {
using J=bmh::cli::Json;using O=J::Object;
const J& at(const J& v,const char *key){return v.object()->at(key);}
void check(bool value,const char *why){if(!value)throw std::runtime_error(why);}
std::string club(const J& view,size_t column){return *at(at(at(view,"rows").array()->at(0),"cells").array()->at(column),"club").string();}
}
int main()try{
ModernState g;g.manager_teams={0};g.manager_records.resize(0xb0c);g.display_start_year=2026;auto &s=g.almanac.current;s.season=0;s.start_year=2026;
for(int i=0;i<8;++i)s.club({"club:"+std::to_string(i),"Synthetic club "+std::to_string(i)});
// Real cup-table indices: 1 UEFA, 2 Champions League, 3 Cup Winners, 8 Supercup.
for(int cup:{1,2,3,8})s.winners.push_back({uint8_t(cup+1),0xff,0xff,0,100,uint16_t(cup==8?4:cup),0xffff});
s.winners.push_back({0,0,0xff,0,100,5,0xffff});s.winners.push_back({1,0xff,0xff,0,100,6,0xffff});s.winners.push_back({0,6,0xff,0,100,7,0xffff});
const auto previous=s;
const auto europe=query_statistics_screen(g,0,O{{"section",7},{"category",1}});
check(at(europe,"ok").boolean()&&*at(europe,"ok").boolean(),"European read unavailable");
check(club(europe,1)=="club:2","Champions League column names another cup's winner");
check(club(europe,2)=="club:3","Cup Winners column names another cup's winner");
check(club(europe,3)=="club:1","UEFA column names another cup's winner");
const auto de=query_statistics_screen(g,0,O{{"section",7},{"category",0}});
check(at(de,"columns").array()->size()==4,"German Supercup column missing");
check(club(de,1)=="club:5"&&club(de,2)=="club:6"&&club(de,3)=="club:4","German winners do not use their recorded competitions");
const auto en=query_statistics_screen(g,0,O{{"section",7},{"category",0},{"winner_country","nation:en"}});
check(club(en,1)=="club:7","foreign championship winner differs");
check(*at(at(en,"columns").array()->at(1),"trophy").string()=="en-premier-league","foreign championship has wrong trophy role");
check(g.almanac.current==previous,"winner queries modified archive");std::cout<<"winners: distinct European cups, Supercup and foreign trophy roles passed\n";return 0;
}catch(const std::exception &e){std::cerr<<e.what()<<'\n';return 1;}