Skip to content

Instantly share code, notes, and snippets.

@gunar
Created April 22, 2025 19:29
Show Gist options
  • Save gunar/3b7f74e0203a3c6134ceaedc7faaaaed to your computer and use it in GitHub Desktop.
Save gunar/3b7f74e0203a3c6134ceaedc7faaaaed to your computer and use it in GitHub Desktop.
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.")
@heenasingla55
Copy link

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

processed_data = list(map(lambda x: x * 2, filter(is_odd_integer, data)))
return processed_data, "Completed", len(processed_data)

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']

processed_data, status, operation_count = process_numbers(input_data_1)
total = get_total_sum(processed_data)

assert total == 50
assert operation_count == 5, f"Test Case 1 Failed: Expected operation count 5, got {operation_count}"
assert status == "Completed", f"Test Case 1 Failed: Expected status 'Completed', got {status}"
assert processed_data == [2, 6, 10, 14, 18], f"Test Case 1 Failed: Internal data mismatch, got {processed_data}"
print("Tests passed.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment