60 lines
2.2 KiB
Python
60 lines
2.2 KiB
Python
"""SubPattern.supports_flip/flip_axis 默认值 + AR 两个子模式的翻转声明。"""
|
||
|
||
from app.question_gen.strategy import SubPattern
|
||
from app.question_gen.strategy_action_recognition import AR_SUB_PATTERNS
|
||
|
||
_FLIP_EXPECTED = {
|
||
"temporal_reasoning_failure": "before/after",
|
||
"cross_segment_entity_tracking": "first/last",
|
||
}
|
||
|
||
|
||
def test_sub_pattern_defaults_no_flip():
|
||
sp = SubPattern(
|
||
name="x", weight=1.0, sampling_level_override=None,
|
||
constraint_override=None, instruction="i",
|
||
)
|
||
assert sp.supports_flip is False
|
||
assert sp.flip_axis is None
|
||
|
||
|
||
def test_ar_flip_declarations():
|
||
by_name = {sp.name: sp for sp in AR_SUB_PATTERNS}
|
||
for name, axis in _FLIP_EXPECTED.items():
|
||
assert by_name[name].supports_flip is True, name
|
||
assert by_name[name].flip_axis == axis, name
|
||
|
||
|
||
def test_other_ar_sub_patterns_keep_defaults():
|
||
for sp in AR_SUB_PATTERNS:
|
||
if sp.name in _FLIP_EXPECTED:
|
||
continue
|
||
assert sp.supports_flip is False, sp.name
|
||
assert sp.flip_axis is None, sp.name
|
||
|
||
|
||
def test_non_ar_strategies_have_no_flip_capable_sub_pattern():
|
||
"""非 AR 题型走 BaseTaskTypeStrategy,无 SubPattern(select_sub_pattern 返回 None),
|
||
故不存在 flip-capable 子模式——翻转门对它们天然跳过。"""
|
||
import random
|
||
from app.question_gen.strategy import get_strategy
|
||
|
||
non_ar = [
|
||
"Action Reasoning", "Attribute Perception", "Counting Problem",
|
||
"Information Synopsis", "Object Recognition", "Object Reasoning",
|
||
"OCR Problems", "Spatial Perception", "Spatial Reasoning",
|
||
"Temporal Perception", "Temporal Reasoning",
|
||
]
|
||
rng = random.Random(0)
|
||
for tt in non_ar:
|
||
assert get_strategy(tt).select_sub_pattern(rng) is None, tt
|
||
|
||
|
||
def test_only_two_ar_sub_patterns_support_flip():
|
||
"""全 6 个 AR SubPattern 中恰有 2 个 supports_flip=True,其余 4 个默认 False。"""
|
||
from app.question_gen.strategy_action_recognition import AR_SUB_PATTERNS
|
||
|
||
flip_names = {sp.name for sp in AR_SUB_PATTERNS if sp.supports_flip}
|
||
assert flip_names == {"temporal_reasoning_failure", "cross_segment_entity_tracking"}
|
||
assert all(sp.flip_axis is None for sp in AR_SUB_PATTERNS if not sp.supports_flip)
|