"""Original-byte guards and mode2 arithmetic projections, not native gameplay.""" from pathlib import Path import math import sys import unittest ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT/'tools/binary')) from bubble_motion import apply_step, collect, keyboard_step, ordinary_destination class BubbleMotionTests(unittest.TestCase): def test_source_spans_virtuals_constants_and_offsets(self): report = collect(ROOT.parent/'Original') self.assertEqual((len(report['bodies']),len(report['vtables'])), (11,8)) self.assertEqual(len(report['sites']),17) self.assertTrue(all(int(b['va'],16)-int(b['file_offset'],16)==0x400000 for b in report['bodies'])) self.assertFalse(report['landing_mode_reset']) def test_fire_is_bubble_throttle_without_ordinary_beam(self): a = keyboard_step(0,0,.25,fire=True) b = keyboard_step(0,0,.25,forward=True) self.assertEqual(a,b) self.assertEqual((a.speed,a.target_pitch), (30,-10)) self.assertEqual(keyboard_step(1340,0,.25,fire=True).speed,1350) def test_mode2_turn_cap_release_and_forward_backward_pose_priority(self): self.assertEqual(keyboard_step(0,49,.5,left=True,right=True).turn,50) self.assertEqual(keyboard_step(0,-49,.5,right=True).turn,-50) a = keyboard_step(100,20,.5) self.assertEqual((a.turn,a.target_pitch,a.target_roll),(0,0,0)) b = keyboard_step(100,10,.1,forward=True,backward=True,left=True) self.assertEqual((b.speed,b.target_pitch,b.target_roll),(112.5,-10,-5)) def test_grounded_input_decay_precedes_brake_and_can_cross_below_zero(self): self.assertEqual(keyboard_step(100,0,.1,supported=True).speed,82.5) self.assertEqual(keyboard_step(100,0,.1,supported=True,backward=True).speed,47.5) self.assertEqual(keyboard_step(100,0,.1,supported=True,forward=True).speed,112.5) crossed = keyboard_step(5,0,.1,supported=True).speed self.assertEqual(crossed,-12.5) self.assertEqual(keyboard_step(crossed,0,.1,supported=True).speed,0) def test_coast_threshold_and_air_brake_do_not_start_reverse(self): self.assertEqual(keyboard_step(1350,0,.1).speed,1332.5) self.assertEqual(keyboard_step(1200,0,.1).speed,1200) self.assertEqual(keyboard_step(5,0,.1,backward=True).speed,0) self.assertEqual(keyboard_step(-5,0,.1,backward=True).speed,0) def test_apply_preserves_vertical_and_pitch_scales_horizontal_only(self): a = apply_step(100,0,0,60,(0,-12,10),.1) self.assertAlmostEqual(a.velocity[2],50) self.assertEqual(a.velocity[1],-12) self.assertEqual((a.published_speed,a.sound,a.movement_mode),(100,None,2)) def test_supported_jump_direct_velocity_and_released_scalar_order(self): a = apply_step(100,0,0,0,(0,-800,10),.1,supported=True) self.assertEqual(a.velocity,(0,300,100)) self.assertEqual((a.published_speed,a.sound,a.movement_mode),(50,None,2)) b = apply_step(100,0,0,0,(0,-800,10),.1,supported=True,jump=True) self.assertEqual(b.velocity,(0,900,100)) self.assertEqual((b.published_speed,b.sound),(100,106)) # No edge latch: a second supported apply also produces the high bounce. self.assertEqual(apply_step(100,0,0,0,b.velocity,.1,supported=True,jump=True).sound,106) def test_zero_incoming_velocity_suppresses_direct_yaw_and_side_only(self): stopped = apply_step(100,50,0,0,(0,0,0),.1) self.assertEqual((stopped.yaw,stopped.velocity),(0,(0,0,100))) moving = apply_step(100,50,0,0,(0,1,0),.1) self.assertEqual(moving.yaw,5) self.assertNotEqual(moving.velocity[0],stopped.velocity[0]) for seconds in (-1,1,math.inf,math.nan): with self.assertRaises(ValueError): apply_step(0,0,0,0,(0,0,0),seconds) with self.assertRaises(ValueError): keyboard_step(0,0,seconds) def test_cleanup_and_ground_no_input_do_not_invent_upright_reset(self): report = collect(ROOT.parent/'Original')['handoff'] self.assertEqual(len(report['bodies']),6) self.assertEqual(len(report['a20_raw_dword_occurrences']),6) self.assertEqual(report['a20_direct_writes'],['0x4226cf','0x428045','0x42821a']) self.assertIsNone(report['a20_consumer']) self.assertFalse(report['derived_aliases_excluded']) self.assertFalse(report['cleanup_resets_euler']) self.assertFalse(report['ground_no_input_resets_euler']) target = (-10.,42.,-12.5) self.assertEqual(ordinary_destination(target,43,20),target) self.assertEqual(ordinary_destination(target,43,20,accepted_ground_direction=True),(0,43,0)) def test_ordinary_air_handoff_targets_zero_pitch_but_retains_turn_lean(self): target = (-10.,42.,-12.5) self.assertEqual(ordinary_destination(target,43,20,airborne=True),(0,43,-20)) self.assertEqual(ordinary_destination(target,43,0,airborne=True),(0,43,0)) if __name__ == '__main__': unittest.main()