Skip to content

Commit 2e1e8dd

Browse files
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 numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package CustomHashMap;
2+
3+
/* Test runner for HashMapCustom. */
4+
5+
public class HashMapCustomTest {
6+
public static void main(String[] args) {
7+
HashMapCustom<Object, Integer> map = new HashMapCustom<Object, Integer>();
8+
map.put("Alice", 25);
9+
map.put("Bob", 30);
10+
map.put("Charlie", 35);
11+
map.put("Alice", 28); // Update value for "Alice"
12+
13+
System.out.println("Value of Alice: " + map.get("Alice")); // 28
14+
System.out.println("Value of Bob: " + map.get("Bob")); // 30
15+
System.out.println("Value of Charlie: " + map.get("Charlie"));// 35
16+
17+
map.remove("Bob");
18+
System.out.println("Value of Bob after removal: " + map.get("Bob")); // null
19+
20+
System.out.println("\nCustom HashMap Contents:");
21+
map.printMap();
22+
23+
System.out.println("\nIterating over CustomHashMap entries:");
24+
for (HashMapCustom.Entry<Object, Integer> entry : map) {
25+
System.out.println(entry.getKey() + " -> " + entry.getValue());
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)