@@ -1683,5 +1683,74 @@ def test_plotmesh_elemselector(self):
16831683 self .assertEqual (np .round (np .sum (facecolors , axis = 0 ), 4 ).tolist (), expected_fc )
16841684
16851685
1686+ class TestUtilities (unittest .TestCase ):
1687+ """Test suite for utility and helper functions"""
1688+
1689+ def setUp (self ):
1690+ """Set up test fixtures"""
1691+ self .polyline = np .array (
1692+ [[0 , 0 ], [1 , 0 ], [2 , 1 ], [3 , 1 ], [4 , 0 ], [5 , 0 ]], dtype = float
1693+ )
1694+
1695+ def test_polylinelen_polyline_length (self ):
1696+ """Test polyline length calculation"""
1697+ result = polylinelen (self .polyline )[0 ]
1698+
1699+ self .assertEqual (
1700+ np .round (result , 8 ).tolist (), [1.0 , 1.41421356 , 1.0 , 1.41421356 , 1.0 ]
1701+ )
1702+
1703+ def test_polylinesimplify_polyline_simplification (self ):
1704+ """Test polyline simplification"""
1705+ tolerance = 0.1
1706+ result = polylinesimplify (self .polyline , 3.14 )
1707+
1708+ self .assertLessEqual (result [0 ].tolist (), [[0 , 0 ], [5 , 0 ]])
1709+ self .assertLessEqual (result [1 ], 5 )
1710+
1711+ def test_polylineinterp_polyline_interpolation (self ):
1712+ """Test polyline interpolation"""
1713+ # Interpolate at specific length
1714+ polylen = polylinelen (self .polyline )[0 ]
1715+ loc = [1.3 , 2.7 ]
1716+ result = polylineinterp (polylen , loc )
1717+
1718+ self .assertEqual (result [0 ].tolist (), [2 , 3 ])
1719+ self .assertEqual (np .round (result [1 ], 8 ).tolist (), [0.21213203 , 0.28578644 ])
1720+
1721+ def test_varargin2struct_argument_parsing (self ):
1722+ """Test argument parsing to structure"""
1723+ # Test with key-value pairs
1724+ result = varargin2struct ("key1" , "value1" , "key2" , 42 , "key3" , [1 , 2 , 3 ])
1725+
1726+ self .assertEqual (result ["key1" ], "value1" )
1727+ self .assertEqual (result ["key2" ], 42 )
1728+
1729+ def test_jsonopt_json_options (self ):
1730+ """Test JSON options processing"""
1731+ options = {"option1" : "value1" , "option2" : 42 }
1732+ key = "option1"
1733+ default = "default_value"
1734+
1735+ result = jsonopt (key , default , options )
1736+
1737+ if result is not None :
1738+ self .assertEqual (result , "value1" )
1739+
1740+ # Test with non-existent key
1741+ result = jsonopt ("nonexistent" , default , options )
1742+ if result is not None :
1743+ self .assertEqual (result , default )
1744+
1745+ def test_closestnode_closest_node_finding (self ):
1746+ """Test closest node finding"""
1747+ nodes = self .polyline
1748+ query_point = np .array ([1.5 , 0.5 ], dtype = float )
1749+
1750+ result = closestnode (nodes , query_point )
1751+
1752+ self .assertEqual (result , (2 , 0.5 ))
1753+
1754+
16861755if __name__ == "__main__" :
16871756 unittest .main ()
0 commit comments