#!/usr/bin/env python3
"""Original oracle strings plus explicitly model-only additional boundaries."""
import importlib.util
import json
import struct
from pathlib import Path
R=Path(__file__).resolve().parent
BASE=R.parent
P=json.loads((BASE/'c-literal-rint-proposal-20261011/proposal.json').read_bytes())
spec=importlib.util.spec_from_file_location('algebra',BASE/'c-literal-rint-execution-20261011/analyze-evidence.py')
A=importlib.util.module_from_spec(spec);spec.loader.exec_module(A)
cases=[]
for i,o in enumerate(P['oracles']):
    lex=o['original_lexeme'];m=A.algebra(None if lex is None else float(lex))
    cases.append({'case_id':'ORACLE-%02d'%(i+1),'original_input':lex,
                  'provenance':o['preferred_stored_oracle']['kind'],
                  'expected_parse64_hex':m['x']['native_double_hex'],
                  'expected_stored_double_hex':o['preferred_stored_oracle']['stored_promoted_double']['native_double_hex'],
                  'expected_direct_getter_hex':o['physical_getter']['native_double_hex'],
                  'source_model_stage_hex':{k:m[k]['native_double_hex'] for k in ['whole','scaled','lower_i','rounded_i','quantized','cap','clipped']},
                  'expected_was_clipped':None if lex is None else m['quantized']['native_double_hex']!=m['clipped']['native_double_hex']})
extra=['0.12499999999999999','0.12500000000000003','-0.12499999999999999','-0.12500000000000003',
       '2.675','-2.675','999999.985','-999999.995','0.015','-0.015','1e-300','-1e-300',
       '1.7976931348623157e308','-1.7976931348623157e308','0.025','-0.025']
for i,lex in enumerate(extra):
    m=A.algebra(float(lex))
    x=struct.unpack('<d',bytes.fromhex(m['stored_double']['native_double_hex']))[0]
    cases.append({'case_id':'MODEL-ONLY-%02d'%(i+1),'original_input':lex,'provenance':'EXTRA_BINARY64_SOURCE_MODEL_ONLY_NOT_DB_OBSERVED',
                  'expected_parse64_hex':m['x']['native_double_hex'],'expected_stored_double_hex':m['stored_double']['native_double_hex'],
                  'expected_direct_getter_hex':struct.pack('<d',float(format(x,'.2f'))).hex(),
                  'source_model_stage_hex':{k:m[k]['native_double_hex'] for k in ['whole','scaled','lower_i','rounded_i','quantized','cap','clipped']},
                  'expected_was_clipped':m['quantized']['native_double_hex']!=m['clipped']['native_double_hex']})
print(json.dumps({'original_distinct_oracle_cases':43,'additional_model_only_cases':16,'cases':cases,
                  'negative_preconditions':['','not-a-number','NaN','INF','1e309',True,[],{},12.345]},indent=2))
