4343STAT_TYPE_MEDIAN_DIFF = 7
4444
4545
46+ # Names for each statistic identifier defined in this module.
47+ STAT_NAME_MEAN_ABS_DIFF = "mean_absolute_diff"
48+ STAT_NAME_RMS_DIFF = "root_mean_square_diff"
49+ STAT_NAME_STD_POPULATION_DEV = "population_std_dev"
50+ STAT_NAME_POPULATION_VARIANCE = "population_variance"
51+ STAT_NAME_PEAK_TO_PEAK_DIFF = "peak_to_peak_diff"
52+ STAT_NAME_SIGNAL_TO_NOISE_RATIO = "signal_to_noise_ratio"
53+ STAT_NAME_MEAN_DIFF = "mean_diff"
54+ STAT_NAME_MEDIAN_DIFF = "median_diff"
55+ STAT_NAME_LIST = [
56+ STAT_NAME_MEAN_ABS_DIFF ,
57+ STAT_NAME_RMS_DIFF ,
58+ STAT_NAME_STD_POPULATION_DEV ,
59+ STAT_NAME_POPULATION_VARIANCE ,
60+ STAT_NAME_PEAK_TO_PEAK_DIFF ,
61+ STAT_NAME_SIGNAL_TO_NOISE_RATIO ,
62+ STAT_NAME_MEAN_DIFF ,
63+ STAT_NAME_MEDIAN_DIFF ,
64+ ]
65+
66+
4667# @unittest.skip
4768class TestAnimCurveDiffStatistics (test_tools_utils .ToolsTestCase ):
4869 def _parse_diff_statistics_result (self , result ):
@@ -56,21 +77,21 @@ def _parse_diff_statistics_result(self, result):
5677 stat_value = result [i + 1 ]
5778
5879 if stat_type == STAT_TYPE_MEAN_ABSOLUTE_DIFF :
59- stats ["mean_absolute_diff" ] = stat_value
80+ stats [STAT_NAME_MEAN_ABS_DIFF ] = stat_value
6081 elif stat_type == STAT_TYPE_RMS_DIFF :
61- stats ["rms_diff" ] = stat_value
82+ stats [STAT_NAME_RMS_DIFF ] = stat_value
6283 elif stat_type == STAT_TYPE_POPULATION_STD_DEV :
63- stats ["population_std_dev" ] = stat_value
84+ stats [STAT_NAME_STD_POPULATION_DEV ] = stat_value
6485 elif stat_type == STAT_TYPE_PEAK_TO_PEAK_DIFF :
65- stats ["peak_to_peak_diff" ] = stat_value
86+ stats [STAT_NAME_PEAK_TO_PEAK_DIFF ] = stat_value
6687 elif stat_type == STAT_TYPE_SIGNAL_TO_NOISE_RATIO :
67- stats ["signal_to_noise_ratio" ] = stat_value
88+ stats [STAT_NAME_SIGNAL_TO_NOISE_RATIO ] = stat_value
6889 elif stat_type == STAT_TYPE_POPULATION_VARIANCE :
69- stats ["population_variance" ] = stat_value
90+ stats [STAT_NAME_POPULATION_VARIANCE ] = stat_value
7091 elif stat_type == STAT_TYPE_MEAN_DIFF :
71- stats ["mean_diff" ] = stat_value
92+ stats [STAT_NAME_MEAN_DIFF ] = stat_value
7293 elif stat_type == STAT_TYPE_MEDIAN_DIFF :
73- stats ["median_diff" ] = stat_value
94+ stats [STAT_NAME_MEDIAN_DIFF ] = stat_value
7495
7596 i += 2
7697
@@ -108,37 +129,29 @@ def test_diff_statistics_basic(self):
108129 stats = self ._parse_diff_statistics_result (result )
109130
110131 # Verify all expected statistics are present.
111- expected_stats = [
112- "mean_absolute_diff" ,
113- "rms_diff" ,
114- "population_std_dev" ,
115- "peak_to_peak_diff" ,
116- "signal_to_noise_ratio" ,
117- "population_variance" ,
118- "mean_diff" ,
119- "median_diff" ,
120- ]
121-
122- for stat_name in expected_stats :
132+ for stat_name in STAT_NAME_LIST :
123133 self .assertIn (stat_name , stats )
124134 self .assertTrue (
125135 math .isfinite (stats [stat_name ]),
126136 "{} is not finite: {}" .format (stat_name , stats [stat_name ]),
127137 )
138+ self .assertEquals (len (stats .keys ()), len (STAT_NAME_LIST ))
128139
129140 # Verify relationships between statistics.
130141 # Standard deviation should be sqrt(variance).
131- expected_std = math .sqrt (stats ["population_variance" ])
132- self .assertAlmostEqual (stats ["population_std_dev" ], expected_std , places = 5 )
142+ expected_std = math .sqrt (stats [STAT_NAME_POPULATION_VARIANCE ])
143+ self .assertAlmostEqual (
144+ stats [STAT_NAME_STD_POPULATION_DEV ], expected_std , places = 5
145+ )
133146
134147 # Mean absolute diff should be >= 0.
135- self .assertGreaterEqual (stats ["mean_absolute_diff" ], 0.0 )
148+ self .assertGreaterEqual (stats [STAT_NAME_MEAN_ABS_DIFF ], 0.0 )
136149
137150 # RMS should be >= 0.
138- self .assertGreaterEqual (stats ["rms_diff" ], 0.0 )
151+ self .assertGreaterEqual (stats [STAT_NAME_RMS_DIFF ], 0.0 )
139152
140153 # Peak-to-peak should be >= 0.
141- self .assertGreaterEqual (stats ["peak_to_peak_diff" ], 0.0 )
154+ self .assertGreaterEqual (stats [STAT_NAME_PEAK_TO_PEAK_DIFF ], 0.0 )
142155
143156 def test_diff_statistics_identical_curves (self ):
144157 """Test statistics when comparing identical curves."""
@@ -176,13 +189,10 @@ def test_diff_statistics_identical_curves(self):
176189 stats = self ._parse_diff_statistics_result (result )
177190
178191 # For identical curves, all differences should be zero.
179- self .assertAlmostEqual (stats ["mean_absolute_diff" ], 0.0 , places = 5 )
180- self .assertAlmostEqual (stats ["rms_diff" ], 0.0 , places = 5 )
181- self .assertAlmostEqual (stats ["mean_diff" ], 0.0 , places = 5 )
182- self .assertAlmostEqual (stats ["median_diff" ], 0.0 , places = 5 )
183- self .assertAlmostEqual (stats ["population_variance" ], 0.0 , places = 5 )
184- self .assertAlmostEqual (stats ["population_std_dev" ], 0.0 , places = 5 )
185- self .assertAlmostEqual (stats ["peak_to_peak_diff" ], 0.0 , places = 5 )
192+ for stat_name in STAT_NAME_LIST :
193+ stat = stats [stat_name ]
194+ self .assertAlmostEqual (stat , 0.0 , places = 5 )
195+ self .assertEquals (len (stats .keys ()), len (STAT_NAME_LIST ))
186196
187197 def test_diff_statistics_constant_offset (self ):
188198 """Test statistics with curves that have a constant offset."""
@@ -221,15 +231,15 @@ def test_diff_statistics_constant_offset(self):
221231
222232 # For constant offset:
223233 # - Mean diff should equal the offset.
224- self .assertAlmostEqual (stats ["mean_diff" ], - offset , places = 5 )
234+ self .assertAlmostEqual (stats [STAT_NAME_MEAN_DIFF ], - offset , places = 5 )
225235 # - Mean absolute diff should equal abs(offset).
226- self .assertAlmostEqual (stats ["mean_absolute_diff" ], abs (offset ), places = 5 )
236+ self .assertAlmostEqual (stats [STAT_NAME_MEAN_ABS_DIFF ], abs (offset ), places = 5 )
227237 # - Median diff should equal the offset.
228- self .assertAlmostEqual (stats ["median_diff" ], - offset , places = 5 )
238+ self .assertAlmostEqual (stats [STAT_NAME_MEDIAN_DIFF ], - offset , places = 5 )
229239 # - Variance should be 0 (no variation in differences).
230- self .assertAlmostEqual (stats ["population_variance" ], 0.0 , places = 5 )
240+ self .assertAlmostEqual (stats [STAT_NAME_POPULATION_VARIANCE ], 0.0 , places = 5 )
231241 # - Peak-to-peak should be 0.
232- self .assertAlmostEqual (stats ["peak_to_peak_diff" ], 0.0 , places = 5 )
242+ self .assertAlmostEqual (stats [STAT_NAME_PEAK_TO_PEAK_DIFF ], 0.0 , places = 5 )
233243
234244 def test_diff_statistics_frame_range (self ):
235245 """Test statistics with different frame ranges."""
@@ -266,8 +276,8 @@ def test_diff_statistics_frame_range(self):
266276
267277 # Statistics should be different for different ranges.
268278 self .assertNotAlmostEqual (
269- stats_full ["mean_absolute_diff" ],
270- stats_partial ["mean_absolute_diff" ],
279+ stats_full [STAT_NAME_MEAN_ABS_DIFF ],
280+ stats_partial [STAT_NAME_MEAN_ABS_DIFF ],
271281 places = 2 ,
272282 )
273283
@@ -307,10 +317,10 @@ def test_diff_statistics_noise_detection(self):
307317 stats = self ._parse_diff_statistics_result (result )
308318
309319 # Verify noise is detected.
310- self .assertGreater (stats ["population_std_dev" ], 0.1 )
311- self .assertGreater (stats ["rms_diff" ], 0.1 )
320+ self .assertGreater (stats [STAT_NAME_STD_POPULATION_DEV ], 0.1 )
321+ self .assertGreater (stats [STAT_NAME_RMS_DIFF ], 0.1 )
312322 # Mean difference should be close to zero for random noise.
313- self .assertLess (abs (stats ["mean_diff" ]), 0.2 )
323+ self .assertLess (abs (stats [STAT_NAME_MEAN_DIFF ]), 0.2 )
314324
315325 def test_diff_statistics_error_handling (self ):
316326 """Test error handling for invalid inputs."""
@@ -323,7 +333,7 @@ def test_diff_statistics_error_handling(self):
323333 )[0 ]
324334
325335 # Test with only one curve (should fail).
326- with self .assertRaises (TypeError ):
336+ with self .assertRaises (RuntimeError ):
327337 maya .cmds .mmAnimCurveDiffStatistics (animCurve , meanDifference = True )
328338
329339 # Test with non-animation curve nodes.
@@ -422,23 +432,23 @@ def test_diff_statistics_single_flag(self):
422432 )
423433 parsed = self ._parse_diff_statistics_result (result )
424434 self .assertEqual (len (parsed ), 1 )
425- self .assertIn ("mean_absolute_diff" , parsed )
435+ self .assertIn (STAT_NAME_MEAN_ABS_DIFF , parsed )
426436
427437 # Test RMS only.
428438 result = maya .cmds .mmAnimCurveDiffStatistics (
429439 animCurve_tx , animCurve_ty , rootMeanSquareDifference = True
430440 )
431441 parsed = self ._parse_diff_statistics_result (result )
432442 self .assertEqual (len (parsed ), 1 )
433- self .assertIn ("rms_diff" , parsed )
443+ self .assertIn (STAT_NAME_RMS_DIFF , parsed )
434444
435445 # Test median difference only.
436446 result = maya .cmds .mmAnimCurveDiffStatistics (
437447 animCurve_tx , animCurve_ty , medianDifference = True
438448 )
439449 parsed = self ._parse_diff_statistics_result (result )
440450 self .assertEqual (len (parsed ), 1 )
441- self .assertIn ("median_diff" , parsed )
451+ self .assertIn (STAT_NAME_MEDIAN_DIFF , parsed )
442452
443453 def test_diff_statistics_combined_flags (self ):
444454 """Test various combinations of statistics flags."""
@@ -459,21 +469,23 @@ def test_diff_statistics_combined_flags(self):
459469 )
460470 parsed = self ._parse_diff_statistics_result (result )
461471 self .assertEqual (len (parsed ), 2 )
462- self .assertIn ("mean_diff" , parsed )
463- self .assertIn ("population_variance" , parsed )
472+ self .assertIn (STAT_NAME_MEAN_DIFF , parsed )
473+ self .assertIn (STAT_NAME_POPULATION_VARIANCE , parsed )
464474
465475 # Test variance + stddev.
466476 result = maya .cmds .mmAnimCurveDiffStatistics (
467477 animCurve_tx , animCurve_ty , variance = True , standardDeviation = True
468478 )
469479 parsed = self ._parse_diff_statistics_result (result )
470480 self .assertEqual (len (parsed ), 2 )
471- self .assertIn ("population_variance" , parsed )
472- self .assertIn ("population_std_dev" , parsed )
481+ self .assertIn (STAT_NAME_POPULATION_VARIANCE , parsed )
482+ self .assertIn (STAT_NAME_STD_POPULATION_DEV , parsed )
473483
474484 # Verify stddev = sqrt(variance).
475- expected_stddev = math .sqrt (parsed ["population_variance" ])
476- self .assertAlmostEqual (parsed ["population_std_dev" ], expected_stddev , places = 5 )
485+ expected_stddev = math .sqrt (parsed [STAT_NAME_POPULATION_VARIANCE ])
486+ self .assertAlmostEqual (
487+ parsed [STAT_NAME_STD_POPULATION_DEV ], expected_stddev , places = 5
488+ )
477489
478490
479491if __name__ == "__main__" :
0 commit comments