Add artifact.1/tests/test_core.py
This commit is contained in:
parent
bb7a2b4b12
commit
2408cea66d
1 changed files with 64 additions and 0 deletions
64
artifact.1/tests/test_core.py
Normal file
64
artifact.1/tests/test_core.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import pytest
|
||||
from typing import List, Dict
|
||||
from src.artifact_1 import core
|
||||
|
||||
|
||||
class TestResult:
|
||||
def __init__(self, group: str, pinned_status: str, warn_rate: float, unknown_rate: float, delta_t_rate: float):
|
||||
self.group = group
|
||||
self.pinned_status = pinned_status
|
||||
self.warn_rate = warn_rate
|
||||
self.unknown_rate = unknown_rate
|
||||
self.delta_t_rate = delta_t_rate
|
||||
|
||||
|
||||
def make_sample_data() -> List[TestResult]:
|
||||
return [
|
||||
TestResult('A', 'pinned', 0.1, 0.05, 0.02),
|
||||
TestResult('A', 'pinned', 0.2, 0.1, 0.03),
|
||||
TestResult('A', 'unpinned', 0.3, 0.15, 0.04),
|
||||
TestResult('B', 'pinned', 0.15, 0.07, 0.01),
|
||||
TestResult('B', 'unpinned', 0.35, 0.12, 0.08),
|
||||
TestResult('B', 'unpinned', 0.4, 0.18, 0.06),
|
||||
]
|
||||
|
||||
|
||||
def test_analyze_ab_data_structure():
|
||||
data = make_sample_data()
|
||||
result = core.analyze_ab_data(data)
|
||||
assert isinstance(result, dict)
|
||||
# groups should contain A and B, with pinned/unpinned stratum inside
|
||||
for group_key in ['A', 'B']:
|
||||
assert group_key in result
|
||||
assert 'pinned' in result[group_key] or 'unpinned' in result[group_key]
|
||||
|
||||
|
||||
def test_aggregation_values():
|
||||
data = make_sample_data()
|
||||
result = core.analyze_ab_data(data)
|
||||
# A-pinned
|
||||
a_pinned = result['A']['pinned']
|
||||
assert pytest.approx(a_pinned['warn_rate_mean'], rel=1e-6) == (0.1 + 0.2) / 2
|
||||
assert pytest.approx(a_pinned['unknown_rate_mean'], rel=1e-6) == (0.05 + 0.1) / 2
|
||||
assert pytest.approx(a_pinned['delta_t_rate_mean'], rel=1e-6) == (0.02 + 0.03) / 2
|
||||
|
||||
# B-unpinned
|
||||
b_unpinned = result['B']['unpinned']
|
||||
assert pytest.approx(b_unpinned['warn_rate_mean'], rel=1e-6) == (0.35 + 0.4) / 2
|
||||
assert pytest.approx(b_unpinned['unknown_rate_mean'], rel=1e-6) == (0.12 + 0.18) / 2
|
||||
assert pytest.approx(b_unpinned['delta_t_rate_mean'], rel=1e-6) == (0.08 + 0.06) / 2
|
||||
|
||||
|
||||
def test_invalid_input_raises():
|
||||
# Input validation should fail for non-list input
|
||||
with pytest.raises((TypeError, ValueError)):
|
||||
core.analyze_ab_data('invalid_input')
|
||||
|
||||
# Input validation should fail for missing attributes
|
||||
class Bad:
|
||||
def __init__(self):
|
||||
self.group = 'A'
|
||||
|
||||
bad_data = [Bad()]
|
||||
with pytest.raises((AttributeError, ValueError)):
|
||||
core.analyze_ab_data(bad_data)
|
||||
Loading…
Reference in a new issue