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.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment