Town house, penthouse, estate house and old terraced house join the six properties of the original: bought and sold at the day's price, moving by a few percent every month and paying a monthly rent. The property board shows all ten. Engine: estates.hpp, bank read funds fund:6-9, bank.commit trades them; saved in state/modern.json. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
73 lines
3.5 KiB
C++
73 lines
3.5 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
// The four further properties of the bank (docs/new_engine/immobilien.md) on a synthetic
|
|
// manager: buying and selling at the day's price, the limit, the monthly price move and the rent.
|
|
#include <cstdio>
|
|
|
|
#include "modern/game/estates.hpp"
|
|
|
|
using namespace bmh;
|
|
using namespace bmh::modern;
|
|
|
|
namespace {
|
|
int failures = 0;
|
|
void check(bool ok, const char* what) {
|
|
if (!ok) {
|
|
std::fprintf(stderr, "FAIL: %s\n", what);
|
|
++failures;
|
|
}
|
|
}
|
|
int32_t cash(const ModernState& g) {
|
|
return int32_t(uint32_t(g.manager_records[0x314]) | uint32_t(g.manager_records[0x315]) << 8 | uint32_t(g.manager_records[0x316]) << 16 |
|
|
uint32_t(g.manager_records[0x317]) << 24);
|
|
}
|
|
ModernState world(int32_t euros) {
|
|
ModernState g;
|
|
g.career_id = "career:test";
|
|
g.level = 2;
|
|
g.manager_teams = {0};
|
|
g.manager_records.assign(5 * 0xb0c, 0);
|
|
for (int i = 0; i < 4; ++i) g.manager_records[0x314 + size_t(i)] = uint8_t(uint32_t(euros) >> (8 * i));
|
|
return g;
|
|
}
|
|
} // namespace
|
|
|
|
int main() {
|
|
{
|
|
ModernState g = world(3000000);
|
|
check(estate_price(g, 0) == 450000 && estate_price(g, 1) == 1200000 && estate_price(g, 2) == 280000 && estate_price(g, 3) == 650000 && estate_price(g, 4) == 0,
|
|
"the starting prices");
|
|
check(estate_rent(g, 1) == 4800, "the rent is four per mille of the price a month");
|
|
check(buy_estate(g, 0, 1, 2) && estates_held(g, 0, 1) == 2 && cash(g) == 600000 && estates_value(g, 0) == 2400000, "two penthouses are bought");
|
|
check(!buy_estate(g, 0, 1, 1) && !buy_estate(g, 0, 0, 0) && !buy_estate(g, 0, 4, 1) && !buy_estate(g, 1, 0, 1) && cash(g) == 600000,
|
|
"no purchase beyond the account, of nothing, of an unknown property or without a manager");
|
|
check(!sell_estate(g, 0, 1, 3) && !sell_estate(g, 0, 0, 1), "nothing is sold that is not held");
|
|
const int32_t before = cash(g);
|
|
estates_month(g);
|
|
bool moved_in_range = true;
|
|
for (int k = 0; k < kEstates; ++k) {
|
|
const int64_t base = kEstateBasePrice[size_t(k)], now = estate_price(g, k);
|
|
moved_in_range = moved_in_range && now >= base * 97 / 100 && now <= base * 103 / 100 + 1000 && now % 1000 == 0;
|
|
}
|
|
check(moved_in_range, "a month moves every price by minus two to plus three percent, in whole thousands");
|
|
check(cash(g) == before + 2 * estate_rent(g, 1), "the rent of what he holds is paid at the new price");
|
|
const int32_t price = estate_price(g, 1), held_cash = cash(g);
|
|
check(sell_estate(g, 0, 1, 1) && estates_held(g, 0, 1) == 1 && cash(g) == held_cash + price, "one is sold at the day's price");
|
|
}
|
|
// the limit of twenty pieces, and prices that stay within half and three times the start
|
|
{
|
|
ModernState g = world(100000000);
|
|
check(buy_estate(g, 0, 2, kEstateLimit) && !buy_estate(g, 0, 2, 1), "twenty pieces of a property at most");
|
|
bool bounded = true;
|
|
for (uint32_t month = 0; month < 600; ++month) {
|
|
g.date = month * 30;
|
|
estates_month(g);
|
|
for (int k = 0; k < kEstates; ++k)
|
|
bounded = bounded && estate_price(g, k) >= kEstateBasePrice[size_t(k)] / 2 && estate_price(g, k) <= kEstateBasePrice[size_t(k)] * 3;
|
|
}
|
|
check(bounded, "over fifty years the prices stay between half and three times their start");
|
|
}
|
|
if (failures) return 1;
|
|
std::puts("modern_estates_tests: ok");
|
|
return 0;
|
|
}
|