mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
merge: Add pronic number implementation (#1023)
* feat: Add pronic number implementation * Add test to Math * Minor fixes * Minor style fixes * refactor: Store square root in a variable * Minor refactoring * fix: Change pronic number check logic Reduced time complexity from O(sqrt(n)) to O(1) * Minor style fixes * fix: Update pronic number check boolean equation * refactor: Change pronic number check condition * refactor: Add tests to Math * Minor style fixes * refactor: Change unit test logic
This commit is contained in:
12
Maths/test/IsPronic.test.js
Normal file
12
Maths/test/IsPronic.test.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { isPronic } from '../IsPronic'
|
||||
|
||||
const pronicNumbers = [0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462, 506, 552, 600, 650, 702, 756, 812, 870, 930, 992, 1056, 1122, 1190, 1260, 1332, 1406, 1482, 1560, 1640, 1722, 1806, 1892, 1980, 2070, 2162, 2256, 2352, 2450, 2550]
|
||||
|
||||
describe('Testing isPronic function', () => {
|
||||
for (let i = 0; i <= 2500; i++) {
|
||||
it('should return true', () => {
|
||||
const isPronicNumber = isPronic(i)
|
||||
expect(isPronicNumber).toBe(pronicNumbers.includes(i))
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user