-
-
Notifications
You must be signed in to change notification settings - Fork 624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating tests for armstrong-numbers #2577
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
"ankorGH", | ||
"gargrave", | ||
"hayashi-ay", | ||
"jagdish-15", | ||
"ovidiu141", | ||
"SleeplessByte", | ||
"xarxziux" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
export const isArmstrongNumber = (input) => { | ||
const digits = [...String(input)]; | ||
const bigInput = BigInt(input); | ||
|
||
const digits = [...String(bigInput)]; | ||
|
||
const sum = digits.reduce( | ||
(total, current) => total + current ** digits.length, | ||
0, | ||
(total, current) => total + BigInt(current) ** BigInt(digits.length), | ||
BigInt(0), | ||
); | ||
return sum === input; | ||
|
||
return sum === bigInput; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,43 @@ | ||
# This is an auto-generated file. Regular comments will be removed when this | ||
# file is regenerated. Regenerating will not touch any manually added keys, | ||
# so comments can be added in a "comment" key. | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[c1ed103c-258d-45b2-be73-d8c6d9580c7b] | ||
description = "Zero is an Armstrong number" | ||
|
||
[579e8f03-9659-4b85-a1a2-d64350f6b17a] | ||
description = "Single digit numbers are Armstrong numbers" | ||
description = "Single-digit numbers are Armstrong numbers" | ||
|
||
[2d6db9dc-5bf8-4976-a90b-b2c2b9feba60] | ||
description = "There are no 2 digit Armstrong numbers" | ||
description = "There are no two-digit Armstrong numbers" | ||
|
||
[509c087f-e327-4113-a7d2-26a4e9d18283] | ||
description = "Three digit number that is an Armstrong number" | ||
description = "Three-digit number that is an Armstrong number" | ||
|
||
[7154547d-c2ce-468d-b214-4cb953b870cf] | ||
description = "Three digit number that is not an Armstrong number" | ||
description = "Three-digit number that is not an Armstrong number" | ||
|
||
[6bac5b7b-42e9-4ecb-a8b0-4832229aa103] | ||
description = "Four digit number that is an Armstrong number" | ||
description = "Four-digit number that is an Armstrong number" | ||
|
||
[eed4b331-af80-45b5-a80b-19c9ea444b2e] | ||
description = "Four digit number that is not an Armstrong number" | ||
description = "Four-digit number that is not an Armstrong number" | ||
|
||
[f971ced7-8d68-4758-aea1-d4194900b864] | ||
description = "Seven digit number that is an Armstrong number" | ||
description = "Seven-digit number that is an Armstrong number" | ||
|
||
[7ee45d52-5d35-4fbd-b6f1-5c8cd8a67f18] | ||
description = "Seven digit number that is not an Armstrong number" | ||
description = "Seven-digit number that is not an Armstrong number" | ||
|
||
[5ee2fdf8-334e-4a46-bb8d-e5c19c02c148] | ||
description = "Armstrong number containing seven zeroes" | ||
|
||
[12ffbf10-307a-434e-b4ad-c925680e1dd4] | ||
description = "The largest and last Armstrong number" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,35 +6,45 @@ describe('Armstrong Numbers', () => { | |
expect(isArmstrongNumber(0)).toEqual(true); | ||
}); | ||
|
||
xtest('Single digit numbers are Armstrong numbers', () => { | ||
xtest('Single-digit numbers are Armstrong numbers', () => { | ||
expect(isArmstrongNumber(5)).toEqual(true); | ||
}); | ||
|
||
xtest('There are no 2 digit Armstrong numbers', () => { | ||
xtest('There are no two-digit Armstrong numbers', () => { | ||
expect(isArmstrongNumber(10)).toEqual(false); | ||
}); | ||
|
||
xtest('Three digit number that is an Armstrong number', () => { | ||
xtest('Three-digit number that is an Armstrong number', () => { | ||
expect(isArmstrongNumber(153)).toEqual(true); | ||
}); | ||
|
||
xtest('Three digit number that is not an Armstrong number', () => { | ||
xtest('Three-digit number that is not an Armstrong number', () => { | ||
expect(isArmstrongNumber(100)).toEqual(false); | ||
}); | ||
|
||
xtest('Four digit number that is an Armstrong number', () => { | ||
xtest('Four-digit number that is an Armstrong number', () => { | ||
expect(isArmstrongNumber(9474)).toEqual(true); | ||
}); | ||
|
||
xtest('Four digit number that is not an Armstrong number', () => { | ||
xtest('Four-digit number that is not an Armstrong number', () => { | ||
expect(isArmstrongNumber(9475)).toEqual(false); | ||
}); | ||
|
||
xtest('Seven digit number that is an Armstrong number', () => { | ||
xtest('Seven-digit number that is an Armstrong number', () => { | ||
expect(isArmstrongNumber(9926315)).toEqual(true); | ||
}); | ||
|
||
xtest('Seven digit number that is not an Armstrong number', () => { | ||
xtest('Seven-digit number that is not an Armstrong number', () => { | ||
expect(isArmstrongNumber(9926314)).toEqual(false); | ||
}); | ||
|
||
xtest('Armstrong number containing seven zeroes', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the runtime for these two for the proof.ci solution on your machine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI the tests are failing because that's not a valid integer. You probably need to switch to BigInt for these tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I’m aware of that, and that’s why comments are included in the test cases’
I was wondering if we should include these tests or not because doing so might cause all community solutions to become outdated and would require new students to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, updating the tests causes all solutions to be rerun again so they will become outdated anyway. You are correct that the current solutions that don't use BigInt will be invalid (if we include the two new tests). I feel that if there's an easy way to implement a solution that would pass all the tests, including the new ones, then they should be included, so if you can figure it out, feel free to commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've got it working using the BigInt approach, but we can't directly pass those large numbers as they are in the test file. Instead, we need to pass them either as strings or as BigInt values. I've demonstrated both approaches in the second-to-last and last tests, respectively. Please review them and let me know which approach we should proceed with. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We barely have any I prefer it if you pass the numbers into the tests with the const largeNumber = 186709961001538790100634132976990n
expect(isArmstrongNumber(largeNumber)).toEqual(true); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also recommend to add an const bigInput = BigInt(42);
// 42n
const bigInput = BigInt(42n);
// 42n |
||
const bigInput = 186709961001538790100634132976990n; | ||
expect(isArmstrongNumber(bigInput)).toEqual(true); | ||
}); | ||
|
||
xtest('The largest and last Armstrong number', () => { | ||
const bigInput = 115132219018763992565095597973971522401n; | ||
expect(isArmstrongNumber(bigInput)).toEqual(true); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other test descriptions needs to be updated to match this.