Skip to content

Commit 6d109d8

Browse files
jagdish-15Cool-Katt
andauthoredJan 22, 2025··
Updating tests for armstrong-numbers (#2577)
* Updating tests for armstrong-numbers * Implementing BigInt to handle last two test cases * Updating test file to implement BigInt * Adding note in the instructions * Adding exercism note block * Fixing the CI, hopefully --------- Co-authored-by: Cool-Katt <[email protected]>
1 parent a3a8df0 commit 6d109d8

File tree

5 files changed

+57
-23
lines changed

5 files changed

+57
-23
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!-- prettier-ignore-start -->
2+
~~~~exercism/note
3+
Some of the tests might pass a `BigInt` as input.
4+
Ensure that your implementation can handle such cases.
5+
~~~~
6+
<!-- prettier-ignore-end -->

‎exercises/practice/armstrong-numbers/.meta/config.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"ankorGH",
77
"gargrave",
88
"hayashi-ay",
9+
"jagdish-15",
910
"ovidiu141",
1011
"SleeplessByte",
1112
"xarxziux"
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
export const isArmstrongNumber = (input) => {
2-
const digits = [...String(input)];
2+
const bigInput = BigInt(input);
3+
4+
const digits = [...String(bigInput)];
5+
36
const sum = digits.reduce(
4-
(total, current) => total + current ** digits.length,
5-
0,
7+
(total, current) => total + BigInt(current) ** BigInt(digits.length),
8+
BigInt(0),
69
);
7-
return sum === input;
10+
11+
return sum === bigInput;
812
};
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[c1ed103c-258d-45b2-be73-d8c6d9580c7b]
613
description = "Zero is an Armstrong number"
714

815
[579e8f03-9659-4b85-a1a2-d64350f6b17a]
9-
description = "Single digit numbers are Armstrong numbers"
16+
description = "Single-digit numbers are Armstrong numbers"
1017

1118
[2d6db9dc-5bf8-4976-a90b-b2c2b9feba60]
12-
description = "There are no 2 digit Armstrong numbers"
19+
description = "There are no two-digit Armstrong numbers"
1320

1421
[509c087f-e327-4113-a7d2-26a4e9d18283]
15-
description = "Three digit number that is an Armstrong number"
22+
description = "Three-digit number that is an Armstrong number"
1623

1724
[7154547d-c2ce-468d-b214-4cb953b870cf]
18-
description = "Three digit number that is not an Armstrong number"
25+
description = "Three-digit number that is not an Armstrong number"
1926

2027
[6bac5b7b-42e9-4ecb-a8b0-4832229aa103]
21-
description = "Four digit number that is an Armstrong number"
28+
description = "Four-digit number that is an Armstrong number"
2229

2330
[eed4b331-af80-45b5-a80b-19c9ea444b2e]
24-
description = "Four digit number that is not an Armstrong number"
31+
description = "Four-digit number that is not an Armstrong number"
2532

2633
[f971ced7-8d68-4758-aea1-d4194900b864]
27-
description = "Seven digit number that is an Armstrong number"
34+
description = "Seven-digit number that is an Armstrong number"
2835

2936
[7ee45d52-5d35-4fbd-b6f1-5c8cd8a67f18]
30-
description = "Seven digit number that is not an Armstrong number"
37+
description = "Seven-digit number that is not an Armstrong number"
38+
39+
[5ee2fdf8-334e-4a46-bb8d-e5c19c02c148]
40+
description = "Armstrong number containing seven zeroes"
41+
42+
[12ffbf10-307a-434e-b4ad-c925680e1dd4]
43+
description = "The largest and last Armstrong number"

‎exercises/practice/armstrong-numbers/armstrong-numbers.spec.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,45 @@ describe('Armstrong Numbers', () => {
66
expect(isArmstrongNumber(0)).toEqual(true);
77
});
88

9-
xtest('Single digit numbers are Armstrong numbers', () => {
9+
xtest('Single-digit numbers are Armstrong numbers', () => {
1010
expect(isArmstrongNumber(5)).toEqual(true);
1111
});
1212

13-
xtest('There are no 2 digit Armstrong numbers', () => {
13+
xtest('There are no two-digit Armstrong numbers', () => {
1414
expect(isArmstrongNumber(10)).toEqual(false);
1515
});
1616

17-
xtest('Three digit number that is an Armstrong number', () => {
17+
xtest('Three-digit number that is an Armstrong number', () => {
1818
expect(isArmstrongNumber(153)).toEqual(true);
1919
});
2020

21-
xtest('Three digit number that is not an Armstrong number', () => {
21+
xtest('Three-digit number that is not an Armstrong number', () => {
2222
expect(isArmstrongNumber(100)).toEqual(false);
2323
});
2424

25-
xtest('Four digit number that is an Armstrong number', () => {
25+
xtest('Four-digit number that is an Armstrong number', () => {
2626
expect(isArmstrongNumber(9474)).toEqual(true);
2727
});
2828

29-
xtest('Four digit number that is not an Armstrong number', () => {
29+
xtest('Four-digit number that is not an Armstrong number', () => {
3030
expect(isArmstrongNumber(9475)).toEqual(false);
3131
});
3232

33-
xtest('Seven digit number that is an Armstrong number', () => {
33+
xtest('Seven-digit number that is an Armstrong number', () => {
3434
expect(isArmstrongNumber(9926315)).toEqual(true);
3535
});
3636

37-
xtest('Seven digit number that is not an Armstrong number', () => {
37+
xtest('Seven-digit number that is not an Armstrong number', () => {
3838
expect(isArmstrongNumber(9926314)).toEqual(false);
3939
});
40+
41+
xtest('Armstrong number containing seven zeroes', () => {
42+
const bigInput = 186709961001538790100634132976990n;
43+
expect(isArmstrongNumber(bigInput)).toEqual(true);
44+
});
45+
46+
xtest('The largest and last Armstrong number', () => {
47+
const bigInput = 115132219018763992565095597973971522401n;
48+
expect(isArmstrongNumber(bigInput)).toEqual(true);
49+
});
4050
});

0 commit comments

Comments
 (0)
Please sign in to comment.