Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-04-29
Problem Statement
Design a simple test framework or suite that validates the functionality of a given module or class by writing structured unit test cases.
The goal is to ensure correctness, handle edge cases, and demonstrate test-driven design thinking.
📋 Problem Description
You are required to write test cases for a small, well-defined module (for example: a Calculator class, Linked List implementation, or String Utility).
Your task is to identify test scenarios, organize them into a test structure, and simulate a minimal test execution environment — without using any external testing libraries (like JUnit,
pytest, etc.).
The exercise focuses on your ability to:
•Think critically about edge cases,
•Design reusable test structures, and
•Validate system correctness systematically.
🧱 Core Requirements
1. Classes to Design
•TestCase: Represents a single test case (contains input, expected output, and logic to run).
•TestSuite: Manages multiple test cases, runs them, and reports results.
•TargetModule: The class or module under test (e.g., Calculator).
2. Functional Requirements
You need to:
1.Identify all testable methods in the target class.
2.For each method, write positive, negative, and boundary test cases.
3.Implement a basic test runner to:
•Execute each test case.
•Compare expected vs actual output.
•Print a summary report (passed/failed counts).
🧩 Example Use Case
Module under test:
12classCalculator:3 def add(self, a, b):return a + b
4 def divide(self, a, b):return a / b