mirror of
https://github.com/open-thought/reasoning-gym.git
synced 2026-04-19 12:58:07 +00:00
string insertion
This commit is contained in:
parent
56ba500959
commit
a79d3d06f2
3 changed files with 195 additions and 0 deletions
94
tests/test_string_insertion.py
Normal file
94
tests/test_string_insertion.py
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
"""Tests for String Insertion questions generation"""
|
||||
|
||||
import pytest
|
||||
|
||||
from reasoning_gym.algorithmic.string_insertion import StringInsertionConfig, StringInsertionDataset
|
||||
|
||||
|
||||
def test_string_insertion_config_validation():
|
||||
"""Test that invalid configs raise appropriate errors"""
|
||||
|
||||
for field in ["min_string_length", "max_string_length"]:
|
||||
for i in range(-1, 5):
|
||||
with pytest.raises(AssertionError):
|
||||
config = StringInsertionConfig(**{field: i}) # [-1, 4] is invalid
|
||||
config.validate()
|
||||
|
||||
|
||||
def test_string_insertion_dataset_deterministic():
|
||||
"""Test that dataset generates same items with same seed"""
|
||||
config = StringInsertionConfig(seed=42, size=10)
|
||||
dataset1 = StringInsertionDataset(config)
|
||||
dataset2 = StringInsertionDataset(config)
|
||||
|
||||
for i in range(len(dataset1)):
|
||||
assert dataset1[i] == dataset2[i]
|
||||
|
||||
|
||||
def test_string_insertion_dataset_items():
|
||||
"""Test basic properties of generated items"""
|
||||
config = StringInsertionConfig(min_string_length=5, max_string_length=30, size=10, seed=42)
|
||||
dataset = StringInsertionDataset(config)
|
||||
|
||||
for i in range(len(dataset)):
|
||||
item = dataset[i]
|
||||
# Check item structure
|
||||
assert isinstance(item, dict)
|
||||
assert "question" in item
|
||||
assert "answer" in item
|
||||
assert "metadata" in item
|
||||
|
||||
# Check metadata
|
||||
assert "string" in item["metadata"]
|
||||
assert "solution" in item["metadata"]
|
||||
|
||||
string = item["metadata"]["string"]
|
||||
solution = item["metadata"]["solution"]
|
||||
|
||||
# Verify string dimensions
|
||||
assert 5 <= len(string) <= 30
|
||||
assert len(string) <= len(solution)
|
||||
|
||||
|
||||
def test_string_insertion_dataset_iteration():
|
||||
"""Test that iteration respects dataset size"""
|
||||
config = StringInsertionConfig(size=5, seed=42)
|
||||
dataset = StringInsertionDataset(config)
|
||||
|
||||
items = list(dataset)
|
||||
assert len(items) == config.size
|
||||
|
||||
# Test multiple iterations yield same items
|
||||
assert items == list(dataset)
|
||||
|
||||
|
||||
def test_string_insertion_answer():
|
||||
"""Test the _get_rotated method"""
|
||||
config = StringInsertionConfig(seed=42)
|
||||
dataset = StringInsertionDataset(config)
|
||||
|
||||
# No pattern match
|
||||
assert dataset._get_answer("AAAAAAA") == "AAAAAAA"
|
||||
assert dataset._get_answer("ADBEEBEA") == "ADBEEBEA"
|
||||
assert dataset._get_answer("ADEACA") == "ADEACA"
|
||||
|
||||
# Insert A after ABCD
|
||||
assert dataset._get_answer("ABCDE") == "ABCDAE"
|
||||
|
||||
# Insert B after BCDE
|
||||
assert dataset._get_answer("AEBCDEC") == "AEBCDEBC"
|
||||
|
||||
# Insert C after CDEA
|
||||
assert dataset._get_answer("BBACDEAC") == "BBACDEACC"
|
||||
|
||||
# Insert D after DEAB
|
||||
assert dataset._get_answer("BAAABDEAB") == "BAAABDEABD"
|
||||
|
||||
# Insert E after EABC
|
||||
assert dataset._get_answer("EABCBCBC") == "EABCEBCBC"
|
||||
|
||||
# Multiple insertions
|
||||
assert dataset._get_answer("AABCDEEEEEEEBCDEAAAAA") == "AABCDAEEEEEEEBCDEBAAAAA"
|
||||
|
||||
# No reuse of newly inserted characters
|
||||
assert dataset._get_answer("ABCDBCD") == "ABCDABCD"
|
||||
Loading…
Add table
Add a link
Reference in a new issue