-
-
Save saimanvith22/562a963b1cf72be0742e06221d2ecaa6 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
| global_operation_counter = 0 | |
| class NumberProcessor: | |
| def __init__(self): | |
| self.processed_data = [] | |
| self.status = "Initialized" | |
| def process_list(self, data): | |
| global global_operation_counter | |
| self.status = "Processing" | |
| if not isinstance(data, list): | |
| print("Error: Input must be a list.") | |
| self.status = "Error" | |
| return | |
| # instead of loop i have refactored it with list | |
| self.processed_data = [number * 2 for number in data if isinstance(number, int) and number % 2 != 0] | |
| global_operation_counter += len(self.processed_data) | |
| self.status = "Completed" | |
| # used lambda operator | |
| 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