-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtimeBasedKeyValueStore.test.js
More file actions
48 lines (42 loc) · 1.75 KB
/
timeBasedKeyValueStore.test.js
File metadata and controls
48 lines (42 loc) · 1.75 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
const { TimeMap } = require("./timeBasedKeyValueStore");
describe("TimeMap", () => {
it("should set a value for a key at a given timestamp", () => {
const timeMap = new TimeMap();
timeMap.set("foo", "bar", 1);
expect(timeMap.get("foo", 1)).toBe("bar");
});
it("should return an empty string if no value is found", () => {
const timeMap = new TimeMap();
expect(timeMap.get("foo", 1)).toBe("");
});
it("should return the correct value if multiple values are set", () => {
const timeMap = new TimeMap();
timeMap.set("foo", "bar", 1);
timeMap.set("foo", "bar2", 2);
expect(timeMap.get("foo", 1)).toBe("bar");
expect(timeMap.get("foo", 2)).toBe("bar2");
});
it("should return the correct value for different keys", () => {
const timeMap = new TimeMap();
timeMap.set("foo", "bar", 1);
timeMap.set("foo2", "bar2", 2);
expect(timeMap.get("foo", 1)).toBe("bar");
expect(timeMap.get("foo2", 2)).toBe("bar2");
});
it("should return the correct value for same key at different timestamps", () => {
const timeMap = new TimeMap();
timeMap.set("foo", "bar", 1);
timeMap.set("foo", "bar2", 2);
timeMap.set("foo", "bar3", 3);
expect(timeMap.get("foo", 1)).toBe("bar");
expect(timeMap.get("foo", 2)).toBe("bar2");
expect(timeMap.get("foo", 3)).toBe("bar3");
});
it("should return the correct value for different keys at different timestamps", () => {
const timeMap = new TimeMap();
timeMap.set("foo", "bar", 1);
timeMap.set("foo2", "bar2", 2);
expect(timeMap.get("foo", 1)).toBe("bar");
expect(timeMap.get("foo2", 2)).toBe("bar2");
});
});