Something went wrong. Try again.
[Mirror] Libreopolis is a cross-platform city simulation game fully compatible with SimCity 2000. gitlab.com/conasg/libreopolis
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768// Newspaper (ui/newspaper.hpp) — the recent-headlines model + story-id text. Verifies the disaster// TYPE→story-id map (transcribed from the original's disaster driver), that every fired story id resolves// to a non-empty headline, the queue cap / recency order, and the Extra!!! (auto-open) set.#include "sc2k/ui/newspaper.hpp"#include <cstdio>#include <string>
using namespace sc2k::ui;
#include "test_harness.hpp"
int main() { // Disaster TYPE → story id (the original's tail switch), incl. the shared ids (fire/firestorm=22, etc.). CHECK(news_story_for_disaster(1) == 22); // Fire CHECK(news_story_for_disaster(0xC) == 22); // Fire Storm → same story as Fire CHECK(news_story_for_disaster(2) == 23); // Flood CHECK(news_story_for_disaster(0xE) == 23); // Major Flood → Flood CHECK(news_story_for_disaster(3) == 35); // Riot CHECK(news_story_for_disaster(0xD) == 35); // Mass Riots → Riot CHECK(news_story_for_disaster(6) == 27); // Earthquake CHECK(news_story_for_disaster(7) == 26); // Tornado CHECK(news_story_for_disaster(8) == 28); // Monster CHECK(news_story_for_disaster(9) == 29); // Meltdown CHECK(news_story_for_disaster(0xA) == 30); // Microwave CHECK(news_story_for_disaster(0xB) == 31); // Volcano CHECK(news_story_for_disaster(0x10) == 34); // Hurricane CHECK(news_story_for_disaster(0x12) == 24); // Air Crash CHECK(news_story_for_disaster(99) == -1); // unknown
// Every disaster story id (22..35) resolves to a non-empty headline + body. for (int id = 22; id <= 35; ++id) { std::string h, b; CHECK(news_story_text(id, 0, "Testville", h, b) && !h.empty() && !b.empty()); } // Milestone story 3 names the size tier and substitutes the city name. { std::string h, b; CHECK(news_story_text(3, 3, "Testville", h, b)); CHECK(h.find("Testville") != std::string::npos && h.find("Capital") != std::string::npos); } // A blank city name falls back to "the city" (no empty substitution). { std::string h, b; news_story_text(22, 0, "", h, b); CHECK(h.find("the city") != std::string::npos); }
// Extra!!! (auto-open) set = disasters + the milestone; ordinary civic stories are not. CHECK(Newspaper::is_extra(27) && Newspaper::is_extra(3)); CHECK(!Newspaper::is_extra(1) && !Newspaper::is_extra(20));
// Queue: most-recent-first, capped at kMax. Newspaper np; for (int i = 0; i < Newspaper::kMax + 4; ++i) np.push(27, 0, 3000 + i, i % 12, "Testville"); CHECK(int(np.stories.size()) == Newspaper::kMax); CHECK(np.stories.front().year == 3000 + Newspaper::kMax + 3); // newest at the front CHECK(np.hasUnread); // A story id with no text doesn't enqueue. const std::size_t before = np.stories.size(); CHECK(!np.push(200, 0, 3100, 1, "Testville") && np.stories.size() == before);
if (failures == 0) std::printf("test_newspaper: all checks passed\n"); else std::printf("test_newspaper: %d FAILURES\n", failures); return failures ? 1 : 0;}