π§ͺ Phase III: Testing and Validation Strategy
Testing must cover functional correctness, edge cases, and concurrent behavior.
A. Unit Test Cases (Functional Logic)
| Test Case | Description | Expected Outcome | Complexity Check |
|---|---|---|---|
| Basic Put/Get | Add item A, retrieve item A. | Successful retrieval of A's value. | $O(1)$ Get |
| Capacity Limit | Set capacity to 2. Insert A, B, C. | A is successfully evicted; only B and C remain. | Correct eviction (LRU) |
| Hit Update Order | Cache: [A (MRU), B, C (LRU)]. Get A. | New usage order: [A (MRU), B, C] $\rightarrow$ [A (MRU), B, C]. The list structure must be updated without changing the size. | $O(1)$ List Reordering |
| Overwrite | Cache: [B, C]. Put B (new value). | B's node is moved to MRU, its value is updated. Eviction check skipped if capacity allows. | $O(1)$ Update & Move |
B. Stress/Concurrency Testing
- Test: Run multiple goroutines concurrently calling
PutandGeton the same cache instance (e.g., 50 concurrent reads, 20 concurrent writes). - Validation: Ensure that no panics occur due to race conditions, and the final state of the cache size and contents remains consistent with the operations performed.