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

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

Choose a reason for hiding this comment

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

The tests you've written are logical and cover different scenarios. However, the requirements specify four exact examples that must be tested. Please add test cases for splitInteger(8, 1), splitInteger(6, 2), splitInteger(17, 4), and splitInteger(32, 6).

const numberOfParts = 4;

const result = splitInteger(value, numberOfParts);

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

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

const result = splitInteger(value, numberOfParts);

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

test('should sort parts ascending if they are not equal', () => {
const value = 100;
const numberOfParts = 3;

const result = splitInteger(value, numberOfParts);

expect(result).toEqual([33, 33, 34]);
});

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

const result = splitInteger(value, numberOfParts);

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