From dcc5096e67117058f5c17a47fd4e4f3c0ba8d442 Mon Sep 17 00:00:00 2001 From: mao-sz <122839503+mao-sz@users.noreply.github.com> Date: Tue, 27 Jan 2026 17:33:02 +0000 Subject: [PATCH] Provide clearer test names "works ..." doesn't communicate very well exactly what it means --- .../solution/totalIntegers-solution.spec.js | 22 +++++++++---------- .../3_totalIntegers/totalIntegers.spec.js | 22 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/computer_science/recursion/3_totalIntegers/solution/totalIntegers-solution.spec.js b/computer_science/recursion/3_totalIntegers/solution/totalIntegers-solution.spec.js index 19676196061..51b77a155e1 100644 --- a/computer_science/recursion/3_totalIntegers/solution/totalIntegers-solution.spec.js +++ b/computer_science/recursion/3_totalIntegers/solution/totalIntegers-solution.spec.js @@ -1,40 +1,40 @@ const totalIntegers = require('./totalIntegers-solution'); describe('totalIntegers', () => { - test('Works with a simple array of numbers', () => { + test('Counts all integers in a simple array of only integers', () => { expect(totalIntegers([1, 2, 3])).toBe(3); }); - test('Ignores non-integer values', () => { + test('Ignores non-number values', () => { expect(totalIntegers([1, 2, '3', 4])).toBe(3); }); - test('Works with simple objects', () => { + test('Counts all integers in a plain object', () => { expect(totalIntegers({ a: 1, b: '2', c: 3 })).toBe(2); }); - test('Works with an empty nested array', () => { + test('Does not find any integers in nested empty arrays', () => { expect(totalIntegers([[], [], []])).toBe(0); }); - test('Works with a very nested array', () => { + test('Counts integers in deeply nested arrays', () => { expect(totalIntegers([[[[[[[[[[[[[[4]]]]]], 246]]]]]]]])).toBe(2); }); - test('Works with negative numbers', () => { + test('Counts negative integers', () => { expect(totalIntegers([5, 7, -7, [45, -1, -0], [4, 7, -4, -4, -4, [777777, -45674]], [-5477654]])).toBe(14); }); - test('Works with floats', () => { + test('Does not count non-integer numbers', () => { expect(totalIntegers([5, 7.7, 7, [45, 1, 0], [4.0, 7, [7.77777, 4567.4]], [5477.654]])).toBe(7); }); - test('Only accepts arrays or objects', () => { + test('Returns undefined for non-array/object arguments', () => { expect(totalIntegers('2')).toBe(undefined); expect(totalIntegers(() => {})).toBe(undefined); expect(totalIntegers(42)).toBe(undefined); expect(totalIntegers(NaN)).toBe(undefined); }); - test('Works with NaN', () => { + test('Does not count NaN as an integer', () => { expect(totalIntegers([5, NaN, [NaN, NaN, 64], 4])).toBe(3); }); - test('Works with a nested array of all kinds of things', () => { + test('Counts all integers even with deeply nested containing multiple types', () => { expect(totalIntegers([NaN, [[{}], 555 ], '444', [], 74.0, undefined, [[() => {}], [4], Infinity, [[[], -44.0], [null, '-4'], NaN [[]], 6]], () => {}, [[], [-Infinity, ['4'], [4.7, -46.7], NaN]]])).toBe(5); }); - test('Works with arrays containing objects containing integers', () => { + test('Counts all integers when nested arrays and objects are mixed together', () => { expect(totalIntegers([4, 6, { a: 1, b: { a: [5, 10], b: 11 } }, 9])).toBe(7); }); }); diff --git a/computer_science/recursion/3_totalIntegers/totalIntegers.spec.js b/computer_science/recursion/3_totalIntegers/totalIntegers.spec.js index d33d2293d30..a5cfbea281c 100644 --- a/computer_science/recursion/3_totalIntegers/totalIntegers.spec.js +++ b/computer_science/recursion/3_totalIntegers/totalIntegers.spec.js @@ -1,50 +1,50 @@ const totalIntegers = require('./totalIntegers'); describe('totalIntegers', () => { - test('Works with a simple array of numbers', () => { + test('Counts all integers in a simple array of only integers', () => { expect(totalIntegers([1, 2, 3])).toBe(3); }); - test.skip('Ignores non-integer values', () => { + test.skip('Ignores non-number values', () => { expect(totalIntegers([1, 2, '3', 4])).toBe(3); }); - test.skip('Works with simple objects', () => { + test.skip('Counts all integers in a plain object', () => { expect(totalIntegers({ a: 1, b: '2', c: 3 })).toBe(2); }); - test.skip('Works with an empty nested array', () => { + test.skip('Does not find any integers in nested empty arrays', () => { expect(totalIntegers([[], [], []])).toBe(0); }); - test.skip('Works with a very nested array', () => { + test.skip('Counts integers in deeply nested arrays', () => { expect(totalIntegers([[[[[[[[[[[[[[4]]]]]], 246]]]]]]]])).toBe(2); }); - test.skip('Works with negative numbers', () => { + test.skip('Counts negative integers', () => { expect(totalIntegers([5, 7, -7, [45, -1, -0], [4, 7, -4, -4, -4, [777777, -45674]], [-5477654]])).toBe(14); }); - test.skip('Works with floats', () => { + test.skip('Does not count non-integer numbers', () => { expect(totalIntegers([5, 7.7, 7, [45, 1, 0], [4.0, 7, [7.77777, 4567.4]], [5477.654]])).toBe(7); }); - test.skip('Only accepts arrays or objects', () => { + test.skip('Returns undefined for non-array/object arguments', () => { expect(totalIntegers('2')).toBe(undefined); expect(totalIntegers(() => {})).toBe(undefined); expect(totalIntegers(42)).toBe(undefined); expect(totalIntegers(NaN)).toBe(undefined); }); - test.skip('Works with NaN', () => { + test.skip('Does not count NaN as an integer', () => { expect(totalIntegers([5, NaN, [NaN, NaN, 64], 4])).toBe(3); }); - test.skip('Works with a nested array of all kinds of things', () => { + test.skip('Counts all integers even with deeply nested containing multiple types', () => { expect(totalIntegers([NaN, [[{}], 555 ], '444', [], 74.0, undefined, [[() => {}], [4], Infinity, [[[], -44.0], [null, '-4'], NaN [[]], 6]], () => {}, [[], [-Infinity, ['4'], [4.7, -46.7], NaN]]])).toBe(5); }); - test.skip('Works with arrays containing objects containing integers', () => { + test.skip('Counts all integers when nested arrays and objects are mixed together', () => { expect(totalIntegers([4, 6, { a: 1, b: { a: [5, 10], b: 11 } }, 9])).toBe(7); }); });