|
| 1 | +import unittest |
| 2 | +import numpy as np |
| 3 | +from ect import SECT, ECT |
| 4 | +from ect.utils.examples import create_example_graph |
| 5 | +from ect.directions import Directions |
| 6 | + |
| 7 | + |
| 8 | +class TestSECT(unittest.TestCase): |
| 9 | + def setUp(self): |
| 10 | + """Set up test fixtures""" |
| 11 | + self.graph = create_example_graph() |
| 12 | + self.num_dirs = 8 |
| 13 | + self.num_thresh = 10 |
| 14 | + self.sect = SECT(num_dirs=self.num_dirs, num_thresh=self.num_thresh) |
| 15 | + |
| 16 | + def test_inheritance(self): |
| 17 | + """Test that SECT properly inherits from ECT""" |
| 18 | + self.assertIsInstance(self.sect, ECT) |
| 19 | + self.assertTrue(hasattr(self.sect, "calculate")) |
| 20 | + |
| 21 | + def test_calculate_output_shape(self): |
| 22 | + """Test that SECT calculation returns correct shape""" |
| 23 | + result = self.sect.calculate(self.graph) |
| 24 | + |
| 25 | + self.assertEqual(result.shape[0], self.num_dirs) |
| 26 | + self.assertEqual(result.shape[1], self.num_thresh) |
| 27 | + self.assertEqual(len(result.thresholds), self.num_thresh) |
| 28 | + self.assertEqual(len(result.directions), self.num_dirs) |
| 29 | + |
| 30 | + def test_smoothing_effect(self): |
| 31 | + """Test that smoothing is actually applied""" |
| 32 | + # Calculate both ECT and SECT |
| 33 | + ect = ECT(num_dirs=self.num_dirs, num_thresh=self.num_thresh) |
| 34 | + sect = SECT(num_dirs=self.num_dirs, num_thresh=self.num_thresh) |
| 35 | + |
| 36 | + ect_result = ect.calculate(self.graph) |
| 37 | + sect_result = sect.calculate(self.graph) |
| 38 | + |
| 39 | + # Verify results are different due to smoothing |
| 40 | + self.assertFalse(np.allclose(ect_result, sect_result)) |
| 41 | + |
| 42 | + # Verify smoothing preserves direction count |
| 43 | + self.assertEqual( |
| 44 | + np.sum(ect_result, axis=1).shape, |
| 45 | + np.sum(sect_result, axis=1).shape, |
| 46 | + ) |
| 47 | + |
| 48 | + def test_with_theta(self): |
| 49 | + """Test SECT calculation with specific theta value""" |
| 50 | + theta = np.pi / 4 |
| 51 | + result = self.sect.calculate(self.graph, theta=theta) |
| 52 | + |
| 53 | + # Should only have one direction when theta is specified |
| 54 | + self.assertEqual(result.shape[0], 1) |
| 55 | + self.assertEqual(result.shape[1], self.num_thresh) |
| 56 | + |
| 57 | + def test_with_override_radius(self): |
| 58 | + """Test SECT calculation with override_bound_radius""" |
| 59 | + override_radius = 2.0 |
| 60 | + result = self.sect.calculate(self.graph, override_bound_radius=override_radius) |
| 61 | + |
| 62 | + # Check that thresholds are within the override radius |
| 63 | + self.assertLessEqual(np.max(np.abs(result.thresholds)), override_radius) |
| 64 | + |
| 65 | + def test_smooth_matrix_properties(self): |
| 66 | + """Test properties of the smoothed matrix""" |
| 67 | + result = self.sect.calculate(self.graph) |
| 68 | + |
| 69 | + # Smoothed values should be finite |
| 70 | + self.assertTrue(np.all(np.isfinite(result))) |
| 71 | + |
| 72 | + # Shape should be preserved after smoothing |
| 73 | + self.assertEqual(result.shape, (self.num_dirs, self.num_thresh)) |
| 74 | + |
| 75 | + # Verify result is float type after smoothing |
| 76 | + self.assertTrue(np.issubdtype(result.dtype, np.floating)) |
0 commit comments