From bd0d0e6fea42bb1312f79bfffc37aab6f3224d56 Mon Sep 17 00:00:00 2001 From: sbaldu Date: Wed, 31 Jan 2024 18:28:07 +0100 Subject: [PATCH] Remove test files for periodic coordinates (to readd in the future) --- tests/test_change_domains.py | 100 ---------------------------------- tests/test_circles_dataset.py | 41 -------------- tests/test_domain_extremes.py | 34 ------------ 3 files changed, 175 deletions(-) delete mode 100644 tests/test_change_domains.py delete mode 100644 tests/test_circles_dataset.py delete mode 100644 tests/test_domain_extremes.py diff --git a/tests/test_change_domains.py b/tests/test_change_domains.py deleted file mode 100644 index 5145c120..00000000 --- a/tests/test_change_domains.py +++ /dev/null @@ -1,100 +0,0 @@ -''' -Testing the function for changing the domain ranges, using the blob dataset as a reference -''' - -from math import pi -import numpy as np -import pytest -import sys -sys.path.insert(1, '../CLUEstering/') -import CLUEstering as clue - - -@pytest.fixture -def blob(): - ''' - Returns the dataframe containing the blob dataset - ''' - csv_file = './test_datasets/blob.csv' - return csv_file - - -def test_default_domains(blob): - ''' - Check the values of the default domain ranges - ''' - clust = clue.clusterer(0.5, 5., 1.2) - clust.read_data(blob) - - # Check that the domains extremes of the two coordinates are the default ones - # equal to +/- the numerical limit of a float - assert clust.clust_data.domain_ranges[0].min == -3.4028234663852886e+38 - assert clust.clust_data.domain_ranges[0].max == 3.4028234663852886e+38 - assert clust.clust_data.domain_ranges[1].min == -3.4028234663852886e+38 - assert clust.clust_data.domain_ranges[1].max == 3.4028234663852886e+38 - - -def test_change_domains_1(): - ''' - Check the renormalization for uniform data - ''' - # We generate data with zero mean and standard deviation, so that the - # domain extremes are not normalized by the standard scaler - x0 = np.zeros(shape=5) - x1 = np.zeros(shape=5) - weight = np.full(shape=5, fill_value=1) - data = {'x0': x0, 'x1': x1, 'weight': weight} - - clust = clue.clusterer(0.5, 5., 1.2) - clust.read_data(data) - - # Check that the original domains are the numerical limits of float - # like in the previous test case - assert clust.clust_data.domain_ranges[0].min == -3.4028234663852886e+38 - assert clust.clust_data.domain_ranges[0].max == 3.4028234663852886e+38 - assert clust.clust_data.domain_ranges[1].min == -3.4028234663852886e+38 - assert clust.clust_data.domain_ranges[1].max == 3.4028234663852886e+38 - - # Change the domains - clust.change_domains(x0=(0., 2.), x1=(-pi, pi)) - - # Check that the new domains are (0, 2) and (-pi, pi) - assert clust.clust_data.domain_ranges[0].min == 0. - assert clust.clust_data.domain_ranges[0].max == 2. - assert clust.clust_data.domain_ranges[1].min == pytest.approx( - -pi, 0.0000001) - assert clust.clust_data.domain_ranges[1].max == pytest.approx( - pi, 0.0000001) - - -def test_change_domains_2(): - ''' - Check the renormalization for non-uniform data - ''' - # We generate data with non-zero mean and standard deviation, and we check - # that the domain exctremes are re-calculated as expected by the scaler - x0 = np.arange(0, 5) - x1 = np.arange(0, 5) - weight = np.full(shape=5, fill_value=1) - data = {'x0': x0, 'x1': x1, 'weight': weight} - - clust = clue.clusterer(0.5, 5., 1.2) - clust.read_data(data) - - # Check that the original domains are the numerical limits of float - # like in the previous test case - assert clust.clust_data.domain_ranges[0].min == -3.4028234663852886e+38 - assert clust.clust_data.domain_ranges[0].max == 3.4028234663852886e+38 - assert clust.clust_data.domain_ranges[1].min == -3.4028234663852886e+38 - assert clust.clust_data.domain_ranges[1].max == 3.4028234663852886e+38 - - # Change the domains - clust.change_domains(x0=(0., 2.), x1=(-pi, pi)) - - # Check that the new domains are (0, 2) and (-pi, pi) - assert clust.clust_data.domain_ranges[0].min == pytest.approx(-1.41, 0.01) - assert clust.clust_data.domain_ranges[0].max == 0. - assert clust.clust_data.domain_ranges[1].min == pytest.approx( - -3.6356550, 0.0000001) - assert clust.clust_data.domain_ranges[1].max == pytest.approx( - 0.8072279, 0.0000001) diff --git a/tests/test_circles_dataset.py b/tests/test_circles_dataset.py deleted file mode 100644 index b299b308..00000000 --- a/tests/test_circles_dataset.py +++ /dev/null @@ -1,41 +0,0 @@ -''' -Testing the algorithm on the circle dataset, a dataset where points are distributed to form -two concentric circles -''' - -from filecmp import cmp -import numpy as np -import os -import pandas as pd -import pytest -import sys -sys.path.insert(1, '../CLUEstering/') -import CLUEstering as clue - - -@pytest.fixture -def circles(): - ''' - Returns the dataframe containing the circle dataset - ''' - return pd.read_csv("./test_datasets/circles.csv") - - -def test_circles_clustering(circles): - ''' - Checks that the output of the clustering is the one given by the truth dataset - ''' - - # Check if the output file already exists and if it does, delete it - if os.path.isfile('./circles_output.csv'): - os.remove('./circles_output.csv') - - c = clue.clusterer(0.9, 5, 1.5) - c.read_data(circles) - c.change_coordinates(x0=lambda x: np.sqrt(x[0]**2 + x[1]**2), - x1=lambda x: np.arctan2(x[1], x[0])) - c.run_clue() - c.to_csv('./', 'circles_output.csv') - - assert cmp('./circles_output.csv', - './test_datasets/truth_files/circles_1000_truth.csv') diff --git a/tests/test_domain_extremes.py b/tests/test_domain_extremes.py deleted file mode 100644 index 10e9388a..00000000 --- a/tests/test_domain_extremes.py +++ /dev/null @@ -1,34 +0,0 @@ -''' -Test that points at opposite extremes of a finite domain are adjacent -''' - -from math import pi -import pandas as pd -import pytest -import sys -sys.path.insert(1, '../CLUEstering/') -import CLUEstering as clue - - -@pytest.fixture -def opposite_angles(): - ''' - Returns a dataset with points distributed at opposite sides of a finite range - ''' - return pd.read_csv("./test_datasets/opposite_angles.csv") - - -def test_opposite_angles(opposite_angles): - ''' - Test the clustering of points at opposite angles - ''' - # Test points with angles distributed at opposite extremes of the domain - # This test assures that the code works for data with periodic coordinates - clust = clue.clusterer(0.1, 1, 1.1) - clust.read_data(opposite_angles, x1=(-pi, pi)) - clust.run_clue() - - # We just check that the number of clusters is one - # If it is, the code recognizes points at the opposite extremes of the domain - # as very near each other - assert clust.clust_prop.n_clusters == 1