Skip to content

Commit 846db55

Browse files
committed
Added test cases for invert.js
1 parent e604821 commit 846db55

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Sprint-2/interpret/invert.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const invert = require("./invert.js");
2+
3+
// Given an object
4+
// When invert is passed this object
5+
// Then it should swap the keys and values
6+
test("invert swaps the keys and values of an object", () => {
7+
expect(invert({ x: 10, y: 20 })).toEqual({
8+
10: "x",
9+
20: "y",
10+
});
11+
});
12+
13+
// Given an object with one key value pair
14+
// When passed to invert
15+
// Then it should return the swapped pair
16+
test("invert swaps a single key value pair", () => {
17+
expect(invert({ a: 1 })).toEqual({
18+
1: "a",
19+
});
20+
});
21+
22+
// Given an empty object
23+
// When passed to invert
24+
// Then it should return an empty object
25+
test("invert on an empty object returns an empty object", () => {
26+
expect(invert({})).toEqual({});
27+
});
28+
29+
// Given an invalid input like an array
30+
// When passed to invert
31+
// Then it should throw an error
32+
test("invert throws an error for invalid input", () => {
33+
expect(() => invert([])).toThrow("Input must be an object");
34+
});

0 commit comments

Comments
 (0)