Skip to content

Commit ec4725c

Browse files
author
JorvanW
committed
added more test cases for invert.test.js
1 parent 04d19dd commit ec4725c

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

‎Sprint-2/interpret/invert.test.js‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
const invert = require("./invert.js");
22

33
test("when passed invert swaps single key-value pair", () => {
4-
expect(invert({ a: 1 })).toEqual({ "1": "a" });
4+
expect(invert({ a: 1 })).toEqual({ 1: "a" });
5+
});
6+
7+
test("when invert is passed two key-value pairs, it swaps both keys and values", () => {
8+
expect(invert({ a: 1, b: 2 })).toEqual({
9+
1: "a",
10+
2: "b",
11+
});
512
});
613

714
test("When invert is passed, multiple keys and values in the object should be swapped ", () => {
8-
expect(invert({ x: 10, y: 20 })).toEqual({ "10": "x", "20": "y" })
15+
expect(invert({ x: 10, y: 20 })).toEqual({ 10: "x", 20: "y" });
16+
});
17+
18+
test("when invert is passed a larger object, it swaps all keys and values", () => {
19+
expect(invert({ a: 1, b: 2, c: 3, d: 4 })).toEqual({
20+
1: "a",
21+
2: "b",
22+
3: "c",
23+
4: "d",
24+
});
925
});
1026

1127
test("when passed invert swaps string values", () => {
12-
expect(invert({ first: "hello",second: "world" })).toEqual({ hello: "first", world: "second" });
13-
});
28+
expect(invert({ first: "hello", second: "world" })).toEqual({
29+
hello: "first",
30+
world: "second",
31+
});
32+
});
33+
34+
test("when invert is passed duplicate values, the last key is kept", () => {
35+
expect(invert({ a: 1, b: 1 })).toEqual({
36+
1: "b",
37+
});
38+
});

0 commit comments

Comments
 (0)