Skip to content

Commit

Permalink
Use pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
runboj committed May 29, 2024
1 parent 81ae6e7 commit eae2c49
Showing 1 changed file with 34 additions and 40 deletions.
74 changes: 34 additions & 40 deletions src/_test/test_umap.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
import numpy as np
import unittest
import pytest

from mlex_dimension_reduction_pca.umap_run import computeUMAP


class TestComputeUMAP(unittest.TestCase):

def test_1d_input(self):
data = np.random.rand(100, 50)
result = computeUMAP(data, n_components=2)
self.assertEqual(result.shape, (100, 2), "Output shape should be (N, 2)")

def test_2d_input(self):
data = np.random.rand(100, 10, 10)
result = computeUMAP(data, n_components=2)
self.assertEqual(result.shape, (100, 2), "Output shape should be (N, 2)")

def test_n_components_3(self):
data = np.random.rand(100, 50)
result = computeUMAP(data, n_components=3)
self.assertEqual(result.shape, (100, 3), "Output shape should be (N, 3) when n_components=3")

def test_min_dist(self):
data = np.random.rand(100, 50)
result1 = computeUMAP(data, min_dist=0.1)
result2 = computeUMAP(data, min_dist=0.5)
self.assertNotEqual(np.sum(result1), np.sum(result2), "UMAP results should differ for different min_dist values")

def test_random_state(self):
data = np.random.rand(100, 50)
result1 = computeUMAP(data, random_state=42)
result2 = computeUMAP(data, random_state=42)
np.testing.assert_array_almost_equal(result1, result2, err_msg="Results should be the same for the same random_state")

def test_different_random_state(self):
data = np.random.rand(100, 50)
result1 = computeUMAP(data, random_state=42)
result2 = computeUMAP(data, random_state=24)
with self.assertRaises(AssertionError):
np.testing.assert_array_almost_equal(result1, result2, err_msg="Results should differ for different random_states")


if __name__ == '__main__':
unittest.main()
def test_1d_input():
data = np.random.rand(100, 50)
result = computeUMAP(data, n_components=2)
assert result.shape == (100, 2), "Output shape should be (N, 2)"

def test_2d_input():
data = np.random.rand(100, 10, 10)
result = computeUMAP(data, n_components=2)
assert result.shape == (100, 2), "Output shape should be (N, 2)"

def test_n_components_3():
data = np.random.rand(100, 50)
result = computeUMAP(data, n_components=3)
assert result.shape == (100, 3), "Output shape should be (N, 3) when n_components=3"

def test_min_dist():
data = np.random.rand(100, 50)
result1 = computeUMAP(data, min_dist=0.1)
result2 = computeUMAP(data, min_dist=0.5)
assert np.sum(result1) != np.sum(result2), "UMAP results should differ for different min_dist values"

def test_random_state():
data = np.random.rand(100, 50)
result1 = computeUMAP(data, random_state=42)
result2 = computeUMAP(data, random_state=42)
np.testing.assert_array_almost_equal(result1, result2, err_msg="Results should be the same for the same random_state")

def test_different_random_state():
data = np.random.rand(100, 50)
result1 = computeUMAP(data, random_state=42)
result2 = computeUMAP(data, random_state=24)
with pytest.raises(AssertionError):
np.testing.assert_array_almost_equal(result1, result2, err_msg="Results should differ for different random_states")

0 comments on commit eae2c49

Please sign in to comment.