Skip to content
Open

Develop #1068

Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test

on:
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .reviewrelatedfiles
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/**/*
2 changes: 2 additions & 0 deletions src/splitInteger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* @param {number} value
* @param {number} numberOfParts
Expand Down
12 changes: 12 additions & 0 deletions src/splitInteger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,29 @@ const splitInteger = require('./splitInteger');
test(`should split a number into equal parts
if a value is divisible by a numberOfParts`, () => {

const result = splitInteger(10, 2)

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

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

const result = splitInteger(10, 1)

expect(result).toEqual([10])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Although some toEqual assertions implicitly verify length, add an explicit test asserting the returned array length equals numberOfParts (checklist #1). e.g. expect(result).toHaveLength(numberOfParts) — this makes the intent explicit in the test suite.

});

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

const result = splitInteger(10, 3)

expect(result).toEqual([3, 3, 4])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add an explicit test that verifies the numeric property max - min <= 1 required by the task (checklist #2). For example: const diff = Math.max(...result) - Math.min(...result); expect(diff).toBeLessThanOrEqual(1) — add this for a non-trivial case (or for each example).

});

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

const result = splitInteger(1, 2)

expect(result).toEqual([0, 1])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add tests for the exact example cases required by the task description. The suite currently uses other values (10 and 1) but must include: splitInteger(8, 1) -> [8], splitInteger(6, 2) -> [3, 3], splitInteger(17, 4) -> [4, 4, 4, 5], and splitInteger(32, 6) -> [5, 5, 5, 5, 6, 6] (checklist items #4#7). See the description for the exact examples .

});