Skip to content
Open

Develop #1068

Show file tree
Hide file tree
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
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
17 changes: 17 additions & 0 deletions src/splitInteger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,34 @@ 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).toEqual([3, 3])
Comment on lines +8 to +10

Choose a reason for hiding this comment

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

Add an explicit length assertion for this test. For example, after const result = splitInteger(6, 2) add expect(result).toHaveLength(2). This satisfies the requirement that the returned array contains exactly numberOfParts elements (checklist item #1).

expect(result).toHaveLength(2)
});

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

const result = splitInteger(8, 1)

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

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

const result = splitInteger(32, 6)

Choose a reason for hiding this comment

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

The required example splitInteger(17, 4) -> [4, 4, 4, 5] is missing. Add a new test (before or after this test) that asserts the exact array, asserts .toHaveLength(4), and (optionally) checks Math.max(...result) - Math.min(...result) <= 1 so the property is explicit. Example:

test('example: splitInteger(17, 4) -> [4,4,4,5]', () => {
  const result = splitInteger(17, 4)
  expect(result).toEqual([4,4,4,5])
  expect(result).toHaveLength(4)
  expect(Math.max(...result) - Math.min(...result)).toBeLessThanOrEqual(1)
})

const diff = Math.max(...result) - Math.min(...result)

expect(result).toEqual([5, 5, 5, 5, 6, 6])
expect(result).toHaveLength(6)
expect(diff).toBeLessThanOrEqual(1)

Choose a reason for hiding this comment

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

Add a test for the required example splitInteger(17, 4) === [4, 4, 4, 5]. Place it after this test block. The test should assert the exact array, assert the length equals 4, and verify the balance constraint (max - min <= 1). Example to add:

test('should split 17 into 4 balanced parts', () => {
  const result = splitInteger(17, 4)

  expect(result).toEqual([4, 4, 4, 5])
  expect(result).toHaveLength(4)
  expect(Math.max(...result) - Math.min(...result)).toBeLessThanOrEqual(1)
})

This addresses the missing required example from the description (HIGH priority).

});

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

const result = splitInteger(1, 2)

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

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 .

expect(result).toHaveLength(2)
});