diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index d36a6cc..9ac0e1e 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -36,3 +36,10 @@ jobs: pip install --no-cache-dir Cython pip install -r requirements.txt pip install . + - name: Install extra dependencies for dataset + run: | + pip install torch + pip install torchvision + - name: Test with pytest + run: | + pytest diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 98c1595..4e4b584 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -41,7 +41,13 @@ jobs: pip install --no-cache-dir Cython pip install -r requirements.txt pip install . - + - name: Install extra dependencies for dataset + run: | + pip install torch + pip install torchvision + - name: Test with pytest + run: | + pytest # steps: # - uses: actions/checkout@v3 # - name: Install miniconda diff --git a/tests/__init__.py b/tests/__init__.py index 1bbcf9e..e69de29 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +0,0 @@ -"""Unit test package for prosemble.""" diff --git a/tests/test_core.py b/tests/test_core.py new file mode 100644 index 0000000..fceb06f --- /dev/null +++ b/tests/test_core.py @@ -0,0 +1 @@ +"""prosemble core test suite""" \ No newline at end of file diff --git a/tests/test_dataset.py b/tests/test_dataset.py new file mode 100644 index 0000000..ed12aa2 --- /dev/null +++ b/tests/test_dataset.py @@ -0,0 +1,81 @@ +"""prosemble dataset test suite""" + +import unittest +import numpy as np +from prosemble import datasets + + +class TestWDBC(unittest.TestCase): + def setUp(self): + self.data,self.labels = datasets.DATA().breast_cancer + + def test_size(self): + self.assertEqual(len(self.data), 569) + self.assertEqual(len(self.labels), 569) + + def test_dimensions(self): + self.assertEqual(self.data.shape[1], 30) + + def test_unique_labels(self): + self.assertEqual(len(np.unique(self.labels)), 2) + + def test_dims_selection(self): + self.input_features = self.data[:, [0, 1]] + self.assertEqual(self.input_features.shape[1], 2) + + +class TestS1(unittest.TestCase): + def setUp(self): + self.data,self.labels = datasets.DATA().S_1 + + def test_size(self): + self.assertEqual(len(self.data), 150) + self.assertEqual(len(self.labels), 150) + + def test_dimensions(self): + self.assertEqual(self.data.shape[1], 2) + + def test_unique_labels(self): + self.assertEqual(len(np.unique(self.labels)), 2) + + def test_dims_selection(self): + self.input_features = self.data[:, [0, 1]] + self.assertEqual(self.data.shape[1], 2) + + + + +class TestS2(unittest.TestCase): + def setUp(self): + self.data,self.labels = datasets.DATA().S_2 + + def test_size(self): + self.assertEqual(len(self.data), 200) + self.assertEqual(len(self.labels), 200) + + def test_dimensions(self): + self.assertEqual(self.data.shape[1], 2) + + def test_unique_labels(self): + self.assertEqual(len(np.unique(self.labels)), 2) + + def test_dims_selection(self): + self.input_features = self.data[:, [0, 1]] + self.assertEqual(self.data.shape[1], 2) + + + +class TestMnits(unittest.TestCase): + def setUp(self): + self.data,self.labels = datasets.DATA().mnist + + def test_size(self): + self.assertEqual(len(self.data), 70000) + self.assertEqual(len(self.labels), 70000) + + def test_dimensions(self): + self.assertEqual(self.data.shape[1], 28) + + def test_unique_labels(self): + self.assertEqual(len(np.unique(self.labels)), 10) + diff --git a/tests/test_models.py b/tests/test_models.py new file mode 100644 index 0000000..282d89b --- /dev/null +++ b/tests/test_models.py @@ -0,0 +1,247 @@ +"""prosemble.models test suite. """ + +import numpy as np +import prosemble.models as ps + + +input_data = np.array( + [ + [1, 2, 3, 4, 1, 3], + [1, 0, 3, 4, 1, 3], + [1, 2, 3, 9, 1, 3], + [6, 2, 5, 4, 1, 3], + [1, 0, 3, 2, 1, 7], + [9, 2, 6, 4, 8, 3], + [2, 2, 1, 4, 7, 3], + [2, 2, 0, 4, 7, 3], + [0, 2, 1, 4, 7, 3], + [2, 2, 3, 4, 7, 3], + [1, 2, 1, 4, 7, 3], + [1, 5, 1, 4, 1, 3], + [3, 1, 1, 2, 6, 1], + [9, 1, 3, 1, 6, 4], + ] +) + + + + +def test_hcm_model_build(): + model = ps.Kmeans( + data=input_data, + c=3, + num_inter=100, + epsilon=0.00001, + ord='fro', + plot_steps=True +) + +def test_afcm_model_build(): + model = ps.AFCM( + data=input_data, + c=3, + num_iter=1000, + epsilon=0.00001, + ord='fro', + m=2, + a=2, + b=2, + k=1, + set_U_matrix='fcm', + plot_steps=True +) + +def test_bgpc_model_build(): + model = ps.BGPC( + data=input_data, + c=3, + a_f=2, + b_f=0.5, + num_iter=100, + epsilon=0.00001, + ord='fro', + set_U_matrix='fcm', + plot_steps=True +) + +def test_fcm_model_build(): + model = ps.FCM( + data=input_data, + c=3, + m=2, + num_iter=100, + epsilon=0.00001, + ord='fro', + set_U_matrix=None, + plot_steps=True +) + + +def test_fpcm_model_build(): + model = ps.FPCM( + data=input_data, + c=3, + m=2, + eta=2, + num_iter=1000, + epsilon=0.00001, + ord='fro', + set_U_matrix='fcm', + plot_steps=True +) + +def test_ipcm_model_build(): + model= ps.IPCM1( + data=input_data, + c=3, + m_f=2, + m_p=2, + k=1, + num_iter=None, + epsilon=0.00001, + ord='fro', + set_U_matrix='fcm', + plot_steps=True +) + +def test_ipcm_2_model_build(): + model = ps.IPCM2( + data=input_data, + c=3, + m_f=2, + m_p=2, + num_iter=None, + epsilon=0.00001, + ord='fro', + set_U_matrix='fcm', + plot_steps=True +) + + +def test_kafcm_model_build(): + model = ps.KAFCM( + data=input_data, + c=3, + num_iter=1000, + epsilon=0.00001, + ord='fro', + m=2, + a=3, + b=3, + k=1, + sigma=1, + set_centroids='kfcm', + set_U_matrix='kfcm', + plot_steps=True +) + + +def test_kfcm_model_build(): + model = ps.KFCM( + data=input_data, + c=3, + num_iter=1000, + epsilon=0.001, + ord='fro', + set_prototypes=None, + m=2, + sigma=1, + set_U_matrix=None, + plot_steps=True +) + + +def test_kpfcm_model_build(): + model = ps.KFPCM( + data=input_data, + c=3, + num_iter=100, + epsilon=0.0001, + ord='fro', + m=2, + sigma=1, + eta=2, + set_centroids=None, + set_U_matrix='kfcm', + plot_steps=True +) + + +def test_kipcm_model_build(): + model = ps.KIPCM( + data=input_data, + c=3, + num_iter=1000, + epsilon=0.001, + ord='fro', + m_f=2, + m_p=2, + k=1, + sigma=10, + set_centroids='fcm', + set_U_matrix='fcm', + plot_steps=True +) + + + +def test_kipcm2_model_build(): + model = ps.KIPCM2( + data=input_data, + c=3, + num_iter=100, + epsilon=0.0001, + ord='fro', + m=2, + k=2, + sigma=10, + set_centroids='fcm', + set_U_matrix='fcm', + plot_steps=True +) + +def test_kpcm_model_build(): + model = ps.KPCM( + data=input_data, + c=3, + num_iter=100, + epsilon=0.001, + ord='fro', + m=2, + k=0.06, + sigma=1, + set_centroids=None, + set_U_matrix='kfcm', + plot_steps=True +) + + +def test_pcm_model_build(): + model= ps.PCM( + data=input_data, + c=3, + m=2, + k=0.001, + num_iter=1000, + epsilon=0.00001, + ord='fro', + set_U_matrix='fcm', + plot_steps=True +) + +def test_pfcm_model_buidl(): + model= ps.PFCM( + data=input_data, + c=3, + m=2, + eta=2, + k=1, + a=2, + b=2, + num_iter=1000, + epsilon=0.00001, + ord='fro', + set_U_matrix='fcm', + plot_steps=True +) + diff --git a/tests/test_prosemble.py b/tests/test_prosemble.py deleted file mode 100644 index e76a56b..0000000 --- a/tests/test_prosemble.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python - -"""Tests for `prosemble` package.""" - - -import unittest - -# from prosemble import prosemble - - -class TestProsemble(unittest.TestCase): - """Tests for `prosemble` package.""" - - def setUp(self): - """Set up test fixtures, if any.""" - - def tearDown(self): - """Tear down test fixtures, if any.""" - - def test_000_something(self): - """Test something."""