# Test Updates for Medicine Dose Plotting Feature ## Overview Updated the test suite to accommodate the new medicine dose plotting functionality in the GraphManager class. ## Files Updated ### 1. `/tests/test_graph_manager.py` #### Updated Tests: - **`test_init`**: - Added checks for all 5 medicine toggle variables (bupropion, hydroxyzine, gabapentin, propranolol, quetiapine) - Verified that bupropion and propranolol are enabled by default - Verified that hydroxyzine, gabapentin, and quetiapine are disabled by default - **`test_toggle_controls_creation`**: - Updated to check for all 9 toggle variables (4 symptoms + 5 medicines) #### New Test Methods Added: - **`test_calculate_daily_dose_empty_input`**: Tests dose calculation with empty/invalid inputs - **`test_calculate_daily_dose_standard_format`**: Tests standard timestamp:dose format parsing - **`test_calculate_daily_dose_with_symbols`**: Tests parsing with bullet symbols (•) - **`test_calculate_daily_dose_no_timestamp`**: Tests parsing without timestamps - **`test_calculate_daily_dose_decimal_values`**: Tests decimal dose values - **`test_medicine_dose_plotting`**: Tests that medicine doses are plotted correctly - **`test_medicine_toggle_functionality`**: Tests that medicine toggles affect dose display - **`test_dose_calculation_comprehensive`**: Tests all sample dose data cases - **`test_dose_calculation_edge_cases`**: Tests malformed and edge case inputs ### 2. `/tests/conftest.py` #### Updated Fixtures: - **`sample_dataframe`**: Enhanced with realistic dose data: - Added proper dose strings in various formats - Included multiple dose entries per day - Added decimal doses and different timestamp formats #### New Fixtures: - **`sample_dose_data`**: Comprehensive test cases for dose calculation including: - Standard format: `'2025-07-28 18:59:45:150mg|2025-07-28 19:34:19:75mg'` - With bullets: `'• • • • 2025-07-30 07:50:00:300'` - Decimal doses: `'2025-07-28 18:59:45:12.5mg|2025-07-28 19:34:19:7.5mg'` - No timestamp: `'100mg|50mg'` - Mixed format: `'• 2025-07-30 22:50:00:10|75mg'` - Edge cases: empty strings, 'nan' values, no units ## Test Coverage Areas ### Dose Calculation Logic: - ✅ Empty/null inputs return 0.0 - ✅ Standard timestamp:dose format parsing - ✅ Multiple dose entries separated by `|` - ✅ Bullet symbol (•) handling and removal - ✅ Decimal dose values - ✅ Doses without timestamps - ✅ Doses without units (mg) - ✅ Mixed format handling - ✅ Malformed data graceful handling ### Graph Plotting: - ✅ Medicine dose bars are plotted when toggles are enabled - ✅ No plotting occurs when toggles are disabled - ✅ No plotting occurs when dose data is empty - ✅ Canvas redraw is called appropriately - ✅ Axis clearing occurs before plotting ### Toggle Functionality: - ✅ All 9 toggle variables are properly initialized - ✅ Default states are correct (symptoms on, some medicines on/off) - ✅ Toggle changes trigger graph updates - ✅ Toggle states affect what gets plotted ## Expected Test Results ### Dose Calculation Examples: - `'2025-07-28 18:59:45:150mg|2025-07-28 19:34:19:75mg'` → 225.0mg - `'• • • • 2025-07-30 07:50:00:300'` → 300.0mg - `'2025-07-28 18:59:45:12.5mg|2025-07-28 19:34:19:7.5mg'` → 20.0mg - `'100mg|50mg'` → 150.0mg - `'• 2025-07-30 22:50:00:10|75mg'` → 85.0mg - `''` → 0.0mg - `'nan'` → 0.0mg - `'2025-07-28 18:59:45:10|2025-07-28 19:34:19:5'` → 15.0mg ## Running the Tests To run the updated tests: ```bash # Run all graph manager tests .venv/bin/python -m pytest tests/test_graph_manager.py -v # Run specific dose calculation tests .venv/bin/python -m pytest tests/test_graph_manager.py -k "dose_calculation" -v # Run all tests with coverage .venv/bin/python -m pytest tests/ --cov=src --cov-report=html ``` ## Notes - All tests are designed to work with mocked matplotlib components to avoid GUI dependencies - Tests use the existing fixture system and follow established patterns - New functionality is thoroughly covered while maintaining backward compatibility - Edge cases and error conditions are properly tested