<?php
declare(strict_types=1);
$root=$argv[1];require $root.'/thinkphp/base.php';\think\Loader::addNamespace('app',$root.'/application/');
$cases=json_decode(file_get_contents(__DIR__.'/../evidence/front-four-fixed-float-source-oracles.json'),true)['cases'];$checks=0;$failed=[];$unmapped=[];
foreach($cases as$c){$v=$c['input'];foreach(['food_weight'=>8,'ssb'=>8,'saccharides'=>8,'price'=>10]as$f=>$m){
 $out=\app\common\service\DishFixedFloatWrite::value($v,$m,false);
 if(!$out instanceof \think\db\Expression){$unmapped[]=$c['case_id'].'.'.$f;continue;}
 if(!preg_match('/^CAST\((.+) AS REAL\)$/',$out->getValue(),$match))throw new RuntimeException('expression');
 $checks++;if(bin2hex(pack('G',(float)$match[1]))!==$c['expected'][$f]['ieee32_hex'])$failed[]=$c['case_id'].'.'.$f;
}}
echo json_encode(['assertions'=>$checks,'failed'=>$failed,'unmapped_invalid_inputs'=>$unmapped]),PHP_EOL;exit($failed?1:0);
