Skip to content

Commit

Permalink
test(test_evaluation_methods): create mock test for qq-plot evaluatio…
Browse files Browse the repository at this point in the history
…n method
  • Loading branch information
ninopleno committed Dec 4, 2023
1 parent 211d2b5 commit 2c6bb68
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/test_evaluation_methods.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import unittest
from unittest.mock import patch

import numpy as np
import pandas as pd

from anomalytics.evals import ks_1sample
from anomalytics.evals import calculate_theoretical_q, ks_1sample, visualize_qq_plot


class TestEvaluationMethod(unittest.TestCase):
Expand All @@ -30,5 +31,35 @@ def test_ks_1sample_with_unimplemented_method(self):
with self.assertRaises(NotImplementedError):
ks_1sample(ts=self.sample_ts, stats_method="AE", fit_params={})

def test_calculate_theoretical_q_pot(self):
sorted_nonzero_ts, theoretical_q, params = calculate_theoretical_q(
ts=self.sample_ts, stats_method="POT", fit_params=self.fit_params
)

self.assertIsInstance((sorted_nonzero_ts, theoretical_q, params), tuple)
self.assertEqual(len(sorted_nonzero_ts), len(theoretical_q))
self.assertEqual(params, self.fit_params[0])

def test_calculate_theoretical_q_with_invalid_series(self):
with self.assertRaises(TypeError):
calculate_theoretical_q(ts="not a series", stats_method="POT", fit_params=self.fit_params)

def test_calculate_theoretical_q_with_unimplemented_method(self):
with self.assertRaises(NotImplementedError):
calculate_theoretical_q(ts=self.sample_ts, stats_method="AE", fit_params=[{}])

@patch("matplotlib.pyplot.show")
def test_visualize_qq_plot_with_valid_input(self, mock_show):
visualize_qq_plot(ts=self.sample_ts, stats_method="POT", fit_params=self.fit_params)
mock_show.assert_called_once()

def test_visualize_qq_plot_with_invalid_series(self):
with self.assertRaises(TypeError):
visualize_qq_plot(ts="not a series", stats_method="POT", fit_params=self.fit_params)

def test_visualize_qq_plot_with_unimplemented_method(self):
with self.assertRaises(NotImplementedError):
visualize_qq_plot(ts=self.sample_ts, stats_method="AE", fit_params=self.fit_params)

def tearDown(self) -> None:
return super().tearDown()

0 comments on commit 2c6bb68

Please sign in to comment.