generated from skills/copilot-codespaces-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac436f7
commit f4126ea
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function calculateNumbers(a, b) { | ||
if (typeof a !== 'number' || typeof b !== 'number') { | ||
throw new Error('Both arguments must be numbers'); | ||
} | ||
|
||
if (isNaN(a) || isNaN(b)) { | ||
throw new Error('Arguments must not be NaN'); | ||
} | ||
|
||
if (!isFinite(a) || !isFinite(b)) { | ||
throw new Error('Arguments must be finite numbers'); | ||
} | ||
|
||
return a + b; | ||
} | ||
|
||
module.exports = { calculateNumbers }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Import the function from the module where it's defined | ||
const { calculateNumbers } = require('./skills'); | ||
|
||
describe('calculateNumbers', () => { | ||
test('adds positive numbers correctly', () => { | ||
expect(calculateNumbers(1, 2)).toBe(3); | ||
}); | ||
|
||
test('adds negative numbers correctly', () => { | ||
expect(calculateNumbers(-1, -2)).toBe(-3); | ||
}); | ||
|
||
test('adds zero correctly', () => { | ||
expect(calculateNumbers(0, 2)).toBe(2); | ||
}); | ||
|
||
test('adds floating point numbers correctly', () => { | ||
expect(calculateNumbers(1.2, 3.4)).toBeCloseTo(4.6); | ||
}); | ||
}); |