#!/usr/bin/env python3
"""Independent fixed expected feasible boundary, no solver import."""
from pathlib import Path
import json,sys
p=Path(__file__).resolve().parent;r=json.loads((Path(sys.argv[1]) if len(sys.argv)>1 else p/'result.json').read_text(encoding='utf-8'))
# For each B count, leftover implementation bounds A; sales not tighter in these inputs.
expected_base=[(8,0,240000),(5,1,220000),(2,2,200000),(0,3,210000)]
expected_cut=[(5,0,150000),(2,1,130000),(0,2,140000)]
for name,expected in [('base',expected_base),('implementation_cut',expected_cut)]:
 f=r[name]['feasible']
 for a,b,value in expected:
  x=max((x for x in f if x['B']==b),key=lambda x:x['A']);assert (x['A'],x['B'],x['contribution_RUB'])==(a,b,value)
 assert r[name]['max_contribution_RUB']==max(x[2] for x in expected)
 assert all(x['A']*4+x['B']*8<=40 for x in f)
 assert all(x['A']*3+x['B']*8<=(24 if name=='base' else 16) for x in f)
assert r['base']['leaders']==[{'A':8,'B':0,'sales_h':32,'implementation_h':24,'contribution_RUB':240000}]
assert r['implementation_cut']['leaders']==[{'A':5,'B':0,'sales_h':20,'implementation_h':15,'contribution_RUB':150000}]
assert r['no_go']['launch_allowed'] is False
print('PASS: independent resource-boundary table, optimal fixed portfolios, owner gate')
