feat: solution for 'Повторный экзамен #2: Сравнительный обзор 3 сущностей (Tavily)'

This commit is contained in:
2026-06-29 16:55:55 +03:00
parent c7e2183e3e
commit 29f9717e89
5 changed files with 155 additions and 141 deletions
+37
View File
@@ -0,0 +1,37 @@
const compare = require('../src/compare');
describe('compare function', () => {
test('returns empty array when all objects are equal', () => {
const a = { x: 1, y: 2 };
const b = { x: 1, y: 2 };
const c = { x: 1, y: 2 };
expect(compare(a, b, c)).toEqual([]);
});
test('detects differences in top-level keys', () => {
const a = { x: 1, y: 2 };
const b = { x: 1, y: 3 };
const c = { x: 1, y: 2 };
expect(compare(a, b, c)).toEqual([
{ key: 'y', values: [2, 3, 2] },
]);
});
test('detects differences in nested objects', () => {
const a = { a: { b: 1 } };
const b = { a: { b: 2 } };
const c = { a: { b: 1 } };
expect(compare(a, b, c)).toEqual([
{ key: 'a.b', values: [1, 2, 1] },
]);
});
test('handles missing keys', () => {
const a = { x: 1 };
const b = { x: 1, y: 2 };
const c = { x: 1 };
expect(compare(a, b, c)).toEqual([
{ key: 'y', values: [undefined, 2, undefined] },
]);
});
});