diff options
| author | matin <matin.kaufmann@gmail.com> | 2025-09-12 20:45:28 +0200 |
|---|---|---|
| committer | matin <matin.kaufmann@gmail.com> | 2025-09-12 20:45:28 +0200 |
| commit | 95d784fb414c6270e560fc0cf7ed289765ddd3ab (patch) | |
| tree | 31f66d2c230634d9325beb82f1125876a3a63e30 /test.py | |
| parent | 315bdeffd7b8c7c1a1792cb91d25ff0ac17fecda (diff) | |
AI refactoring (see architecture analysis and refactoring_summary)
Diffstat (limited to 'test.py')
| -rw-r--r-- | test.py | 92 |
1 files changed, 81 insertions, 11 deletions
@@ -2,10 +2,13 @@ from date_calculator import DateCalculator from calendar_manager import CalendarManager from prediction_controller import PredictionController - +from event_type_handler import EventTypeHandler +from config import EventConfig - def test_calculate_prediction(): + """Test the refactored prediction calculation system""" + print("Testing refactored prediction calculation system...") + # Input event dates as strings event1_str = ["2023-01-01", "2023-01-10"] event2_str = ["2023-01-05", "2023-01-15"] @@ -17,25 +20,92 @@ def test_calculate_prediction(): project2_str = ["2025-02-01", "2025-06-30"] project3_str = ["2024-05-05", "2024-06-07"] + # Initialize components date_calculator = DateCalculator() calendar_manager = CalendarManager() - prediction_controller = PredictionController(calendar_manager, date_calculator, ["EZ 100%", "EZ 50%", "EZ pauschal", "Sonstige"]) + prediction_controller = PredictionController(calendar_manager, date_calculator) + # Add entries to calendar + print("Adding calendar entries...") calendar_manager.add_entry(event1_str[0], event1_str[1], "Sonstige") calendar_manager.add_entry(event2_str[0], event2_str[1], "Sonstige") calendar_manager.add_entry(project1_str[0], project1_str[1], "EZ 100%") calendar_manager.add_entry(project2_str[0], project2_str[1], "EZ 50%") calendar_manager.add_entry(project3_str[0], project3_str[1], "EZ 50%") - # Set launch date and duration - prediction_controller.make_prediction("2023-01-01", 2) + # Test validation + print("Testing input validation...") + errors = prediction_controller.validate_prediction_inputs("2023-01-01", 2) + if errors: + print(f"Validation errors: {errors}") + else: + print("Input validation passed") - prediction = prediction_controller.get_prediction() + # Calculate prediction + print("Calculating prediction...") + success = prediction_controller.make_prediction("2023-01-01", 2) + + if success: + prediction = prediction_controller.get_prediction() + print(f"Predicted completion date: {prediction}") + + # Test event type handler + print("\nTesting EventTypeHandler...") + entries = calendar_manager.list_entries() + categorized = EventTypeHandler.categorize_events(entries) + print(f"Categorized events: {list(categorized.keys())}") + + # Test accounted time calculation + for entry in entries: + accounted_time = EventTypeHandler.calculate_accounted_time(entry) + print(f"Entry {entry.id}: {accounted_time}") + + print(f"\nAll calendar entries: {len(calendar_manager.list_entries())}") + else: + print("Prediction calculation failed") - # Output the result - print(f"Predicted completion date: {prediction}") - print(calendar_manager.list_entries()) +def test_event_type_handler(): + """Test the EventTypeHandler functionality""" + print("\nTesting EventTypeHandler...") + + # Test keyword validation + for keyword in EventConfig.KEYWORDS: + is_valid = EventTypeHandler.validate_event_type(keyword) + print(f"Keyword '{keyword}' is valid: {is_valid}") + + # Test duration calculation + from datetime import datetime + start_date = datetime(2023, 1, 1) + duration = EventTypeHandler.get_duration_for_type("EZ pauschal", start_date) + print(f"EZ pauschal duration from {start_date}: {duration}") + + # Test display names + for keyword in EventConfig.KEYWORDS: + display_name = EventTypeHandler.get_event_type_display_name(keyword) + print(f"'{keyword}' -> '{display_name}'") +def test_date_calculator(): + """Test the refactored DateCalculator""" + print("\nTesting DateCalculator...") + + from datetime import datetime + + # Test period sorting + periods = [ + (datetime(2023, 3, 1), datetime(2023, 3, 10), "id1"), + (datetime(2023, 1, 1), datetime(2023, 1, 10), "id2"), + (datetime(2023, 2, 1), datetime(2023, 2, 10), "id3") + ] + + sorted_periods = DateCalculator.sort_periods(periods) + print(f"Sorted periods: {[(p[0].strftime('%Y-%m-%d'), p[1].strftime('%Y-%m-%d'), p[2]) for p in sorted_periods]}") + + # Test truncation + launch_date = datetime(2023, 1, 15) + truncated = DateCalculator.truncate_periods(sorted_periods, launch_date) + print(f"Truncated periods: {[(p[0].strftime('%Y-%m-%d'), p[1].strftime('%Y-%m-%d'), p[2]) for p in truncated]}") -# Run the test -test_calculate_prediction()
\ No newline at end of file +if __name__ == "__main__": + test_calculate_prediction() + test_event_type_handler() + test_date_calculator()
\ No newline at end of file |
