Skip to content
Open

Done #818

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
10 changes: 10 additions & 0 deletions src/splitInteger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,28 @@ const splitInteger = require('./splitInteger');

test(`should split a number into equal parts
if a value is divisible by a numberOfParts`, () => {
const result = splitInteger(6, 2);

expect(result[0]).toEqual(result[1]);
});

test(`should return a part equals to a value
when splitting into 1 part`, () => {
const result = splitInteger(32, 1);

expect(result.length).toBe(1);
});

test('should sort parts ascending if they are not equal', () => {
const result = splitInteger(32, 6);

const sortedResult = result.sort((v1, v2) => v1 - v2);

expect(result).toEqual(sortedResult);
Comment on lines +23 to +24

Choose a reason for hiding this comment

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

The test case assumes that the result from splitInteger might not be sorted, and it sorts the result before comparing. Ensure that the splitInteger function does not already return a sorted array, as this would make the sorting step redundant and the test less meaningful.

});

test('should add zeros if value < numberOfParts', () => {
const result = splitInteger(4, 5);

expect(result).toContain(0);
});