Skip to content
Open

Develop #1048

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/splitInteger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,30 @@ const splitInteger = require('./splitInteger');
test(`should split a number into equal parts
if a value is divisible by a numberOfParts`, () => {
Comment on lines 5 to 6

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description seems to have been swapped with the next test's description. This test case, splitInteger(8, 1), is about splitting into a single part, which is what the description for the second test mentions.


const result = splitInteger(8, 1);

expect(result).toEqual([8]);
});

test(`should return a part equals to a value
when splitting into 1 part`, () => {
Comment on lines 13 to 14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description would be perfect for a test case like splitInteger(8, 1). For the current test, splitInteger(6, 2), the description from the first test (should split a number into equal parts...) would be more suitable.


const result = splitInteger(6, 2);

expect(result).toEqual([3, 3]);
});

test('should sort parts ascending if they are not equal', () => {

const result = splitInteger(17, 4);

expect(result).toEqual([4, 4, 4, 5]);
expect(result).toEqual(result.slice().sort((a, b) => a - b));
});

test('should add zeros if value < numberOfParts', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description is misleading. For the test case splitInteger(32, 6), the value (32) is not less than numberOfParts (6), and the function doesn't add zeros. A more accurate description could be should correctly split the number when parts are not equal.


const result = splitInteger(32, 6);

expect(result).toEqual([5, 5, 5, 5, 6, 6]);
});