|
| 1 | +const invert = require("./invert.js"); |
| 2 | + |
| 3 | +describe("invert", () => { |
| 4 | + // Given an object with one key-value pair |
| 5 | + // When invert is called with this object |
| 6 | + // Then it should return an object with the key and value swapped |
| 7 | + test("invert swaps key and value for single pair", () => { |
| 8 | + expect(invert({ a: 1 })).toEqual({ 1: "a" }); |
| 9 | + }); |
| 10 | + |
| 11 | + // Given an object with multiple key-value pairs |
| 12 | + // When invert is called with this object |
| 13 | + // Then it should return an object with the keys and values swapped |
| 14 | + test("invert swaps keys and values for multiple pairs", () => { |
| 15 | + expect(invert({ a: 1, b: 2 })).toEqual({ 1: "a", 2: "b" }); |
| 16 | + }); |
| 17 | + |
| 18 | + // Given an object with string values |
| 19 | + // When invert is called with this object |
| 20 | + // Then it should return an object with the keys and values swapped |
| 21 | + test("invert swaps keys and values for string values", () => { |
| 22 | + expect(invert({ x: "apple", y: "banana" })).toEqual({ |
| 23 | + apple: "x", |
| 24 | + banana: "y", |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + // Given an object with mixed value types |
| 29 | + // When invert is called with this object |
| 30 | + // Then it should return an object with the keys and values swapped |
| 31 | + test("invert swaps keys and values for mixed value types", () => { |
| 32 | + expect(invert({ a: 1, b: "two", c: 3 })).toEqual({ |
| 33 | + 1: "a", |
| 34 | + two: "b", |
| 35 | + 3: "c", |
| 36 | + }); |
| 37 | + }); |
| 38 | +}); |
0 commit comments