def test_incorrect_formats(self):
        """Test code format reward with various incorrect formats."""
        incorrect_formats = [
            # Missing think/answer tags
            "```python\ndef hello():\n    print('world')\n```",
            # Missing code block
            "<think>Some thinking</think><answer>Just plain text</answer>",
            # Wrong language
            "<think>Analysis</think><answer>```javascript\nconsole.log('hello');\n```</answer>",
            # Missing language identifier
            "<think>Analysis</think><answer>```\ndef hello(): pass\n```</answer>",
            # Wrong order of tags
            "<answer>```python\ndef hello(): pass\n```</answer><think>Analysis</think>",
        ]

        reward_fn = get_code_format_reward(language="python")
        for fmt in incorrect_formats:
            completion = [[{"content": fmt}]]
            rewards = reward_fn(completion)
            self.assertEqual(rewards[0], 0.0)
Test code format reward with various incorrect formats.
tests/test_rewards.py