Add channel-limited cellular uptake proposal
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m53s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (client) (push) Canceled after 3m14s
Foundation / checks (checks) (push) Canceled after 3m19s
Foundation / checks (network) (push) Canceled after 1m19s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m53s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (client) (push) Canceled after 3m14s
Foundation / checks (checks) (push) Canceled after 3m19s
Foundation / checks (network) (push) Canceled after 1m19s
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
#include "evo/biology/cellular_uptake.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <source_location>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
using namespace evo::biology;
|
||||
using evo::accounting::Inventory;
|
||||
void check(bool value, std::source_location at = std::source_location::current()) {
|
||||
if (!value)
|
||||
throw std::runtime_error("cellular uptake line " + std::to_string(at.line()));
|
||||
}
|
||||
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
|
||||
|
||||
MetabolicBudget budget() {
|
||||
MetabolicBudget result{};
|
||||
result.rate_microseconds = 1'000'000;
|
||||
result.intake_limit = {{1'001}, {{{101}, {53}, {31}, {17}}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
void channel_limited_atomic_proposal() {
|
||||
constexpr auto maximum = std::numeric_limits<std::uint64_t>::max();
|
||||
const Inventory patch{{101}, {{{100}, {1}, {100}, {50}}}};
|
||||
const Inventory reserve{{49}, {{{maximum - 3}, {0}, {0}, {0}}}};
|
||||
const auto result = propose_cellular_uptake(patch, reserve, budget());
|
||||
CHECK(result);
|
||||
CHECK(result->acquired == Inventory{{50}, {{{3}, {1}, {1}, {0}}}});
|
||||
CHECK(result->patch_after == Inventory{{51}, {{{97}, {0}, {99}, {50}}}});
|
||||
CHECK(result->reserve_after == Inventory{{99}, {{{maximum}, {1}, {1}, {0}}}});
|
||||
CHECK(result->patch_after.energy.value + result->reserve_after.energy.value ==
|
||||
patch.energy.value + reserve.energy.value);
|
||||
for (std::size_t channel = 0; channel < patch.matter.size(); ++channel) {
|
||||
CHECK(patch.matter[channel].value - result->patch_after.matter[channel].value ==
|
||||
result->acquired.matter[channel].value);
|
||||
CHECK(result->reserve_after.matter[channel].value - reserve.matter[channel].value ==
|
||||
result->acquired.matter[channel].value);
|
||||
}
|
||||
}
|
||||
|
||||
void empty_and_full_channels() {
|
||||
constexpr auto maximum = std::numeric_limits<std::uint64_t>::max();
|
||||
const auto no_stock = propose_cellular_uptake({}, {}, budget());
|
||||
CHECK(no_stock && no_stock->acquired == Inventory{} && no_stock->patch_after == Inventory{});
|
||||
|
||||
Inventory patch{};
|
||||
patch.energy.value = maximum;
|
||||
patch.matter.fill({maximum});
|
||||
Inventory reserve{};
|
||||
reserve.energy.value = maximum;
|
||||
reserve.matter.fill({maximum});
|
||||
const auto full = propose_cellular_uptake(patch, reserve, budget());
|
||||
CHECK(full && full->acquired == Inventory{});
|
||||
CHECK(full->patch_after == patch && full->reserve_after == reserve);
|
||||
}
|
||||
|
||||
void unsupported_rate_period() {
|
||||
auto invalid = budget();
|
||||
invalid.rate_microseconds = 50'000;
|
||||
CHECK(!propose_cellular_uptake({}, {}, invalid));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
try {
|
||||
channel_limited_atomic_proposal();
|
||||
empty_and_full_channels();
|
||||
unsupported_rate_period();
|
||||
std::puts("PASS cellular uptake: finite channel limits and atomic proposal");
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "%s\n", error.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user