Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4df1e9e

Browse files
pomkarnath98omkarnathparida
andauthored
tests: Project Euler Problem 1 (TheAlgorithms#1161)
* 📦 NEW: Added solution for ProjectEuler-007 * 🐛 FIX: Spelling mistake fixes * 👌 IMPROVE: changed variable name from `inc` to `candidateValue` and thrown error in case of invalid input * 👌 IMPROVE: Modified the code * 👌 IMPROVE: Added test case for ProjectEuler Problem001 Co-authored-by: Omkarnath Parida <omkarnath.parida@yocket.in>
1 parent 36c6a4d commit 4df1e9e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

‎Project-Euler/Problem001.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ Find the sum of all the multiples of 3 or 5 below the provided parameter value n
55
*/
66

77
const multiplesThreeAndFive = (num) => {
8+
if (num < 1) throw new Error('No natural numbers exist below 1')
9+
810
let total = 0
911
// total for calculating the sum
10-
for (let i = 0; i < num; i++) {
12+
for (let i = 1; i < num; i++) {
1113
if (i % 3 === 0 || i % 5 === 0) {
1214
total += i
1315
}

‎Project-Euler/test/Problem001.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { multiplesThreeAndFive } from '../Problem001.js'
2+
3+
describe('Sum of multiples of 3 or 5', () => {
4+
it('should throw error when number is negative number', () => {
5+
expect(() => multiplesThreeAndFive(-24)).toThrowError('No natural numbers exist below 1')
6+
})
7+
it('should throw error when number is 0', () => {
8+
expect(() => multiplesThreeAndFive(0)).toThrowError('No natural numbers exist below 1')
9+
})
10+
test('if the number is greater than 0', () => {
11+
expect(multiplesThreeAndFive(10)).toBe(23)
12+
})
13+
// Project Euler Condition Check
14+
test('if the number is 1000', () => {
15+
expect(multiplesThreeAndFive(1000)).toBe(233168)
16+
})
17+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /