File size: 1,692 Bytes
0dd6c2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from linalg_zero.generator.core import DatasetGenerator, QuestionGenerator
from linalg_zero.generator.models import DifficultyCategory, Question, Task, Topic


def test_question_generator_factory_pattern() -> None:
    """Test QuestionGenerator uses injected factory correctly (core pattern test)."""

    def simple_factory() -> Question:
        return Question(
            question="Test question",
            answer="42",
            topic=Topic.LINEAR_ALGEBRA,
            difficulty=DifficultyCategory.ONE_TOOL_CALL,
            problem_type=Task.ONE_DETERMINANT,
        )

    generator = QuestionGenerator(question_factory=simple_factory)
    question = generator.generate()

    assert question.question == "Test question"
    assert question.answer == "42"
    assert question.topic == Topic.LINEAR_ALGEBRA
    assert question.is_valid is True  # Should be validated


def test_dataset_generation() -> None:
    """Test that DatasetGenerator creates datasets with expected properties."""
    generator = DatasetGenerator(topic=Topic.LINEAR_ALGEBRA)
    questions = generator.generate_dataset(num_questions=3)

    # Check we got the right number of questions
    assert len(questions) == 3

    # Check all questions are valid Question objects
    for question in questions:
        assert isinstance(question, Question)
        assert question.is_valid is True  # Only valid questions should be returned
        assert len(question.question) > 0
        assert len(question.answer) > 0
        assert question.difficulty in [
            DifficultyCategory.ONE_TOOL_CALL,
            DifficultyCategory.TWO_TOOL_CALLS,
            DifficultyCategory.THREE_TOOL_CALLS,
        ]