test: compare preserved playground DTO floats by exact IEEE bits

This commit is contained in:
NINI
2026-10-10 05:55:00 +09:00
parent 9850d2c539
commit 891c7d0072
2 changed files with 72 additions and 4 deletions
+24
View File
@@ -14,6 +14,30 @@ function NativeTouch([int[]]$Contacts) {
if($actualExit-ne0){throw "Actual native gesture failed: $actualExit"}
}
function Clone($Value){return $Value|ConvertTo-Json -Depth 20|ConvertFrom-Json}
function Float32Record($Value,[string]$Parent=''){
if($Value-is[Collections.IDictionary]){
$keys=@($Value.Keys)
foreach($key in $keys){
$isFloat=($Parent-cin@('position','target')-and$key-cin@('x','y','z'))-or($Parent-ceq'rotation'-and$key-cin@('x','y','z','w'))-or($key-ceq'distance'-and$keys-ccontains'target'-and$keys-ccontains'rotation')
if($isFloat){
$number=$Value[$key]
if(($number-isnot[long]-and$number-isnot[double])-or![single]::IsFinite([single]$number)){throw 'Preserved DTO float must be a finite JSON number'}
$Value[$key]='float32:'+([BitConverter]::SingleToInt32Bits([single]$number)).ToString('X8')
}else{Float32Record $Value[$key] $key}
}
}elseif($Value-is[Collections.IList]){foreach($item in $Value){Float32Record $item $Parent}}
}
function Same($First,$Second){
# Only DTO float fields use IEEE754 identity; all keys, array order and other values stay exact.
try{
$records=@(foreach($value in @($First,$Second)){
$copy=ConvertFrom-Json -InputObject (ConvertTo-Json -InputObject $value -Depth 20 -Compress) -AsHashtable -NoEnumerate
Float32Record $copy
ConvertTo-Json -InputObject $copy -Depth 20 -Compress
})
return $records[0]-ceq$records[1]
}catch{return $false}
}
function Slot($State,[string]$Type,[int]$Stage){if($Type-eq'free'){return $State.latestFreePlay};return @($State.puzzleStates|Where-Object stageId -eq $Stage)[0]}
function SameBalls($First,$Second,[double]$Tolerance=.004){
if((($First.balls.id|Sort-Object)-join',')-ne(($Second.balls.id|Sort-Object)-join',')){return $false}