Skip to content
Open

done #1016

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
4 changes: 1 addition & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ module.exports = {
jest: true
},
rules: {
'no-proto': 0,
strict: 0,
'max-len': 0,
'no-proto': 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The configuration disables the no-proto rule using a numeric severity (0). Consider one of the following for clarity:

  • Use the named severity: "no-proto": "off" so it's immediately clear to readers, or
  • Add a brief comment explaining why you disabled this rule (e.g., legacy code relies on __proto__).

Either approach improves maintainability but is not required for functionality.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider using the string form for the rule level for readability and adding a short justification comment if disabling no-proto is intentional. For example:

'no-proto': 'off' // disabled to allow use of __proto__ in test helpers / legacy interop

Using 'off' is clearer than 0 and helps future maintainers understand the intent.

},
plugins: ['jest']
};
23 changes: 23 additions & 0 deletions .github/workflows/test.yml-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test

on:
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"license": "GPL-3.0",
"devDependencies": {
"@mate-academy/eslint-config": "*",
"@mate-academy/scripts": "^0.9.7",
"@mate-academy/scripts": "^2.1.1",
"@types/jest": "^30.0.0",
"eslint": "^5.16.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-node": "^8.0.1",
Expand Down
8 changes: 4 additions & 4 deletions src/splitInteger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ const splitInteger = require('./splitInteger');

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

expect(splitInteger(6, 2)).toEqual([3, 3]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This test asserting exact equality for splitInteger(6, 2) is fine for the example. In addition, add a property-based test (for divisible case) that checks: - the returned array has length numberOfParts, - the sum equals value, - array is sorted ascending, - max - min <= 1. That ensures the core constraints are validated independently of exact distribution.

});

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

expect(splitInteger(8, 1)).toEqual([8]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good: this test covers the numberOfParts = 1 case. Consider also adding a property test for this scenario that asserts length and sum explicitly (e.g., expect(result).toHaveLength(1); expect(result.reduce((a,b)=>a+b,0)).toBe(8);).

});

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

expect(splitInteger(32, 6)).toEqual([5, 5, 5, 5, 6, 6]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This example-based test for splitInteger(32, 6) is fine, but the task checklist requires a test for the example splitInteger(17, 4) which is missing. Add a test asserting splitInteger(17, 4) yields [4, 4, 4, 5]. Also add a non-divisible property-based test (could use 32,6 or 17,4) that checks length, sum, sorted order, and max - min <= 1 rather than relying only on exact equality.

});

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

expect(splitInteger(4, 6)).toEqual([0, 0, 1, 1, 1, 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.

This test covers the value < numberOfParts case and asserts a concrete expected array. Also add a property-based test for this scenario verifying length and sum (and the max-min <= 1 constraint). That will satisfy checklist items requiring varied scenario coverage without over-constraining internal distributions.

});