Skip to content

Commit

Permalink
Expand package testing
Browse files Browse the repository at this point in the history
  • Loading branch information
iskandergaba committed Dec 28, 2024
1 parent 232afe4 commit c987ee8
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 3 deletions.
54 changes: 51 additions & 3 deletions tests/detectors/conftest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,65 @@
import numpy as np
import pytest
from scipy.signal import sawtooth
from statsmodels.datasets import co2


@pytest.fixture(scope="module")
def sinewave_10():
return sinewave(1000, 10, 1)


@pytest.fixture(scope="module")
def sinewave_50():
return sinewave(1000, 50, 1)


@pytest.fixture(scope="module")
def sinewave_100():
return sinewave(1000, 100, 1)


@pytest.fixture(scope="module")
def trianglewave_10():
return trianglewave(1000, 10, 1)


@pytest.fixture(scope="module")
def trianglewave_50():
return trianglewave(1000, 50, 1)


@pytest.fixture(scope="module")
def trianglewave_100():
return trianglewave(1000, 100, 1)


@pytest.fixture(scope="module")
def co2_daily():
return co2.load().data.resample("D").mean().ffill()
return co2_data().resample("D").mean().ffill()


@pytest.fixture(scope="module")
def co2_weekly():
return co2.load().data.resample("W").mean().ffill()
return co2_data().resample("W").mean().ffill()


@pytest.fixture(scope="module")
def co2_monthly():
return co2.load().data.resample("ME").mean().ffill()
return co2_data().resample("ME").mean().ffill()


def sinewave(n, period, amp):
x = np.arange(0, n, 1)
freq = 1 / period
return amp * np.sin(2 * np.pi * freq * x)


def trianglewave(n, period, amp):
x = np.arange(0, n, 1)
freq = 1 / period
return amp * sawtooth(2 * np.pi * freq * x, 0.5)


def co2_data():
return co2.load().data
35 changes: 35 additions & 0 deletions tests/detectors/test_acf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
from pyriodicity import ACFPeriodicityDetector


def test_sinewave_10_acf_find_all_periods(sinewave_10):
data = sinewave_10
periods = ACFPeriodicityDetector.detect(data)
assert len(periods) > 0
assert 10 in periods


def test_sinewave_50_acf_find_all_periods(sinewave_50):
data = sinewave_50
periods = ACFPeriodicityDetector.detect(data)
assert len(periods) > 0
assert 50 in periods


def test_sinewave_100_acf_find_all_periods(sinewave_100):
data = sinewave_100
periods = ACFPeriodicityDetector.detect(data)
assert len(periods) > 0
assert 100 in periods


def test_sinewave_10_acf_find_strongest_period(sinewave_10):
data = sinewave_10
periods = ACFPeriodicityDetector.detect(data, max_period_count=1)
assert len(periods) == 1
assert 10 in periods


def test_sinewave_50_acf_find_strongest_period(sinewave_50):
data = sinewave_50
periods = ACFPeriodicityDetector.detect(data, max_period_count=1)
assert len(periods) == 1
assert 50 in periods


def test_co2_daily_acf_default(co2_daily):
data = co2_daily
periods = ACFPeriodicityDetector.detect(data)
Expand Down
42 changes: 42 additions & 0 deletions tests/detectors/test_autoperiod.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
from pyriodicity import Autoperiod


def test_sinewave_10_autoperiod_find_all_periods(sinewave_10):
data = sinewave_10
periods = Autoperiod.detect(data)
assert len(periods) > 0
assert 10 in periods


def test_sinewave_50_autoperiod_find_all_periods(sinewave_50):
data = sinewave_50
periods = Autoperiod.detect(data)
assert len(periods) > 0
assert 50 in periods


def test_sinewave_100_autoperiod_find_all_periods(sinewave_100):
data = sinewave_100
periods = Autoperiod.detect(data)
assert len(periods) > 0
assert 100 in periods


def test_trianglewave_10_autoperiod_find_all_periods(trianglewave_10):
data = trianglewave_10
periods = Autoperiod.detect(data)
assert len(periods) > 0
assert 10 in periods


def test_trianglewave_50_autoperiod_find_all_periods(trianglewave_50):
data = trianglewave_50
periods = Autoperiod.detect(data)
assert len(periods) > 0
assert 50 in periods


def test_trianglewave_100_autoperiod_find_all_periods(trianglewave_100):
data = trianglewave_100
periods = Autoperiod.detect(data)
assert len(periods) > 0
assert 100 in periods


def test_co2_daily_autoperiod_default(co2_daily):
data = co2_daily
periods = Autoperiod.detect(data)
Expand Down
42 changes: 42 additions & 0 deletions tests/detectors/test_cfd_autoperiod.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
from pyriodicity import CFDAutoperiod


def test_sinewave_10_cfd_autoperiod_find_all_periods(sinewave_10):
data = sinewave_10
periods = CFDAutoperiod.detect(data)
assert len(periods) > 0
assert 10 in periods


def test_sinewave_50_cfd_autoperiod_find_all_periods(sinewave_50):
data = sinewave_50
periods = CFDAutoperiod.detect(data)
assert len(periods) > 0
assert 50 in periods


def test_sinewave_100_cfd_autoperiod_find_all_periods(sinewave_100):
data = sinewave_100
periods = CFDAutoperiod.detect(data)
assert len(periods) > 0
assert 100 in periods


def test_trianglewave_10_cfd_autoperiod_find_all_periods(trianglewave_10):
data = trianglewave_10
periods = CFDAutoperiod.detect(data)
assert len(periods) > 0
assert 10 in periods


def test_trianglewave_50_cfd_autoperiod_find_all_periods(trianglewave_50):
data = trianglewave_50
periods = CFDAutoperiod.detect(data)
assert len(periods) > 0
assert 50 in periods


def test_trianglewave_100_cfd_autoperiod_find_all_periods(trianglewave_100):
data = trianglewave_100
periods = CFDAutoperiod.detect(data)
assert len(periods) > 0
assert 100 in periods


def test_co2_daily_cfd_autoperiod_default(co2_daily):
data = co2_daily
periods = CFDAutoperiod.detect(data)
Expand Down
84 changes: 84 additions & 0 deletions tests/detectors/test_fft.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,90 @@
from pyriodicity import FFTPeriodicityDetector


def test_sinewave_10_fft_find_all_periods(sinewave_10):
data = sinewave_10
periods = FFTPeriodicityDetector.detect(data)
assert len(periods) > 0
assert 10 in periods


def test_sinewave_50_fft_find_all_periods(sinewave_50):
data = sinewave_50
periods = FFTPeriodicityDetector.detect(data)
assert len(periods) > 0
assert 50 in periods


def test_sinewave_100_fft_find_all_periods(sinewave_100):
data = sinewave_100
periods = FFTPeriodicityDetector.detect(data)
assert len(periods) > 0
assert 100 in periods


def test_sinewave_10_fft_find_strongest_period(sinewave_10):
data = sinewave_10
periods = FFTPeriodicityDetector.detect(data, max_period_count=1)
assert len(periods) == 1
assert 10 in periods


def test_sinewave_50_fft_find_strongest_period(sinewave_50):
data = sinewave_50
periods = FFTPeriodicityDetector.detect(data, max_period_count=1)
assert len(periods) == 1
assert 50 in periods


def test_sinewave_100_fft_find_strongest_period(sinewave_100):
data = sinewave_100
periods = FFTPeriodicityDetector.detect(data, max_period_count=1)
assert len(periods) == 1
assert 100 in periods


def test_trianglewave_10_fft_find_all_periods(trianglewave_10):
data = trianglewave_10
periods = FFTPeriodicityDetector.detect(data)
assert len(periods) > 0
assert 10 in periods


def test_trianglewave_50_fft_find_all_periods(trianglewave_50):
data = trianglewave_50
periods = FFTPeriodicityDetector.detect(data)
assert len(periods) > 0
assert 50 in periods


def test_trianglewave_100_fft_find_all_periods(trianglewave_100):
data = trianglewave_100
periods = FFTPeriodicityDetector.detect(data)
assert len(periods) > 0
assert 100 in periods


def test_trianglewave_10_fft_find_strongest_period(trianglewave_10):
data = trianglewave_10
periods = FFTPeriodicityDetector.detect(data, max_period_count=1)
assert len(periods) == 1
assert 10 in periods


def test_trianglewave_50_fft_find_strongest_period(trianglewave_50):
data = trianglewave_50
periods = FFTPeriodicityDetector.detect(data, max_period_count=1)
assert len(periods) == 1
assert 50 in periods


def test_trianglewave_100_fft_find_strongest_period(trianglewave_100):
data = trianglewave_100
periods = FFTPeriodicityDetector.detect(data, max_period_count=1)
assert len(periods) == 1
assert 100 in periods


def test_co2_monthly_fft_find_all_periods(co2_monthly):
data = co2_monthly
periods = FFTPeriodicityDetector.detect(data)
Expand Down
38 changes: 38 additions & 0 deletions tests/detectors/test_robustperiod.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
import pytest

from pyriodicity import RobustPeriod


def test_sinewave_10_robustperiod_default(sinewave_10):
data = sinewave_10
with pytest.raises(AttributeError):
RobustPeriod.detect(data)


def test_sinewave_50_robustperiod_default(sinewave_50):
data = sinewave_50
with pytest.raises(AttributeError):
RobustPeriod.detect(data)


def test_sinewave_100_robustperiod_default(sinewave_100):
data = sinewave_100
with pytest.raises(AttributeError):
RobustPeriod.detect(data)


def test_trianglewave_10_robustperiod_default(trianglewave_10):
data = trianglewave_10
with pytest.raises(AttributeError):
RobustPeriod.detect(data)


def test_trianglewave_50_robustperiod_default(trianglewave_50):
data = trianglewave_50
with pytest.raises(AttributeError):
RobustPeriod.detect(data)


def test_trianglewave_100_robustperiod_default(trianglewave_100):
data = trianglewave_100
with pytest.raises(AttributeError):
RobustPeriod.detect(data)


def test_co2_weekly_robustperiod_default(co2_weekly):
data = co2_weekly
periods = RobustPeriod.detect(data)
Expand Down

0 comments on commit c987ee8

Please sign in to comment.