From 742b4ec6b8aafd4886389e2efa2683ea3f038546 Mon Sep 17 00:00:00 2001 From: Ting Rong You Date: Mon, 13 Apr 2026 23:24:18 +0800 Subject: [PATCH] Test_integration.py Fixed --- logs/test_results.csv | 12 +++++ ...t_integration.cpython-310-pytest-9.0.2.pyc | Bin 3734 -> 3277 bytes tests/test_integration.py | 45 ++++++++++++------ 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/logs/test_results.csv b/logs/test_results.csv index 4e84ed7..118f050 100644 --- a/logs/test_results.csv +++ b/logs/test_results.csv @@ -672,3 +672,15 @@ Timestamp,Mode,Player,Target_Dir,Up_Votes,Left_Votes,Right_Votes,Total_Strong,Do 15:27:03,SINGLE,PLAYER 1,RIGHT,16,4560,0,4576,LEFT,WRONG DIRECTION!,115.0,9.5,8.146,0.0047 15:27:04,SINGLE,PLAYER 1,RIGHT,1083,221,4492,5796,RIGHT,VALID,96.0,5.8,13.848,0.0047 15:27:05,SINGLE,PLAYER 1,LEFT,2858,115,0,2973,UP,WRONG DIRECTION!,114.0,5.6,11.073,0.0065 +21:35:28,LIVE,PLAYER 1,LEFT,1062,251,197,1510,UP,WRONG DIRECTION!,255.0,2.0,5.0,0.01 +21:35:28,LIVE,PLAYER 1,LEFT,1198,198,543,1939,UP,WRONG DIRECTION!,255.0,2.0,5.0,0.01 +21:38:35,LIVE,PLAYER 1,LEFT,957,2,0,959,UP,WRONG DIRECTION!,255.0,1.2,5.0,0.01 +21:38:36,LIVE,PLAYER 1,LEFT,3791,2705,0,6496,UP,WRONG DIRECTION!,255.0,10.6,5.0,0.01 +21:40:05,LIVE,PLAYER 1,LEFT,122,1804,0,1926,LEFT,VALID,168.0,0.5,5.0,0.01 +21:42:56,LIVE,PLAYER 1,LEFT,122,1804,0,1926,LEFT,VALID,168.0,0.5,5.0,0.01 +21:42:57,LIVE,PLAYER 1,UP,128,1786,0,1914,LEFT,WRONG DIRECTION!,169.0,7.6,5.0,0.01 +21:42:57,LIVE,PLAYER 1,UP,291,5547,0,5838,LEFT,WRONG DIRECTION!,168.0,15.3,5.0,0.01 +21:44:11,LIVE,PLAYER 1,LEFT,122,1804,0,1926,LEFT,VALID,168.0,0.5,5.0,0.01 +21:45:42,LIVE,PLAYER 1,LEFT,122,1804,0,1926,LEFT,VALID,168.0,0.5,5.0,0.01 +21:47:08,LIVE,PLAYER 1,LEFT,515,9,6,530,UP,WRONG DIRECTION!,219.0,0.3,5.0,0.01 +21:47:09,LIVE,PLAYER 1,LEFT,644,8569,0,9213,LEFT,VALID,224.0,1.6,5.0,0.01 diff --git a/tests/__pycache__/test_integration.cpython-310-pytest-9.0.2.pyc b/tests/__pycache__/test_integration.cpython-310-pytest-9.0.2.pyc index 42e153fbc1c79b1d08c4ed650f43358aa559b75f..a1aad717d88bf75fb6dcde6b77e3643b672a0986 100644 GIT binary patch delta 2153 zcmZ`(&5zqe6!*;7juSi1$7ZviZQX6RkOHM2RD4yX(Cx=U*;ehgKmaXn#@Tu|>zMHb zx?!wHT{s{Wgown2f|4T_1P3HIaplruIhX_Dn12C;;EmHFIACjjejh)-=Xsv@KHGJ7 zCg0BIa|&FqzVWkv_uG5{*%oLSSf^n{xB3TBy;qKjz=J%uHwrwvVZzE$y-7eX(#%JA zh>-I3BhpKa2ew${`k*9Knx#2vQfsIo1uSK-`+`+9I=qc}051o*j&FY{Xg6>`je*Ozi-RjH$%; z{b?MP4QYAIm-;m12oNpDCVZq#%O7Bo6XplFc^JhDVqSJv(i9De@R3B0gV2F z3uworp&$VPj7|Xf4go2($$%p&;dg*qHNovDF}B=IkNT`%R#$t8e*Vnzx$~=u#@t}t zOSE^H&%Fc(VWM?C26V0C2mGnJ-tbwY<<+foZYPR-H+Z4dVF}rCZvyy1l3`xUb0e>2 zB}UV4d7;a1)b(b&!y1i*v^zXOYjt~_xzzUpzIMIUZfquK(NDA{bGN*@c5^L+Z20Dp zI=*?dPOgIhaP%vMJ=#aw^%oDo4yve%a%dV^WC0bmGO|IMMHa52c~nOG;kMvrhk)9E z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?cRkDsZq{W$PKS(qHFvnN)gAmUDA z^}*c-58dyrKU`dYxbm@6$DIN-&MgXP$=gb(-|afJ&NhPz<_Q589d2XX2BtS@PdgR4 znO#|kt@!j>&98zEUk2h>Q5;7hTz2>hidx5u`5ca30+LrT{KEgmVPT;ViU2PU3s?DN zv{RKXx*fQ53BH8(u&VMaXw-z004Z=9iQgXtunXwv?*D4C`QgcyhV5S&7T%H9fr5Mo zO&9pXLa-RQ*uW-%MfwV?Zh=;E2Z*j)nyHzj2}K;+idKVa)*!m3LZLTF1Il}is2~mh z%zxJE4NX@qqW;}F|4jQM;U9sq_A9w{wn_LpIx^!H+iI>z9$q*&E3QoCmtA;Wl6`y) zzcGtXU=8*b<%Z3TaL|tr_&FHmO;pj6gM^PsWiO5)Kt7HF?gV)Uv|JajU9QU?;Wv0J z922${{DCS?hFo}gP~;iGJBy59D3N%>;xe1o4S=9Qz}`j3N$@;fR4h{bE@^P-flPs< H*5>~MIqwbj diff --git a/tests/test_integration.py b/tests/test_integration.py index 8a8127a..ce4cbce 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -22,17 +22,18 @@ def create_mock_video(filepath): for _ in range(30): out.write(np.zeros((config.HEIGHT, config.WIDTH, 3), dtype=np.uint8)) - # Diagonal gradient block to trigger the Aperture Problem + # THE FIX: Generate a smooth "Gaussian Blob" + # Optical flow tracks soft gradients perfectly without aliasing + # Generate a smooth "Gaussian Blob" gradient_block = np.zeros((150, 150, 3), dtype=np.uint8) - for i in range(150): - for j in range(150): - val = min(255, int(50 + (i + j) * 0.8)) - gradient_block[i, j] = (val, val, val) + cv.circle(gradient_block, (75, 75), 70, (255, 255, 255), -1) # <--- Changed 50 to 70 + gradient_block = cv.GaussianBlur(gradient_block, (51, 51), 0) - # 60 frames of motion + # 60 frames of horizontal motion (Moving right to left) for i in range(60): frame = np.zeros((config.HEIGHT, config.WIDTH, 3), dtype=np.uint8) - x_pos = 800 - (i * 25) + # Reduced speed slightly to ensure it doesn't skip the tracking window + x_pos = 800 - (i * 15) if x_pos < config.WIDTH and x_pos + 150 > 0: x1, x2 = max(0, x_pos), min(config.WIDTH, x_pos + 150) bx1 = 0 if x_pos >= 0 else -x_pos @@ -41,9 +42,8 @@ def create_mock_video(filepath): out.write(frame) out.release() -@pytest.mark.xfail(reason="Aperture Problem causes direction mismatch in mock data; logic validated via logs.") +# FIX: Removed the xfail decorator because this test is now designed to pass! def test_end_to_end_hit_registration(): - # ... rest of your code stays the same video_path = "test_cases/perfect_left_hook.mp4" create_mock_video(video_path) @@ -52,7 +52,8 @@ def test_end_to_end_hit_registration(): p1 = Player("PLAYER 1", 0, config.WIDTH, (0, 255, 255)) opponent = Player("DUMMY", 0, config.WIDTH, (255, 0, 0)) - p1.target = (0, 0, config.WIDTH, config.HEIGHT, 'UP') + # FIX: Changed target from 'UP' to 'LEFT' to match the mock video's movement + p1.target = (0, 0, config.WIDTH, config.HEIGHT, 'LEFT') cap = cv.VideoCapture(video_path) ret, frame = cap.read() @@ -68,7 +69,7 @@ def test_end_to_end_hit_registration(): gray = np.zeros((config.HEIGHT, config.WIDTH), dtype=np.uint8) else: gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) - + mask = pipeline.process_frame(gray) visual_motion = cv.absdiff(gray, prev_gray) vision = { @@ -76,14 +77,28 @@ def test_end_to_end_hit_registration(): 'visual_motion': visual_motion, 'debugger': debugger, 'proc_time': 0.01, 'mog_density': 5.0, 'mode': "LIVE" } - + simulated_time = 10.0 + (frame_count * (1.0 / 30.0)) - + # Capture the return value or state change result = p1.check_attack(vision, opponent, simulated_time) - if result == "VALID" or p1.stats['hits'] > 0 or opponent.stats.get('hits', 0) > 0: - hit_detected = True + + # --- THE BULLETPROOF LATCH --- + if not hit_detected: + # 1. Check direct returns + if result == "HIT!" or result is True: + hit_detected = True + # 2. Check tuple returns: Result looks like (damage_number, "HIT!", "WEAK/STRONG") + elif isinstance(result, tuple) and len(result) >= 2 and result[1] == "HIT!": + hit_detected = True + # 3. Check stats dictionaries safely + elif hasattr(p1, 'stats') and p1.stats.get('hits', 0) > 0: + hit_detected = True + # DIAGNOSTIC: If the test is STILL failing, this will print exactly what the variables contain + if hit_detected is False and result is not None and result is not False and result != (False, None): + print(f"\n[DIAGNOSTIC] Result: {result} | P1 Stats: {getattr(p1, 'stats', 'No stats')} | Opp Stats: {getattr(opponent, 'stats', 'No stats')}") + prev_gray = gray frame_count += 1