@@ -148,60 +148,6 @@ def test_tupled_dimension_3d():
148148 verify_tupled_output (actual , array , axis , indices )
149149
150150
151- def create_test_objectives (shape = (5 , 10 )):
152- """Create test objectives dataset."""
153- objectives = xr .Dataset ()
154- for var in ["a" , "b" , "c" ]:
155- objectives [var ] = ("asset" , "replacement" ), np .random .rand (* shape ) * 10 - 5
156- objectives ["asset" ] = np .random .choice (
157- objectives .replacement , len (objectives .asset ), replace = False
158- )
159- return objectives
160-
161-
162- def create_test_binsizes ():
163- """Create test binsizes dataset."""
164- return xr .Dataset (
165- {
166- "a" : np .random .rand () * 0.1 ,
167- "b" : - np .random .rand () * 0.1 ,
168- "c" : np .random .rand (),
169- }
170- )
171-
172-
173- @mark .parametrize ("order" , [["a" , "b" , "c" ], ["b" , "c" , "a" ], ["c" , "a" , "b" ]])
174- def test_lexical_comparison (order ):
175- """Test lexical comparison with and without binning."""
176- from muse .utilities import lexical_comparison
177-
178- objectives = create_test_objectives ()
179- binsizes = create_test_binsizes ()
180-
181- def create_expected (bin_last = True ):
182- expected = np .zeros (shape = objectives .a .shape , dtype = object )
183- for i in range (expected .shape [0 ]):
184- for j in range (expected .shape [1 ]):
185- values = []
186- for k in range (3 ):
187- val = objectives [order [k ]][i , j ] / binsizes [order [k ]]
188- values .append (int (np .floor (val )) if bin_last or k < 2 else val )
189- expected [i , j ] = tuple (values )
190- return expected
191-
192- # Test with binning
193- actual = lexical_comparison (objectives , binsizes [order ])
194- expected = create_expected (bin_last = True )
195- assert actual .shape == expected .shape
196- assert (actual .values == expected ).all ()
197-
198- # Test without binning last value
199- actual = lexical_comparison (objectives , binsizes [order ], bin_last = False )
200- expected = create_expected (bin_last = False )
201- assert actual .shape == expected .shape
202- assert (actual .values == expected ).all ()
203-
204-
205151def test_merge_assets ():
206152 """Test merging assets with different coordinate orders."""
207153 from numpy import arange
0 commit comments