Spaces:
Running
Running
| """Backend functions test suite. | |
| This module contains unit tests for the backend functions of the application. | |
| This module is designed to ensure the correctness and reliability of the backend logic | |
| """ | |
| import unittest | |
| from src.app_backend import ( | |
| footprint_corner_crd, | |
| cloud_liquid_water_content, | |
| polygon_cross_points, | |
| frame_corner_crd, | |
| kulemin_specific_rcs, | |
| itu_cloud_attenuation, | |
| itu_rain_attenuation, | |
| bistatic_radar_model | |
| ) | |
| class TestBackendFunctions(unittest.TestCase): | |
| def test_footprint_corner_crd(self): | |
| result = footprint_corner_crd('A', 1000, 500, 30, 60) | |
| self.assertNotEqual(result, 'none') | |
| self.assertIsInstance(result, list) | |
| self.assertEqual(len(result), 2) | |
| def test_cloud_liquid_water_content(self): | |
| self.assertAlmostEqual(cloud_liquid_water_content(1000), 0.132574, places=5) | |
| self.assertEqual(cloud_liquid_water_content(0), 0) | |
| def test_polygon_cross_points(self): | |
| polygon = [[0, 1, 1, 0], [0, 0, 1, 1]] | |
| result = polygon_cross_points(polygon, 0.5) | |
| self.assertEqual(result, [0.0, 1.0]) | |
| def test_frame_corner_crd(self): | |
| result = frame_corner_crd(1000, 500, 30, 60) | |
| self.assertNotEqual(result, 'none') | |
| self.assertIsInstance(result, list) | |
| self.assertEqual(len(result), 2) | |
| def test_kulemin_specific_rcs(self): | |
| result = kulemin_specific_rcs('лес летом', 45) | |
| self.assertIsInstance(result, float) | |
| self.assertNotEqual(result, -20) | |
| unknown_surface = kulemin_specific_rcs('unknown', 45) | |
| self.assertEqual(unknown_surface, -20) | |
| def test_itu_cloud_attenuation(self): | |
| result = itu_cloud_attenuation() | |
| self.assertIsInstance(result, float) | |
| self.assertGreater(result, 0) | |
| def test_itu_rain_attenuation(self): | |
| result = itu_rain_attenuation(10, 45) | |
| self.assertIsInstance(result, float) | |
| self.assertGreaterEqual(result, 0) | |
| def test_bistatic_radar_model(self): | |
| result = bistatic_radar_model( | |
| v=200, | |
| h=1000, | |
| uav_interval=500, | |
| psi_t=30, | |
| psi_r=60, | |
| srcs='лес летом', | |
| cloud_base=500, | |
| cloud_thickness=1000, | |
| rain_rate=10 | |
| ) | |
| self.assertNotEqual(result, 'none') | |
| self.assertIsInstance(result, dict) | |
| self.assertIn('dx', result) | |
| self.assertIn('dy', result) | |
| self.assertIn('snr', result) | |
| self.assertIn('tau', result) | |
| self.assertIn('tau_echo', result) | |
| self.assertIn('t_repeat', result) | |
| self.assertIn('t_synthesis_max', result) | |
| if __name__ == '__main__': | |
| unittest.main() |