diff --git a/reasoning_gym/cognition/arc_1d.py b/reasoning_gym/cognition/arc_1d.py index d9bb2f82..2aa65d76 100644 --- a/reasoning_gym/cognition/arc_1d.py +++ b/reasoning_gym/cognition/arc_1d.py @@ -1030,6 +1030,31 @@ def task_gravity_weighted_colors(rng: Random, size: int) -> Optional[Dict[str, L return {"input": question, "output": answer} +def task_mirror(task_result: Optional[Dict[str, List[int]]]) -> Optional[Dict[str, List[int]]]: + """Mirror the input and output arrays of a task result.""" + if task_result is None: + return None + return { + "input": list(reversed(task_result["input"])), + "output": list(reversed(task_result["output"])) + } + + +def task_inverse(task_result: Optional[Dict[str, List[int]]]) -> Optional[Dict[str, List[int]]]: + """Swap the input and output arrays of a task result.""" + if task_result is None: + return None + return { + "input": task_result["output"], + "output": task_result["input"] + } + + +def task_identity(task_result: Optional[Dict[str, List[int]]]) -> Optional[Dict[str, List[int]]]: + """Return the task result unchanged.""" + return task_result + + def task_color_left_half_blocks(rng: Random, size: int) -> Optional[Dict[str, List[int]]]: """Generate a task where left half of blocks are colored differently.""" pos = 0 diff --git a/tests/test_arc_1d.py b/tests/test_arc_1d.py index f724037f..082869c6 100644 --- a/tests/test_arc_1d.py +++ b/tests/test_arc_1d.py @@ -46,6 +46,24 @@ def test_all_arc_1d_tasks(): # Fixed move_pix value for testing move_pix = 2 + # Test task augmentation functions + base_task = task_move_n_pix(rng, size, move_pix, True) + assert base_task is not None + + mirrored = task_mirror(base_task) + assert mirrored is not None + assert mirrored["input"] == list(reversed(base_task["input"])) + assert mirrored["output"] == list(reversed(base_task["output"])) + + inversed = task_inverse(base_task) + assert inversed is not None + assert inversed["input"] == base_task["output"] + assert inversed["output"] == base_task["input"] + + identical = task_identity(base_task) + assert identical is not None + assert identical == base_task + tasks = [ (task_move_n_pix, {"move_pix": move_pix, "solid": True}), (task_move_n_pix_wrapped, {"move_pix": move_pix, "solid": True}),