Created
April 22, 2025 19:29
-
-
Save gunar/3b7f74e0203a3c6134ceaedc7faaaaed 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
import os | |
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 | |
self.processed_data = [] | |
for number in data: | |
if isinstance(number, int): | |
if number % 2 != 0: | |
doubled_number = number * 2 | |
self.processed_data.append(doubled_number) | |
global_operation_counter += 1 | |
else: | |
pass | |
self.status = "Completed" | |
def get_total_sum(self): | |
total = 0 | |
for value in self.processed_data: | |
total += value | |
return total | |
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
from typing import List, Tuple, Union
def is_odd_integer(value: Union[int, any]) -> bool:
return isinstance(value, int) and value % 2 != 0
def process_numbers(data: List[Union[int, any]]) -> Tuple[List[int], str, int]:
if not isinstance(data, list):
print("Error: Input must be a list.")
return [], "Error", 0
def get_total_sum(numbers: List[int]) -> int:
return sum(numbers)
if name == "main":
input_data_1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'eleven']