69 lines
4.0 KiB
C++
69 lines
4.0 KiB
C++
#include "gateway/profession_delta.hpp"
|
|
#ifdef NDEBUG
|
|
#undef NDEBUG
|
|
#endif
|
|
#include <cassert>
|
|
#include <iostream>
|
|
#include <map>
|
|
using namespace gateway;
|
|
int main(){
|
|
constexpr unsigned start=718;
|
|
ProfessionSkillState state;
|
|
std::map<unsigned,uint32_t> blank,update;
|
|
assert(!state.initialized() && state.observe(blank,start).rows.empty());
|
|
// Missing fields in the initial full create are known zero, not unknown.
|
|
state.initialize(blank,start);
|
|
update={{start+30,186},{start+31,1u|(75u<<16)}};
|
|
auto learned=state.observe(update,start);
|
|
assert(learned.slot_mask==1 && learned.slots[0]==186 && learned.slots[1]==0);
|
|
assert(learned.rows.size()==2 && learned.rows[0].slot==10 && learned.rows[0].step==1);
|
|
assert(learned.rows[1].id==2946 && learned.rows[1].rank==1 && learned.rows[1].maximum==75);
|
|
// A lone bonus word must preserve the source ID/rank/cap.
|
|
update={{start+32,0x0003fff9}};
|
|
auto bonus=state.observe(update,start);
|
|
assert(!bonus.slot_mask && bonus.rows.size()==2);
|
|
assert(bonus.rows[0].id==186 && bonus.rows[0].rank==1 && bonus.rows[0].temporary==65529);
|
|
assert(bonus.rows[1].id==2946 && bonus.rows[1].permanent==3);
|
|
update={{start+60,182},{start+61,7u|(75u<<16)}};
|
|
auto herb=state.observe(update,start);
|
|
assert(herb.slot_mask==2 && herb.slots[0]==186 && herb.slots[1]==182);
|
|
// Native slots are stable: removing slot zero must not move the other line.
|
|
update={{start+30,0},{start+31,0},{start+32,0}};
|
|
auto removed=state.observe(update,start);
|
|
assert(removed.slot_mask==1 && removed.slots[0]==0 && removed.slots[1]==182);
|
|
assert(removed.rows[0].slot==10 && removed.rows[0].id==0);
|
|
assert(removed.rows[1].id==2946 && removed.rows[1].starting==1 && removed.rows[1].rank==0);
|
|
update={{start+15,164},{start+16,1u|(75u<<16)}};
|
|
auto smith=state.observe(update,start);
|
|
assert(smith.slot_mask==1 && smith.slots[0]==164 && smith.slots[1]==182);
|
|
// A third primary in an earlier Source slot must preserve both current
|
|
// summary slots, while publishing its real skill and child view.
|
|
update={{start+3,171},{start+4,1u|(75u<<16)}};
|
|
auto third=state.observe(update,start);
|
|
assert(!third.slot_mask && third.slots[0]==164 && third.slots[1]==182);
|
|
assert(third.rows.size()==2 && third.rows[0].id==171 && third.rows[1].id==2937);
|
|
// Duplicate learned lines remain malformed, and validation is transactional.
|
|
update={{start+6,171},{start+7,2u|(75u<<16)}};
|
|
try{(void)state.observe(update,start);assert(false);}catch(const Error&){}
|
|
update={{start+61,8u|(75u<<16)}};
|
|
auto rank=state.observe(update,start);
|
|
assert(rank.slot_mask==0 && rank.slots[0]==164 && rank.slots[1]==182);
|
|
assert(rank.rows[0].id==182 && rank.rows[0].rank==8);
|
|
assert(rank.rows[1].id==2944 && rank.rows[1].rank==8);
|
|
// Freeing one summary slot promotes the third without moving its survivor.
|
|
auto promoted=state.observe(std::map<unsigned,uint32_t>{{start+15,0},{start+16,0}},start);
|
|
assert(promoted.slot_mask==1 && promoted.slots[0]==171 && promoted.slots[1]==182);
|
|
// A later valid update proves the rejected duplicate was not committed.
|
|
auto after=state.observe(std::map<unsigned,uint32_t>{{start+4,3u|(75u<<16)}},start);
|
|
assert(!after.slot_mask && after.rows[0].id==171 && after.rows[0].rank==3);
|
|
state.clear();assert(!state.initialized() && state.observe(update,start).rows.empty());
|
|
// A fresh create discards the prior character generation and derives the
|
|
// complete Source state even when unchanged zero words are omitted.
|
|
std::map<unsigned,uint32_t> initial={{start+9,182},{start+10,17u|(150u<<16)}};
|
|
state.initialize(initial,start);
|
|
auto promote=state.observe(std::map<unsigned,uint32_t>{{start+10,18u|(225u<<16)}},start);
|
|
assert(!promote.slot_mask && promote.slots[0]==182 && promote.slots[1]==0);
|
|
assert(promote.rows.size()==2 && promote.rows[0].step==3 && promote.rows[1].step==3);
|
|
std::cout<<"Profession snapshot, sparse updates, stable slots and removals passed\n";
|
|
}
|