Commit 2e1e8dd
committed
test(HashMapCustomTest): add driver program for custom HashMap implementation
What
- Introduced HashMapCustomTest class to demonstrate and validate functionality of HashMapCustom<K,V>.
- Operations tested:
- put() with new keys.
- put() with duplicate key to update value.
- get() to retrieve values.
- remove() to delete a key.
- printMap() to display buckets and entries.
- for-each iteration over entries via Iterable support.
Why
- Provide a simple, executable test harness for HashMapCustom.
- Validate that:
- Updates overwrite existing values.
- Removal clears entries and subsequent get() returns null.
- Iteration traverses all stored entries.
- Serve as documentation/example usage for developers.
How
- Created HashMapCustom<Object, Integer> instance.
- Inserted sample key-value pairs (Alice, Bob, Charlie).
- Updated Alice’s value to confirm overwrite behavior.
- Removed Bob to confirm removal behavior.
- Printed contents via printMap().
- Iterated over entries with for-each loop to demonstrate Iterable support.
Logic
- Inputs: string keys, integer values inserted via put().
- Outputs: integer values retrieved via get(), null for missing keys, and formatted entries from printMap()/iteration.
- Execution flow:
1. Insert/update → check key uniqueness and collision handling.
2. Retrieve values by key to verify correctness.
3. Remove entry → verify absence.
4. Print and iterate → show map’s internal state and traversal.
Real-life applications
- Educational demonstration of custom HashMap operations.
- Quick validation of custom map implementation.
- Useful for regression testing as HashMapCustom evolves.
Notes
- Currently uses Object keys and Integer values; type parameters can be adjusted for specific use cases.
- Output order is not guaranteed (depends on hashing and bucket distribution).
- This test is not exhaustive (e.g., no explicit load factor / resize testing), but covers basic CRUD operations and iteration.
Signed-off-by: https://github.com/Someshdiwan <someshdiwan369@gmail.com>1 parent 6f1475b commit 2e1e8dd
1 file changed
Lines changed: 28 additions & 0 deletions
File tree
- Section 25 Collections Frameworks/Map Interface/HashMap/Custom HashMap/src/CustomHashMap
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
0 commit comments