93 lines
5.9 KiB
C++
93 lines
5.9 KiB
C++
#include "gateway/spell_modifier_operations.hpp"
|
|
#include <array>
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <limits>
|
|
using namespace gateway::spell_modifier;
|
|
static unsigned checks;
|
|
static void check(bool ok) { ++checks; if (!ok) { std::cerr << "FAIL " << checks << '\n'; std::exit(1); } }
|
|
int main() {
|
|
// All 34 source numeric slots, including unused holes13/25. Independently
|
|
// enumerated from source/native consumers; NOT generated from helper table.
|
|
constexpr std::array<int,34> expected{{0,1,2,-1,4,5,6,7,8,9,10,11,-1,-1,14,15,16,17,18,19,20,-1,22,-1,24,-1,-1,27,28,38,-1,-1,-1,-1}};
|
|
for (unsigned op=0; op<expected.size(); ++op) {
|
|
auto m=operation_mapping(static_cast<uint8_t>(op));
|
|
check(bool(m)==(expected[op]>=0));
|
|
if (!m) { check(!translate_aggregate(static_cast<uint8_t>(op),Kind::Flat,10,true)); continue; }
|
|
check(m->native_operation==expected[op]);
|
|
auto f=translate_aggregate(static_cast<uint8_t>(op),Kind::Flat,0,true);
|
|
auto pct=translate_aggregate(static_cast<uint8_t>(op),Kind::Percent,0,true);
|
|
check(f && f->value==0.0f); check(pct && pct->value==1.0f);
|
|
}
|
|
// Source .7 chain multiplier plus a flat1 ->1.7; native70+100 ->170/100.
|
|
auto chain=translate_aggregate(20,Kind::Flat,1);
|
|
check(chain && chain->value==100.f && (70.f+chain->value)/100.f==1.7f);
|
|
check(translate_aggregate(20,Kind::Percent,30)->value==1.3f);
|
|
// Source 10seconds +(-2seconds) == native10000ms -2000ms.
|
|
auto proc=translate_aggregate(29,Kind::Flat,-2);
|
|
check(proc && proc->native_operation==38 && 10000+proc->value==8000);
|
|
check(translate_aggregate(29,Kind::Percent,-50)->value==.5f);
|
|
// Both coefficient consumers operate on coeff*100; source flat5 means .05.
|
|
check(translate_aggregate(24,Kind::Flat,5)->value==5.f);
|
|
check(translate_aggregate(27,Kind::Flat,2)->value==2.f);
|
|
check(!translate_aggregate(14,Kind::Flat,-10));
|
|
check(operation_mapping(14)->requires_power_index_zero);
|
|
check(translate_aggregate(14,Kind::Flat,-10,true)->value==-10.f);
|
|
// Replacements: receiving +20 then +30 means final1.3, not1.56.
|
|
check(translate_aggregate(8,Kind::Percent,20)->value==1.2f);
|
|
check(translate_aggregate(8,Kind::Percent,30)->value==1.3f);
|
|
check(translate_aggregate(8,Kind::Percent,-100)->value==0.f);
|
|
check(translate_aggregate(8,Kind::Percent,-120)->value==-.2f);
|
|
// No rounding or clamping of flat aggregates, including after unit scaling.
|
|
check(translate_aggregate(8,Kind::Flat,16777216).has_value());
|
|
check(!translate_aggregate(8,Kind::Flat,16777217));
|
|
check(!translate_aggregate(29,Kind::Flat,std::numeric_limits<int32_t>::max()));
|
|
check(translate_aggregate(8,Kind::Percent,std::numeric_limits<int32_t>::max()).has_value());
|
|
check(!translate_aggregate(8,static_cast<Kind>(99),1));
|
|
for (unsigned op=34; op<256; ++op) check(!operation_mapping(static_cast<uint8_t>(op)));
|
|
// Producer-qualified target mapping; never a global source30 -> native3 rule.
|
|
const OperationMapping points0{3, 1.0, false};
|
|
check(!operation_mapping(30));
|
|
check(!translate_aggregate(30, Kind::Flat, 50));
|
|
auto qualified=translate_qualified_aggregate(points0, Kind::Flat, 50);
|
|
check(qualified && qualified->native_operation==3 && qualified->value==50.f);
|
|
check(100.f+qualified->value==150.f);
|
|
check(translate_qualified_aggregate(points0,Kind::Flat,100)->value==100.f);
|
|
check(translate_qualified_aggregate(points0,Kind::Flat,0)->value==0.f);
|
|
check(translate_qualified_aggregate(points0,Kind::Flat,-50)->value==-50.f);
|
|
check(translate_qualified_aggregate(points0,Kind::Flat,16777216).has_value());
|
|
check(!translate_qualified_aggregate(points0,Kind::Flat,16777217));
|
|
check(translate_qualified_aggregate(points0,Kind::Flat,std::numeric_limits<int32_t>::min()).has_value());
|
|
check(!translate_qualified_aggregate(points0,Kind::Flat,std::numeric_limits<int32_t>::max()));
|
|
check(translate_qualified_aggregate(points0,Kind::Percent,25)->value==1.25f);
|
|
check(translate_qualified_aggregate(points0,Kind::Percent,0)->value==1.f);
|
|
check(translate_qualified_aggregate(points0,Kind::Percent,-100)->value==0.f);
|
|
check(translate_qualified_aggregate(points0,Kind::Percent,-125)->value==-.25f);
|
|
check(translate_qualified_aggregate(points0,Kind::Percent,std::numeric_limits<int32_t>::max()).has_value());
|
|
check(!translate_qualified_aggregate(points0,static_cast<Kind>(99),1));
|
|
check(!translate_qualified_aggregate({14,1.0,true},Kind::Flat,5));
|
|
check(translate_qualified_aggregate({14,1.0,true},Kind::Flat,5,true)->value==5.f);
|
|
check(!translate_qualified_aggregate({14,1.0,true},Kind::Percent,5));
|
|
check(translate_qualified_aggregate({12,100.0,false},Kind::Flat,2)->value==200.f);
|
|
check(translate_qualified_aggregate({23,100.0,false},Kind::Percent,25)->value==1.25f);
|
|
check(!translate_qualified_aggregate({3,0.1,false},Kind::Flat,1));
|
|
check(!translate_qualified_aggregate({3,std::numeric_limits<double>::max(),false},Kind::Flat,2));
|
|
check(!translate_qualified_aggregate({3,std::numeric_limits<double>::max(),false},Kind::Flat,1));
|
|
for (double bad : {std::numeric_limits<double>::infinity(),std::numeric_limits<double>::quiet_NaN()}) {
|
|
check(!translate_qualified_aggregate({3,bad,false},Kind::Flat,0));
|
|
check(!translate_qualified_aggregate({3,bad,false},Kind::Percent,0));
|
|
}
|
|
// Existing mapped entry point must preserve the exact numerical conversion.
|
|
for (uint8_t op : {uint8_t(8),uint8_t(14),uint8_t(20),uint8_t(29)}) {
|
|
auto mapping=operation_mapping(op);
|
|
for (Kind kind : {Kind::Flat,Kind::Percent}) {
|
|
auto old_api=translate_aggregate(op,kind,-2,true);
|
|
auto new_api=translate_qualified_aggregate(*mapping,kind,-2,true);
|
|
check(old_api && new_api && old_api->native_operation==new_api->native_operation && old_api->value==new_api->value);
|
|
}
|
|
}
|
|
std::cout << checks << " checks PASS\n";
|
|
}
|