85 lines
4.4 KiB
Python
85 lines
4.4 KiB
Python
"""Synthetic family6 allocation boundaries; no real cohorts or row allocation."""
|
|
import copy
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
import unittest
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
|
|
import warrior_cooldown_private_bits as private
|
|
|
|
|
|
def source(family=6):
|
|
return [dict(id=10, family=family, mask=128), dict(id=20, family=family, mask=128),
|
|
dict(id=99, family=family, mask=0)]
|
|
|
|
|
|
def native(ident, mask, family=6):
|
|
return dict(ID=ident+100, SpellID=ident, ModalNextSpell=0, SpellClassSet=family,
|
|
SpellClassMask=[(mask >> (32*i)) & 0xffffffff for i in range(4)])
|
|
|
|
|
|
def target(family=6):
|
|
return [native(10, 1, family), native(20, 2, family), native(99, (1<<127)|3, family)]
|
|
|
|
|
|
CLOSURE = {i:dict(spell_id=i, complete=True) for i in (10,20)}
|
|
|
|
|
|
class FamilyAllocation(unittest.TestCase):
|
|
def test_priest_scope_preserves_input_fields_bits_and_collateral(self):
|
|
old=target(); src=source(); saved=copy.deepcopy((src,old,CLOSURE))
|
|
result=private.allocate(src,old,CLOSURE,[7],family=6)
|
|
self.assertEqual((src,old,CLOSURE),saved)
|
|
self.assertEqual(result['allocations'],[dict(source_bit=7,native_bit=126,spell_ids=[10,20],globally_unused_in_baseline=True)])
|
|
expected=copy.deepcopy(old)
|
|
for row in expected[:2]: row['SpellClassMask'][3] |= 1<<30
|
|
self.assertEqual(result['native_inventory'],expected)
|
|
self.assertEqual([r['id'] for r in result['record_replacements']],[110,120])
|
|
self.assertEqual(result['mapping_profile']['family'],6)
|
|
self.assertEqual(result['mapping_profile']['admitted'],[dict(source_bit=7,native_bit=126,spell_ids=[10,20])])
|
|
self.assertFalse(result['new_parent_definitions_authored'])
|
|
self.assertFalse(result['installable_package'])
|
|
self.assertEqual(private.validate_allocation(result,src,old,CLOSURE,[7],family=6),result)
|
|
|
|
def test_family6_exhaustion_preserves_all_rows(self):
|
|
rows=target(); rows[2]=native(99,(1<<128)-1)
|
|
result=private.allocate(source(),rows,CLOSURE,[7],family=6)
|
|
self.assertEqual(result['native_inventory'],rows)
|
|
self.assertEqual(result['allocations'],[])
|
|
self.assertEqual(result['record_replacements'],[])
|
|
self.assertEqual(result['held_allocations'][0]['reason'],'no-unused-native-class-bit')
|
|
|
|
def test_family6_missing_identity_and_definition_remain_held(self):
|
|
for rows,closure,reason in [(target()[:1]+target()[2:],CLOSURE,'missing-native-class-identities'),
|
|
(target(),{10:CLOSURE[10]},'incomplete-parent-definition-closure')]:
|
|
with self.subTest(reason=reason):
|
|
result=private.allocate(source(),rows,closure,[7],family=6)
|
|
self.assertEqual(result['allocations'],[])
|
|
self.assertEqual(result['native_inventory'],rows)
|
|
self.assertEqual(result['held_allocations'][0]['reason'],reason)
|
|
|
|
def test_family6_existing_exact_route_is_unchanged(self):
|
|
rows=[native(10,1<<45),native(20,1<<45),native(99,1<<127)]
|
|
result=private.allocate(source(),rows,CLOSURE,[7],family=6)
|
|
self.assertEqual(result['native_inventory'],rows)
|
|
self.assertEqual(result['allocations'],[])
|
|
self.assertEqual(result['mapping_profile']['admitted'][0]['native_bit'],45)
|
|
|
|
def test_family6_revalidation_rejects_stale_and_tampered_candidate(self):
|
|
rows=target(); result=private.allocate(source(),rows,CLOSURE,[7],family=6)
|
|
bad=copy.deepcopy(result);bad['native_inventory'][2]['SpellClassMask'][0]=0
|
|
stale=copy.deepcopy(rows);stale[2]['SpellClassMask'][3] |= 1<<30
|
|
for proposal,baseline in [(bad,rows),(result,stale)]:
|
|
with self.assertRaises(ValueError):private.validate_allocation(proposal,source(),baseline,CLOSURE,[7],family=6)
|
|
with self.assertRaises(ValueError):private.validate_allocation(result,source(),rows,CLOSURE,[7],family=4)
|
|
|
|
def test_default_output_matches_frozen_prechange_result(self):
|
|
result=private.allocate(source(4),target(4),CLOSURE,[7])
|
|
digest=hashlib.sha256(json.dumps(result,sort_keys=True,separators=(',',':')).encode()).hexdigest()
|
|
self.assertEqual(digest, 'efef41249c191bcd16aec4ad6edb2793e9678b534fbc16a3a33e815643f0cded')
|
|
self.assertEqual(private.allocate(source(4),target(4),CLOSURE,[7],family=4),result)
|
|
|
|
|
|
if __name__=='__main__':unittest.main(verbosity=2)
|