24 lines
2.3 KiB
PowerShell
24 lines
2.3 KiB
PowerShell
param([Parameter(Mandatory)][string]$EvidenceDir,[string]$SelectorSource=(Join-Path $PSScriptRoot 'exercise-final-progression.ps1'))
|
|
$ErrorActionPreference='Stop'
|
|
New-Item -ItemType Directory -Path $EvidenceDir -Force|Out-Null
|
|
$selector=@(Get-Content -LiteralPath $SelectorSource|Where-Object {$_-match'^\s*\$ids='})[0]
|
|
if(!$selector){throw 'Missing actual SplitReal selection assignment'}
|
|
$checks=[Collections.Generic.List[object]]::new()
|
|
foreach($case in @(@{stage=10;size=1;expected='s10-b01'},@{stage=12;size=2;expected='s10-b01,s10-b02'},@{stage=13;size=2;expected='s10-b01,s10-b05'})){
|
|
$Stage=$case.stage;$Selected=$case.size;$group=[pscustomobject]@{ballIds=@('s10-b01','s10-b02','s10-b03','s10-b04','s10-b05')}
|
|
. ([scriptblock]::Create($selector))
|
|
$passed=$ids-is[array]-and$ids.Count-eq$Selected-and($ids-join',')-eq$case.expected-and$ids[0]-eq's10-b01'
|
|
$checks.Add(@{kind='actual-SplitReal-assignment';stage=$Stage;selected=$Selected;source=$selector;passed=$passed;ids=$ids;firstId=$ids[0];arrayType=$ids.GetType().FullName})
|
|
}
|
|
$ast=[Management.Automation.Language.Parser]::ParseFile((Join-Path $PSScriptRoot 'final-common.ps1'),[ref]$null,[ref]$null)
|
|
$function=$ast.Find({param($n)$n-is[Management.Automation.Language.FunctionDefinitionAst]-and$n.Name-eq'BallPoint'},$true)
|
|
. ([scriptblock]::Create($function.Extent.Text))
|
|
$script:adbCalls=0
|
|
function Adb([string[]]$Arguments){$script:adbCalls++;return 'Physical size: 1080x2400'}
|
|
$board=[pscustomobject]@{balls=@([pscustomobject]@{id='s10-b01';position=[pscustomobject]@{x=-.5;y=.8;z=0}});camera=[pscustomobject]@{rotation=[pscustomobject]@{x=0;y=0;z=0;w=1};target=[pscustomobject]@{x=0;y=.6;z=0};distance=8}}
|
|
foreach($id in @('s','missing','')){$rejected=$false;try{BallPoint $board $id|Out-Null}catch{$rejected=$true};$checks.Add(@{kind='missing-ID-before-ADB';id=$id;passed=($rejected-and$script:adbCalls-eq0);adbCalls=$script:adbCalls})}
|
|
$point=BallPoint $board 's10-b01';$checks.Add(@{kind='valid-whole-ID-native-coordinate';point=$point;passed=($point.Count-eq2-and$script:adbCalls-eq1-and$point[0]-lt1200)})
|
|
$passed=@($checks|Where-Object passed -ne $true).Count-eq0
|
|
@{passed=$passed;sourceCommit=(& git rev-parse HEAD);selectorSource=$SelectorSource;checks=$checks.ToArray()}|ConvertTo-Json -Depth 5|Set-Content -LiteralPath (Join-Path $EvidenceDir 'selection-result.json')
|
|
if(!$passed){exit 1};exit 0
|