35 lines
1.9 KiB
Python
35 lines
1.9 KiB
Python
import sys,unittest
|
|
from pathlib import Path
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/"ops"))
|
|
from spell_modifier_overlap import source_union_weights, source_application_weights, apply_weights
|
|
class Overlap(unittest.TestCase):
|
|
def test_one_shared_modifier_counts_once(self):
|
|
w=source_union_weights([0b11],0b11)
|
|
self.assertEqual(apply_weights(w,{0:-500,1:-500}),-500)
|
|
def test_independent_modifiers_both_count(self):
|
|
w=source_union_weights([0b01,0b10],0b11)
|
|
self.assertEqual(apply_weights(w,{0:-500,1:-500}),-1000)
|
|
def test_same_wire_different_authoritative_totals_is_held(self):
|
|
self.assertIsNone(source_union_weights([0b01,0b10,0b11],0b11))
|
|
def test_signed_fractional_weights_recover_actual_aura_sum(self):
|
|
# Three independent two-bit masks, one contribution per aura.
|
|
masks=[0b011,0b101,0b110];w=source_union_weights(masks,0b111)
|
|
self.assertEqual(apply_weights(w,{0:30,1:50,2:40}),60)
|
|
self.assertEqual(apply_weights(w,{0:0,1:0,2:0}),0)
|
|
def test_outside_target_and_duplicate_cohort_rows(self):
|
|
w=source_union_weights([1,1,2],1)
|
|
self.assertEqual(apply_weights(w,{0:7,1:99}),7)
|
|
def test_script_wire_and_application_masks_are_distinct(self):
|
|
w=source_application_weights([(1,2)],2)
|
|
self.assertEqual(apply_weights(w,{0:20}),20)
|
|
self.assertEqual(apply_weights(source_application_weights([(1,2)],1),{0:20}),0)
|
|
def test_same_wire_different_application_cannot_be_guessed(self):
|
|
self.assertIsNone(source_application_weights([(1,1),(1,2)],1))
|
|
def test_all_source_bits_are_available(self):
|
|
w=source_union_weights([1<<63],1<<63)
|
|
self.assertEqual(apply_weights(w,{63:-17}),-17)
|
|
def test_unobserved_required_aggregate_is_not_zero(self):
|
|
w=source_union_weights([1,2],3)
|
|
with self.assertRaises(ValueError):apply_weights(w,{0:3})
|
|
if __name__=="__main__":unittest.main()
|