Add spike_classifier/tests/test_core.py
This commit is contained in:
parent
6d3e66951d
commit
4177b8a40b
1 changed files with 43 additions and 0 deletions
43
spike_classifier/tests/test_core.py
Normal file
43
spike_classifier/tests/test_core.py
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
from spike_classifier import core
|
||||||
|
|
||||||
|
|
||||||
|
def load_test_data():
|
||||||
|
data_path = os.path.join(os.path.dirname(__file__), 'data', 'test_spikes.json')
|
||||||
|
with open(data_path, 'r', encoding='utf-8') as f:
|
||||||
|
return json.load(f)
|
||||||
|
|
||||||
|
|
||||||
|
def test_classify_spikes_returns_list():
|
||||||
|
json_data = load_test_data()
|
||||||
|
result = core.classify_spikes(json_data)
|
||||||
|
assert isinstance(result, list), 'Ergebnis sollte eine Liste sein.'
|
||||||
|
for item in result:
|
||||||
|
assert isinstance(item, dict), 'Jedes Element in der Liste sollte ein Dict sein.'
|
||||||
|
|
||||||
|
|
||||||
|
def test_spike_fields_present_and_types():
|
||||||
|
json_data = load_test_data()
|
||||||
|
results = core.classify_spikes(json_data)
|
||||||
|
required_fields = {'spike_id': str, 'cpu_path': str, 'reorder_score': float, 'timestamp': str, 'signature': str}
|
||||||
|
for spike in results:
|
||||||
|
for field, expected_type in required_fields.items():
|
||||||
|
assert field in spike, f"Feld {field} fehlt im Ergebnis."
|
||||||
|
assert isinstance(spike[field], expected_type), f"Feld {field} hat falschen Typ: {type(spike[field])} statt {expected_type}."
|
||||||
|
|
||||||
|
|
||||||
|
def test_reorder_score_range():
|
||||||
|
json_data = load_test_data()
|
||||||
|
results = core.classify_spikes(json_data)
|
||||||
|
for spike in results:
|
||||||
|
score = spike.get('reorder_score')
|
||||||
|
assert 0.0 <= score <= 1.0, 'reorder_score sollte zwischen 0.0 und 1.0 liegen.'
|
||||||
|
|
||||||
|
|
||||||
|
def test_unique_spike_ids():
|
||||||
|
json_data = load_test_data()
|
||||||
|
results = core.classify_spikes(json_data)
|
||||||
|
spike_ids = [s['spike_id'] for s in results]
|
||||||
|
assert len(spike_ids) == len(set(spike_ids)), 'spike_id-Werte sollten eindeutig sein.'
|
||||||
Loading…
Reference in a new issue