@@ -839,6 +839,77 @@ def test_draw_sample_stats(self):
839839 self .assertEqual (line , 1 )
840840 self .assertGreater (self .collector ._max_sample_rate , 0 )
841841
842+ def test_progress_bar_uses_target_rate (self ):
843+ """Test that progress bar uses target rate instead of max rate."""
844+ # Set up collector with specific sampling interval
845+ collector = LiveStatsCollector (10000 , pid = 12345 , display = self .mock_display ) # 10ms = 100Hz target
846+ collector .start_time = time .perf_counter ()
847+ collector .total_samples = 500
848+ collector ._max_sample_rate = 150 # Higher than target to test we don't use this
849+
850+ colors = {"cyan" : curses .A_BOLD , "green" : curses .A_BOLD }
851+ collector ._initialize_widgets (colors )
852+
853+ # Clear the display buffer to capture only our progress bar content
854+ self .mock_display .buffer .clear ()
855+
856+ # Draw sample stats with a known elapsed time that gives us a specific sample rate
857+ elapsed = 10.0 # 500 samples in 10 seconds = 50 samples/second
858+ line = collector ._header_widget .draw_sample_stats (0 , 160 , elapsed )
859+
860+ # Verify display was updated
861+ self .assertEqual (line , 1 )
862+ self .assertGreater (len (self .mock_display .buffer ), 0 )
863+
864+ # Verify the label shows current/target format with units instead of "max"
865+ found_current_target_label = False
866+ found_max_label = False
867+ for (line_num , col ), (text , attr ) in self .mock_display .buffer .items ():
868+ # Should show "50.0Hz/100.0Hz (50.0%)" since we're at 50% of target (50/100)
869+ if "50.0Hz/100.0Hz" in text and "50.0%" in text :
870+ found_current_target_label = True
871+ if "max:" in text :
872+ found_max_label = True
873+
874+ self .assertTrue (found_current_target_label , "Should display current/target rate with percentage" )
875+ self .assertFalse (found_max_label , "Should not display max rate label" )
876+
877+ def test_progress_bar_different_intervals (self ):
878+ """Test that progress bar adapts to different sampling intervals."""
879+ test_cases = [
880+ (1000 , "1.0KHz" , "100.0Hz" ), # 1ms interval -> 1000Hz target (1.0KHz), 100Hz current
881+ (5000 , "200.0Hz" , "100.0Hz" ), # 5ms interval -> 200Hz target, 100Hz current
882+ (20000 , "50.0Hz" , "100.0Hz" ), # 20ms interval -> 50Hz target, 100Hz current
883+ (100000 , "10.0Hz" , "100.0Hz" ), # 100ms interval -> 10Hz target, 100Hz current
884+ ]
885+
886+ for interval_usec , expected_target_formatted , expected_current_formatted in test_cases :
887+ with self .subTest (interval = interval_usec ):
888+ collector = LiveStatsCollector (interval_usec , display = MockDisplay ())
889+ collector .start_time = time .perf_counter ()
890+ collector .total_samples = 100
891+
892+ colors = {"cyan" : curses .A_BOLD , "green" : curses .A_BOLD }
893+ collector ._initialize_widgets (colors )
894+
895+ # Clear buffer
896+ collector .display .buffer .clear ()
897+
898+ # Draw with 1 second elapsed time (gives us current rate of 100Hz)
899+ collector ._header_widget .draw_sample_stats (0 , 160 , 1.0 )
900+
901+ # Check that the current/target format appears in the display with proper units
902+ found_current_target_format = False
903+ for (line_num , col ), (text , attr ) in collector .display .buffer .items ():
904+ # Looking for format like "100.0Hz/1.0KHz" or "100.0Hz/200.0Hz"
905+ expected_format = f"{ expected_current_formatted } /{ expected_target_formatted } "
906+ if expected_format in text and "%" in text :
907+ found_current_target_format = True
908+ break
909+
910+ self .assertTrue (found_current_target_format ,
911+ f"Should display current/target rate format with units for { interval_usec } µs interval" )
912+
842913 def test_draw_efficiency_bar (self ):
843914 """Test drawing efficiency bar."""
844915 self .collector ._successful_samples = 900
0 commit comments