-
-
Save Mrutyunjay09/27a396f057c9002ff91f00f253f4368c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import List, Union | |
| global_operation_counter = 0 | |
| def is_valid_odd_integer(value: Union[int, str]) -> bool: | |
| return isinstance(value, int) and value % 2 != 0 | |
| def double(number: int) -> int: | |
| return number * 2 | |
| def filter_and_double_odds(data: List[Union[int, str]]) -> List[int]: | |
| return [double(num) for num in data if is_valid_odd_integer(num)] | |
| class NumberProcessor: | |
| def __init__(self): | |
| self.processed_data: List[int] = [] | |
| self.status: str = "Initialized" | |
| def process_list(self, data: List[Union[int, str]]) -> None: | |
| global global_operation_counter | |
| if not isinstance(data, list): | |
| print("Error: Input must be a list.") | |
| self.status = "Error" | |
| return | |
| self.status = "Processing" | |
| self.processed_data = filter_and_double_odds(data) | |
| global_operation_counter += len(self.processed_data) | |
| self.status = "Completed" | |
| def get_total_sum(self) -> int: | |
| return sum(self.processed_data) | |
| if __name__ == "__main__": | |
| global_operation_counter = 0 | |
| processor1 = NumberProcessor() | |
| input_data_1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'eleven'] | |
| processor1.process_list(input_data_1) | |
| assert processor1.get_total_sum() == 50 | |
| assert global_operation_counter == 5, f"Test Case 1 Failed: Expected operation count 5, got {global_operation_counter}" | |
| assert processor1.status == "Completed", f"Test Case 1 Failed: Expected status 'Completed', got {processor1.status}" | |
| assert processor1.processed_data == [2, 6, 10, 14, 18], f"Test Case 1 Failed: Internal data mismatch, got {processor1.processed_data}" | |
| print("Tests passed.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment