initial commit
This commit is contained in:
53
tests/test_transform/test_cfc.py
Normal file
53
tests/test_transform/test_cfc.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""Tests for CFC filtering."""
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from impakt.transform.cfc import CFCFilter, cfc_filter
|
||||
|
||||
|
||||
class TestCFCFilter:
|
||||
def test_cfc60(self, head_accel_x):
|
||||
filtered = cfc_filter(head_accel_x, 60)
|
||||
assert filtered.cfc_class == 60
|
||||
assert len(filtered.data) == len(head_accel_x.data)
|
||||
# Filtered signal should be smoother (lower peak)
|
||||
assert filtered.peak <= head_accel_x.peak
|
||||
# But still retain the general shape
|
||||
assert filtered.peak > 20.0 # Not completely killed
|
||||
|
||||
def test_cfc180(self, head_accel_x):
|
||||
filtered = cfc_filter(head_accel_x, 180)
|
||||
assert filtered.cfc_class == 180
|
||||
|
||||
def test_cfc600(self, head_accel_x):
|
||||
filtered = cfc_filter(head_accel_x, 600)
|
||||
assert filtered.cfc_class == 600
|
||||
|
||||
def test_cfc1000(self, head_accel_x):
|
||||
filtered = cfc_filter(head_accel_x, 1000)
|
||||
assert filtered.cfc_class == 1000
|
||||
# CFC 1000 removes very little — peak should be close to original
|
||||
assert abs(filtered.peak - head_accel_x.peak) < 5.0
|
||||
|
||||
def test_invalid_cfc_class(self):
|
||||
with pytest.raises(ValueError, match="Invalid CFC class"):
|
||||
CFCFilter(cfc_class=42)
|
||||
|
||||
def test_transform_history(self, head_accel_x):
|
||||
filtered = cfc_filter(head_accel_x, 180)
|
||||
assert len(filtered.transform_history) == 1
|
||||
assert "CFC 180" in filtered.transform_history[0]
|
||||
|
||||
def test_original_unchanged(self, head_accel_x):
|
||||
original_data = head_accel_x.data.copy()
|
||||
_ = cfc_filter(head_accel_x, 180)
|
||||
assert np.array_equal(head_accel_x.data, original_data)
|
||||
|
||||
def test_progressive_filtering(self, head_accel_x):
|
||||
"""Lower CFC classes should produce smoother (lower peak) output."""
|
||||
peak_1000 = cfc_filter(head_accel_x, 1000).peak
|
||||
peak_600 = cfc_filter(head_accel_x, 600).peak
|
||||
peak_180 = cfc_filter(head_accel_x, 180).peak
|
||||
peak_60 = cfc_filter(head_accel_x, 60).peak
|
||||
assert peak_1000 >= peak_600 >= peak_180 >= peak_60
|
||||
Reference in New Issue
Block a user