File size: 4,631 Bytes
c7b7c5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
"""Tests for the DatasetLoader."""
import pytest
from server.dataset_loader import DatasetLoader


class TestDatasetLoaderInit:
    """Tests for DatasetLoader initialization."""

    def test_loader_initializes(self):
        """DatasetLoader should initialize without errors."""
        loader = DatasetLoader()
        assert loader is not None


class TestDatasetSampling:
    """Tests for dataset sampling."""

    def test_get_sample_returns_data(self):
        """get_sample should return a sample with required fields."""
        loader = DatasetLoader()
        sample = loader.get_sample("task_1_factual_grounding")

        assert sample is not None
        assert hasattr(sample, 'question') or 'question' in sample

    def test_get_sample_has_context(self):
        """Sample should include context."""
        loader = DatasetLoader()
        sample = loader.get_sample("task_1_factual_grounding")

        assert hasattr(sample, 'context') or 'context' in sample

    def test_get_sample_has_ground_truth(self):
        """Sample should include ground truth."""
        loader = DatasetLoader()
        sample = loader.get_sample("task_1_factual_grounding")

        assert hasattr(sample, 'ground_truth') or 'ground_truth' in sample

    def test_get_sample_for_task_1(self):
        """get_sample for task_1 should work."""
        loader = DatasetLoader()
        sample = loader.get_sample("task_1_factual_grounding")

        assert sample is not None

    def test_get_sample_for_task_2(self):
        """get_sample for task_2 should work."""
        loader = DatasetLoader()
        sample = loader.get_sample("task_2_multi_hop_synthesis")

        assert sample is not None

    def test_get_sample_for_task_3(self):
        """get_sample for task_3 should work."""
        loader = DatasetLoader()
        sample = loader.get_sample("task_3_adversarial_resistance")

        assert sample is not None


class TestDatasetStats:
    """Tests for dataset statistics."""

    def test_get_available_datasets(self):
        """Should be able to get list of available datasets."""
        loader = DatasetLoader()

        if hasattr(loader, 'get_available_datasets'):
            datasets = loader.get_available_datasets()
            assert isinstance(datasets, list)
            assert len(datasets) > 0

    def test_get_dataset_size(self):
        """Should be able to get dataset size info."""
        loader = DatasetLoader()

        if hasattr(loader, 'get_dataset_size'):
            size = loader.get_dataset_size("task_1_factual_grounding")
            assert size is None or isinstance(size, int)


class TestDatasetCaching:
    """Tests for dataset caching behavior."""

    def test_multiple_samples_dont_crash(self):
        """Requesting multiple samples should work."""
        loader = DatasetLoader()

        samples = []
        for _ in range(5):
            sample = loader.get_sample("task_1_factual_grounding")
            samples.append(sample)

        assert len(samples) == 5

    def test_loader_handles_missing_dataset(self):
        """Loader should handle request for missing dataset gracefully."""
        loader = DatasetLoader()

        try:
            sample = loader.get_sample("nonexistent_dataset")
            # If it returns None, that's acceptable
            assert sample is None or sample is not None
        except Exception as e:
            # Should raise a reasonable exception, not crash
            assert "not found" in str(e).lower() or "invalid" in str(e).lower() or "error" in str(e).lower()


class TestTaskDifficulty:
    """Tests for task difficulty mapping."""

    def test_task_1_is_beginner(self):
        """Task 1 should map to beginner difficulty."""
        loader = DatasetLoader()

        if hasattr(loader, 'get_task_difficulty'):
            difficulty = loader.get_task_difficulty("task_1_factual_grounding")
            assert difficulty in ["beginner", "easy", 1, "1"]

    def test_task_2_is_intermediate(self):
        """Task 2 should map to intermediate difficulty."""
        loader = DatasetLoader()

        if hasattr(loader, 'get_task_difficulty'):
            difficulty = loader.get_task_difficulty("task_2_multi_hop_synthesis")
            assert difficulty in ["intermediate", "medium", 2, "2"]

    def test_task_3_is_advanced(self):
        """Task 3 should map to advanced difficulty."""
        loader = DatasetLoader()

        if hasattr(loader, 'get_task_difficulty'):
            difficulty = loader.get_task_difficulty("task_3_adversarial_resistance")
            assert difficulty in ["advanced", "hard", 3, "3"]