Files
WoW-Hybrid-gateway/tests/spell_modifier_groups_test.py

44 lines
2.1 KiB
Python

import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
from spell_modifier_groups import partition
def modifier(mask, op=10, aura=107, exception=False):
return dict(family=3, operation=op, aura=aura, application_mask=mask,
arcane_icon_exception=exception)
class Groups(unittest.TestCase):
def test_one_aura_intersection_is_counted_once(self):
targets=[dict(id=i+1,family=3,mask=m) for i,m in enumerate([1,2,3,4])]
result=partition(targets,[modifier(3)],family=3)
self.assertEqual(result['groups'],[dict(spell_ids=[1,2,3],responses=[0])])
# Independently applicable modifiers must split all three response sets.
split=partition(targets,[modifier(1),modifier(2)],family=3)
self.assertEqual(len(split['groups']),3)
self.assertEqual(split['groups'][2]['responses'],[0,1])
def test_op_and_kind_keep_different_response_sets(self):
targets=[dict(id=1,family=3,mask=1),dict(id=2,family=3,mask=2)]
result=partition(targets,[modifier(1,8,108),modifier(2,10,107)],family=3)
self.assertEqual(len(result['groups']),2)
self.assertNotEqual(result['groups'][0]['responses'],result['groups'][1]['responses'])
def test_arcane_exception_includes_zero_mask_and_requires_school(self):
targets=[dict(id=1,family=3,mask=0,school=6),dict(id=2,family=3,mask=1,school=2),dict(id=3,family=3,mask=0,school=2)]
result=partition(targets,[modifier(1,15,108,True)],family=3)
self.assertEqual(result['groups'][0]['spell_ids'],[1,2])
del targets[0]['school']
with self.assertRaises(ValueError):partition(targets,[modifier(1,15,108,True)],family=3)
def test_order_and_duplicate_definitions_do_not_change_partition(self):
targets=[dict(id=2,family=3,mask=2),dict(id=1,family=3,mask=1)]
mods=[modifier(1),modifier(2)]
self.assertEqual(partition(targets,mods,family=3),partition(targets[::-1],mods[::-1]+mods,family=3))
with self.assertRaises(ValueError):partition(targets+targets,mods,family=3)
if __name__=='__main__':unittest.main()