"Independent native Squeak 6.1 regression suite for Aurora / Relay. File in endless-runner-final.st first. Then file in this file. Run ARIndependentTests suite run. No production classes are modified. Headless tests temporarily install Squeak's official X11 virtual-key table; KeyboardEvent instances are routed through the World active hand. The fast-run subclass deliberately stress-tests swept contact at 3,000 m/s." TestCase subclass: #ARIndependentTests instanceVariableNames: 'app savedKeyMap' classVariableNames: 'Metrics' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay-IndependentTests'! ARRun subclass: #ARIndependentFastRun instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay-IndependentTests'! ARRun subclass: #ARIndependentCappedRun instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay-IndependentTests'! !ARIndependentCappedRun methodsFor: 'testing'! speed ^ self maximumSpeed ! ! !ARIndependentFastRun methodsFor: 'testing'! speed ^ 3000 ! ! !ARIndependentTests class methodsFor: 'reporting'! metrics ^ Metrics ifNil: [Metrics := Dictionary new] ! ! !ARIndependentTests methodsFor: 'running'! setUp super setUp. app := nil. savedKeyMap := EventSensor virtualKeyTable. EventSensor classPool at: #VirtualKeyTable put: EventSensor virtualKeysOnX11 ! ! !ARIndependentTests methodsFor: 'running'! tearDown app ifNotNil: [app window ifNotNil: [app window delete]]. EventSensor classPool at: #VirtualKeyTable put: savedKeyMap. super tearDown ! ! !ARIndependentTests methodsFor: 'support'! openApp app := ARApp open. ^ app ! ! !ARIndependentTests methodsFor: 'support'! send: type code: code | event | event := KeyboardEvent new setType: type buttons: 0 position: app view center keyValue: code keyCode: code hand: World activeHand stamp: Time millisecondClockValue. World activeHand handleEvent: event ! ! !ARIndependentTests methodsFor: 'support'! tap: code self send: #keyDown code: code. self send: #keyUp code: code ! ! !ARIndependentTests methodsFor: 'support'! pumpFor: milliseconds | start | start := Time millisecondClockValue. [(Time millisecondsSince: start) < milliseconds] whileTrue: [World runStepMethods. (Delay forMilliseconds: 5) wait] ! ! !ARIndependentTests methodsFor: 'support'! stepCount ^ (((World instVarNamed: 'worldState') instVarNamed: 'stepList') select: [:each | each receiver == app]) size ! ! !ARIndependentTests methodsFor: 'testing'! testVectorArithmetic | a b | a := ARVector x: 2 y: -3 z: 4. b := ARVector x: 5 y: 6 z: 7. self assert: (a+b) asArray = #(7 3 11). self assert: (a-b) asArray = #(-3 -9 -3). self assert: (a*2) asArray = #(4 -6 8) ! ! !ARIndependentTests methodsFor: 'testing'! testCameraNearFarAndBehind | camera z | camera := ARCamera new. z := camera position z. self assert: (camera project: (ARVector x: 0 y: 4 z: z)) isNil. self assert: (camera project: (ARVector x: 0 y: 4 z: z-1)) isNil. self assert: (camera project: (ARVector x: 0 y: 4 z: z+0.499)) isNil. self assert: (camera project: (ARVector x: 0 y: 4 z: z+0.5)) = camera center. self assert: (camera project: (ARVector x: 0 y: 4 z: z+175)) = camera center. self assert: (camera project: (ARVector x: 0 y: 4 z: z+175.01)) isNil. self assert: (camera project: (ARVector x: 1 y: 5 z: 3)) = (394@113) ! ! !ARIndependentTests methodsFor: 'testing'! testVisibleObjectsCullWholeNearPlaneAndSort | a b c d e visible | self openApp. app game objects removeAll. a := ARWall lane: 0 z: -6.1. b := ARWall lane: 0 z: -6.0. c := ARWall lane: 0 z: 50. d := ARWall lane: 0 z: 168. e := ARWall lane: 0 z: -20. app game objects addAll: {a. b. c. d. e}. visible := app view visibleObjects. self assert: visible size = 2. self assert: visible first == c. self assert: visible last == b. self shouldnt: [app window imageForm] raise: Error ! ! !ARIndependentTests methodsFor: 'testing'! testSweptWallHurdleArchSpark #(#wall #hurdle #arch #spark) with: {ARWall. ARHurdle. ARArch. ARSpark} do: [:kind :cls | | body standingStart standingFinish | body := cls lane: 0 z: 10. standingStart := ARVector x: 0 y: 0.825 z: 0. standingFinish := ARVector x: 0 y: 0.825 z: 30. self assert: (body touchesFrom: standingStart to: standingFinish height: 1.65). self deny: (body touchesFrom: (ARVector x: 2.5 y: 0.825 z: 0) to: (ARVector x: 2.5 y: 0.825 z: 30) height: 1.65)] ! ! !ARIndependentTests methodsFor: 'testing'! testSweptCollisionThroughRunAtExtremeSpeed {ARWall. ARHurdle. ARArch. ARSpark} do: [:cls | | game | game := ARIndependentFastRun new. game objects removeAll; add: (cls lane: 0 z: 10). game togglePause. game advanceSlice: 0.01. cls = ARSpark ifTrue: [self assert: game coins = 1. self assert: game isRunning] ifFalse: [self assert: game state = #over]. self assert: game distance = 30] ! ! !ARIndependentTests methodsFor: 'testing'! testSweptSlideAndJumpClearance | arch hurdle wall slideStart slideEnd jumpStart jumpEnd | arch := ARArch lane: 0 z: 10. hurdle := ARHurdle lane: 0 z: 10. wall := ARWall lane: 0 z: 10. slideStart := ARVector x: 0 y: 0.31 z: 0. slideEnd := ARVector x: 0 y: 0.31 z: 30. self deny: (arch touchesFrom: slideStart to: slideEnd height: 0.62). self assert: (hurdle touchesFrom: slideStart to: slideEnd height: 0.62). jumpStart := ARVector x: 0 y: 1.825 z: 0. jumpEnd := ARVector x: 0 y: 1.825 z: 30. self deny: (hurdle touchesFrom: jumpStart to: jumpEnd height: 1.65). self assert: (wall touchesFrom: jumpStart to: jumpEnd height: 1.65) ! ! !ARIndependentTests methodsFor: 'testing'! testSweptLateralCrossingAndMiss | wall | wall := ARWall lane: 0 z: 10. self assert: (wall touchesFrom: (ARVector x: -2.5 y: 0.825 z: 0) to: (ARVector x: 2.5 y: 0.825 z: 20) height: 1.65). self deny: (wall touchesFrom: (ARVector x: -2.5 y: 0.825 z: 0) to: (ARVector x: 2.5 y: 0.825 z: 4) height: 1.65). self deny: (wall touchesFrom: (ARVector x: 0 y: 0.825 z: 12) to: (ARVector x: 0 y: 0.825 z: 30) height: 1.65) ! ! !ARIndependentTests methodsFor: 'testing'! testSparkIsCollectedOnlyOnce | game spark | game := ARRun new. spark := ARSpark lane: 0 z: 0. 10 timesRepeat: [spark contactIn: game]. self assert: game coins = 1. self assert: spark spent ! ! !ARIndependentTests methodsFor: 'testing'! testNativeJumpClearsHurdle self openApp. app game objects removeAll; add: (ARHurdle lane: 0 z: 4.2). self tap: 13. self tap: 32. 25 timesRepeat: [app game tick]. self assert: app game isRunning. self assert: app game player feet = 0. self assert: app game player verticalSpeed = 0 ! ! !ARIndependentTests methodsFor: 'testing'! testNativeSlideClearsArch self openApp. app game objects removeAll; add: (ARArch lane: 0 z: 4.2). self tap: 13. self tap: 31. self assert: app game player height = 0.62. 25 timesRepeat: [app game tick]. self assert: app game isRunning. self assert: app game player height = 1.65 ! ! !ARIndependentTests methodsFor: 'testing'! testNativeStandingCrashesOnArch self openApp. app game objects removeAll; add: (ARArch lane: 0 z: 4.2). self tap: 13. 20 timesRepeat: [app game tick]. self assert: app game state = #over ! ! !ARIndependentTests methodsFor: 'testing'! testNativeInputRepeatAndRestart self openApp. self tap: 13. self send: #keyDown code: 29. 20 timesRepeat: [self send: #keyDown code: 29]. self assert: app game player lane = 1. self send: #keyUp code: 29. self tap: 28. self assert: app game player lane = 0. self send: #keyDown code: 114. self assert: app game state = #ready. self tap: 13. app game tick. self send: #keyDown code: 114. self assert: app game isRunning. self assert: app game ticks = 1. self send: #keyUp code: 114. self tap: 114. self assert: app game state = #ready. self assert: app game distance = 0 ! ! !ARIndependentTests methodsFor: 'testing'! testFocusLossPausesAndClearsHeldKeys self openApp. self tap: 13. self send: #keyDown code: 29. self assert: app controller pressed notEmpty. World activeHand newKeyboardFocus: nil. self assert: app game state = #paused. self assert: app controller pressed isEmpty. self deny: app isStepping. World activeHand newKeyboardFocus: app view. self tap: 13. self tap: 28. self assert: app game player lane = 0 ! ! !ARIndependentTests methodsFor: 'testing'! testPauseFreezesAllSimulation | distance feet slide coins ticks positions | self openApp. self tap: 13. self tap: 32. app game tick. self tap: 27. distance := app game distance. feet := app game player feet. slide := app game player slideRemaining. coins := app game coins. ticks := app game ticks. positions := app game objects collect: [:body | body position asArray]. 100 timesRepeat: [app game tick]. self assert: app game distance = distance. self assert: app game player feet = feet. self assert: app game player slideRemaining = slide. self assert: app game coins = coins. self assert: app game ticks = ticks. self assert: (app game objects collect: [:body | body position asArray]) = positions ! ! !ARIndependentTests methodsFor: 'testing'! testGeneratorDeterminism | a b oa ob | a := ARGenerator seed: 8297. b := ARGenerator seed: 8297. 1 to: 1000 do: [:row | oa := OrderedCollection new. ob := OrderedCollection new. a addRowTo: oa at: row*28. b addRowTo: ob at: row*28. self assert: (oa collect: [:body | {body kind. body position asArray}]) = (ob collect: [:body | {body kind. body position asArray}])] ! ! !ARIndependentTests methodsFor: 'testing'! testGeneratorFairnessAcrossTwentyThousandRows | gen objects previous safe hazards coin lanes | lanes := Set new. 1 to: 100 do: [:seed | gen := ARGenerator seed: seed*104729. previous := 1. 1 to: 200 do: [:row | objects := OrderedCollection new. gen addRowTo: objects at: row*28. safe := gen safeLane. lanes add: safe. self assert: (safe-previous) abs <= 1. self assert: (#(-1 0 1) includes: safe). self assert: objects size = 4. hazards := objects reject: [:body | body kind = #spark]. coin := objects detect: [:body | body kind = #spark]. self assert: hazards size = 2. self assert: (hazards allSatisfy: [:body | body position x ~= (safe*2.5)]). self assert: coin position x = (safe*2.5). self assert: ((gen gap - 1.6) / ARRun new maximumSpeed) > (2.5/18). previous := safe]]. self assert: lanes size = 3. self class metrics at: 'fairnessSeeds' put: 100; at: 'fairnessRows' put: 20000 ! ! !ARIndependentTests methodsFor: 'testing'! testLongNativeGameplayAndBoundedObjects | maxObjects switches previousLane nearest sparks target before | self openApp. self tap: 13. maxObjects := 0. switches := 0. previousLane := 0. 1 to: 12000 do: [:tick | sparks := app game objects select: [:body | body kind = #spark and: [body position z >= 6]]. sparks notEmpty ifTrue: [ nearest := sparks inject: sparks first into: [:best :body | body position z < best position z ifTrue: [body] ifFalse: [best]]. nearest position z < 14 ifTrue: [ target := nearest position x / 2.5. target < app game player lane ifTrue: [self tap: 28]. target > app game player lane ifTrue: [self tap: 29]]]. previousLane ~= app game player lane ifTrue: [switches := switches+1. previousLane := app game player lane]. (tick rem: 250) = 0 ifTrue: [self tap: 13. before := app game distance. app game tick. self assert: app game distance = before. self tap: 13]. app game tick. maxObjects := maxObjects max: app game objects size. self assert: app game isRunning. self assert: (app game objects allSatisfy: [:body | body position z > -12])]. self assert: switches > 70. self assert: app game distance > 8000. self assert: app game speed = app game maximumSpeed. self assert: app game coins > 500. self assert: maxObjects <= 28. self class metrics at: 'simulationTicks' put: 12000; at: 'simulationSeconds' put: 480; at: 'distanceMeters' put: app game distance; at: 'sparksCollected' put: app game coins; at: 'laneSwitches' put: switches; at: 'liveObjectsHighWater' put: maxObjects; at: 'finalSpeedMetersPerSecond' put: app game speed. app game objects removeAll; add: (ARWall lane: app game player lane z: 0.5). app game tick. self assert: app game state = #over. before := app game distance. 10 timesRepeat: [app game tick]. self assert: app game distance = before. self tap: 114. self assert: app game state = #ready. self assert: app game distance = 0. self assert: app game coins = 0. self assert: app game player lane = 0. self tap: 13. self assert: app game isRunning ! ! !ARIndependentTests methodsFor: 'testing'! testActualSchedulerCadenceAndSingleLifecycle | before window ticks | self openApp. self assert: self stepCount = 0. self deny: (app wantsStepsIn: app window). self tap: 13. 20 timesRepeat: [app synchronizeStepping]. self assert: self stepCount = 1. self assert: app isStepping. before := app game ticks. self pumpFor: 440. ticks := app game ticks-before. self assert: ticks >= 8. self assert: ticks <= 14. self class metrics at: 'schedulerWindowMilliseconds' put: 440; at: 'schedulerTicks' put: ticks. self assert: self stepCount = 1. self tap: 27. self assert: self stepCount = 0. before := app game ticks. self pumpFor: 100. self assert: app game ticks = before. self tap: 13. self assert: self stepCount = 1. window := app window. window delete. self assert: app window isNil. self assert: self stepCount = 0. self assert: app game state = #paused. self deny: app hasViewFocus. app open. self assert: self stepCount = 0. self tap: 13. self assert: self stepCount = 1. app game crash. app synchronizeStepping. self assert: self stepCount = 0 ! ! !ARIndependentTests methodsFor: 'testing'! testArchSupportsMatchVisiblePosts | arch | arch := ARArch lane: 0 z: 10. #(-0.86 -0.5 0.5 0.86) do: [:x | self assert: (arch touchesFrom: (ARVector x: x y: 0.31 z: 0) to: (ARVector x: x y: 0.31 z: 30) height: 0.62)]. #(-2.5 -1.28 -0.4 0 0.4 1.28 2.5) do: [:x | self deny: (arch touchesFrom: (ARVector x: x y: 0.31 z: 0) to: (ARVector x: x y: 0.31 z: 30) height: 0.62)]. self assert: (arch touchesFrom: (ARVector x: 0 y: 0.31 z: 0) to: (ARVector x: 1.72 y: 0.31 z: 20) height: 0.62) ! ! !ARIndependentTests methodsFor: 'support'! clickButton: selector | button hand event | button := app submorphs detect: [:m | (m isKindOf: SimpleButtonMorph) and: [m actionSelector = selector]]. hand := World activeHand. event := MouseButtonEvent new setType: #mouseDown position: button center which: 4 buttons: 4 hand: hand stamp: Time millisecondClockValue. hand handleEvent: event. event := MouseButtonEvent new setType: #mouseUp position: button center which: 4 buttons: 0 hand: hand stamp: Time millisecondClockValue. hand handleEvent: event ! ! !ARIndependentTests methodsFor: 'testing'! testSidebarMouseStartRecoversSceneFocus World submorphs copy do: [:m | (#(PreferenceWizardMorph SystemProgressMorph) includes: m class name) ifTrue: [m delete]]. self openApp. app window position: 10@10. app window imageForm. World activeHand newKeyboardFocus: nil. self clickButton: #togglePause. self assert: app game isRunning. self assert: app hasViewFocus. app step. self assert: app game isRunning. self clickButton: #togglePause. self assert: app game state = #paused. self clickButton: #restart. self assert: app game state = #ready ! ! !ARIndependentTests methodsFor: 'testing'! testNativeWASDAliasesAndBoundaryClamps self openApp. self tap: 13. self send: #keyDown code: 97. self send: #keyDown code: 65. self assert: app game player lane = -1. self send: #keyUp code: 97. self tap: 97. self assert: app game player lane = -1. self tap: 100. self assert: app game player lane = 0. self tap: 68. self assert: app game player lane = 1. self tap: 100. self assert: app game player lane = 1. self tap: 119. self assert: app game player verticalSpeed > 0. 25 timesRepeat: [app game tick]. self tap: 83. self assert: app game player height = 0.62 ! ! !ARIndependentTests methodsFor: 'testing'! testWindowFitsSupportedWorld self openApp. (World width >= app window width and: [World height >= app window height]) ifTrue: [ self assert: (World bounds containsRect: app window bounds)] ! ! !ARIndependentTests methodsFor: 'testing'! testNativeGuaranteedRouteAtMaximumSpeedAcrossSeeds | run sparks nearest target total | self openApp. total := 0. 1 to: 12 do: [:seed | app pause. run := ARIndependentCappedRun new seed: seed*65537; yourself. app instVarNamed: 'game' put: run. self tap: 13. 1600 timesRepeat: [ sparks := run objects select: [:body | body kind = #spark and: [body position z >= 6]]. sparks notEmpty ifTrue: [ nearest := sparks inject: sparks first into: [:best :body | body position z < best position z ifTrue: [body] ifFalse: [best]]. nearest position z < 14 ifTrue: [ target := nearest position x / 2.5. target < run player lane ifTrue: [self tap: 28]. target > run player lane ifTrue: [self tap: 29]]]. run tick. self assert: run isRunning. self assert: run objects size <= 28]. self assert: run distance > 1400. self assert: run coins >= 96. total := total + run distance]. self class metrics at: 'maximumSpeedRouteSeeds' put: 12; at: 'maximumSpeedRouteTicks' put: 19200; at: 'maximumSpeedRouteTotalMeters' put: total ! ! !ARIndependentTests methodsFor: 'testing'! testNativeJumpAndSlideAreExclusiveBeforeTakeoff self openApp. self tap: 13. self tap: 32. self assert: app game player feet = 0. self assert: app game player verticalSpeed > 0. self tap: 83. self assert: app game player slideRemaining = 0. self assert: app game player height = 1.65. app game tick. self assert: app game player feet > 0. self tap: 114. self tap: 13. self tap: 83. self tap: 32. self assert: app game player verticalSpeed = 0. self assert: app game player feet = 0. self assert: app game player height = 0.62 ! !