forked from TheAlgorithms/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_map.test.ts
More file actions
91 lines (68 loc) · 2.11 KB
/
Copy pathhash_map.test.ts
File metadata and controls
91 lines (68 loc) · 2.11 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { HashMap } from "../../map/hash_map";
describe("Hash Map", () => {
let hashMap: HashMap<string, number>;
beforeEach(() => {
hashMap = new HashMap();
});
it("should set a value", () => {
hashMap.set("a", 1);
expect(hashMap.values()).toEqual([1]);
});
it("should override a value", () => {
hashMap.set("a", 1);
hashMap.set("a", 2);
expect(hashMap.values()).toEqual([2]);
});
it("should get a value", () => {
hashMap.set("a", 1);
expect(hashMap.get("a")).toBe(1);
});
it("should get null if key does not exist", () => {
expect(hashMap.get("a")).toBeNull();
});
it("should delete a value", () => {
hashMap.set("a", 1);
hashMap.delete("a");
expect(hashMap.get("a")).toBeNull();
});
it("should do nothing on delete if key does not exist", () => {
hashMap.delete("a");
expect(hashMap.get("a")).toBeNull();
});
it("should return true if key exists", () => {
hashMap.set("a", 1);
expect(hashMap.has("a")).toBe(true);
});
it("should return false if key does not exist", () => {
expect(hashMap.has("a")).toBe(false);
});
it("should clear the hash table", () => {
hashMap.set("a", 1);
hashMap.set("b", 2);
hashMap.set("c", 3);
hashMap.clear();
expect(hashMap.getSize()).toBe(0);
});
it("should return all keys", () => {
hashMap.set("a", 1);
hashMap.set("b", 2);
hashMap.set("c", 3);
expect(hashMap.keys()).toEqual(["a", "b", "c"]);
});
it("should return all values", () => {
hashMap.set("a", 1);
hashMap.set("b", 2);
hashMap.set("c", 3);
expect(hashMap.values()).toEqual([1, 2, 3]);
});
it("should return all key-value pairs", () => {
hashMap.set("a", 1);
hashMap.set("b", 2);
hashMap.set("c", 3);
expect(hashMap.entries()).toEqual([
{ key: "a", value: 1 },
{ key: "b", value: 2 },
{ key: "c", value: 3 },
]);
});
});