rock_paper_scissors / tests /test_hand_detection_status.py
trtd56's picture
Initial commit
24836e5
"""手検出ステータスのテスト"""
import pytest
import numpy as np
from rock_paper_scissors.game.states import Hand
class TestHandDetectionStatus:
"""APIステータスに含まれるべき手検出情報のテスト"""
def test_status_should_include_hand_detection_available(self):
"""ステータスに手検出の利用可否が含まれる"""
from rock_paper_scissors.detection import HandDetectionStatus
status = HandDetectionStatus()
assert hasattr(status, 'available')
assert isinstance(status.available, bool)
def test_status_should_include_hand_position(self):
"""ステータスに手の位置が含まれる"""
from rock_paper_scissors.detection import HandDetectionStatus
status = HandDetectionStatus(
detected=True,
center_x=0.5,
center_y=0.5,
)
assert status.center_x == 0.5
assert status.center_y == 0.5
def test_status_should_include_gesture_info(self):
"""ステータスにジェスチャ情報が含まれる"""
from rock_paper_scissors.detection import HandDetectionStatus
status = HandDetectionStatus(
detected=True,
gesture="rock",
gesture_confidence=0.85,
)
assert status.gesture == "rock"
assert status.gesture_confidence == 0.85
def test_status_should_include_landmark_count(self):
"""ステータスにランドマーク数が含まれる(検出確認用)"""
from rock_paper_scissors.detection import HandDetectionStatus
status = HandDetectionStatus(
detected=True,
landmark_count=21,
)
assert status.landmark_count == 21
def test_status_default_values_when_not_detected(self):
"""手が検出されていない場合のデフォルト値"""
from rock_paper_scissors.detection import HandDetectionStatus
status = HandDetectionStatus()
assert status.detected is False
assert status.center_x is None
assert status.center_y is None
assert status.gesture is None
assert status.gesture_confidence == 0.0
assert status.landmark_count == 0
def test_status_to_dict_for_api(self):
"""APIレスポンス用のdict変換"""
from rock_paper_scissors.detection import HandDetectionStatus
status = HandDetectionStatus(
available=True,
detected=True,
center_x=0.5,
center_y=0.6,
gesture="paper",
gesture_confidence=0.92,
landmark_count=21,
)
result = status.to_dict()
assert result["hand_detection_available"] is True
assert result["hand_detected"] is True
assert result["hand_center_x"] == 0.5
assert result["hand_center_y"] == 0.6
assert result["detected_gesture"] == "paper"
assert result["gesture_confidence"] == 0.92
assert result["landmark_count"] == 21
class TestWaveDetectionStatus:
"""手振り検出ステータスのテスト"""
def test_wave_progress_tracking(self):
"""手振り検出の進捗トラッキング"""
from rock_paper_scissors.detection import WaveDetector
detector = WaveDetector()
# 左右の動きをシミュレート
positions = [0.3, 0.5, 0.7, 0.5, 0.3]
for pos in positions:
detector.update(pos)
# 進捗を取得できる
progress = detector.get_progress()
assert 0.0 <= progress <= 1.0
def test_wave_direction_changes_count(self):
"""方向変化のカウント"""
from rock_paper_scissors.detection import WaveDetector
detector = WaveDetector()
# 左右の動き
positions = [0.3, 0.5, 0.7, 0.5, 0.3, 0.5, 0.7]
for pos in positions:
detector.update(pos)
direction_changes = detector.get_direction_changes()
assert direction_changes >= 0