"""Checks expected outputs and meaningful boundaries; errors exit nonzero."""
import copy,json,sys
from pathlib import Path
from calculate import calculate
def main():
 d=json.loads(Path(__file__).with_name("data.json").read_text())
 expected={"positive_share":"7/10","confirmed_share":"11/14","fulfilled_after_confirmation":"4/5","fulfilled_all":"11/25","capacity_with_followup":10,"ordinary_result":30000,"bundle_result":28000,"bundle_threshold":85}
 if calculate(d)!=expected:raise AssertionError("Fixed example differs")
 changed=copy.deepcopy(d);changed["minutes"]=30
 if calculate(changed)["capacity_with_followup"]!=4:raise AssertionError("Changed capacity")
 changed=copy.deepcopy(d);changed["minutes"]=10
 if calculate(changed)["capacity_with_followup"]!=0:raise AssertionError("Zero capacity")
 # Independent neighboring integer checks, without calling threshold formula.
 if 84*450-8000!=29800 or 85*450-8000!=30250:raise AssertionError("Independent order bounds")
 bads=[]
 for k,v in (("confirmed",111),("requests",0),("check_minutes",0),("minutes",9),("bundle_setup",-1)):
  bad=copy.deepcopy(d);bad[k]=v;bads.append(bad)
 for bad in bads:
  try:calculate(bad)
  except ValueError:pass
  else:raise AssertionError("Invalid input accepted")
 print(json.dumps({"fixed_example":True,"changed_minutes":30,"zero_capacity":True,"independent_order_bounds":[29800,30250],"invalid_inputs_rejected":len(bads)}))
if __name__=="__main__":
 try:main()
 except Exception as error:
  print("FAIL: "+str(error),file=sys.stderr);sys.exit(1)
