mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
add algorithm that calculates next power of two
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {IsPowerOfTwo} from '../IsPowerOfTwo'
|
||||
import { IsPowerOfTwo } from '../IsPowerOfTwo'
|
||||
|
||||
test('Check if 0 is a power of 2 or not:', () => {
|
||||
const res = IsPowerOfTwo(0)
|
||||
|
||||
18
Bit-Manipulation/test/NextPowerOfTwo.test.js
Normal file
18
Bit-Manipulation/test/NextPowerOfTwo.test.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { nextPowerOfTwo } from '../NextPowerOfTwo'
|
||||
|
||||
describe('NextPowerOfTwo', () => {
|
||||
it.each`
|
||||
input | result
|
||||
${0} | ${1}
|
||||
${1} | ${2}
|
||||
${2} | ${4}
|
||||
${3} | ${4}
|
||||
${5} | ${8}
|
||||
${125} | ${128}
|
||||
${1024} | ${2048}
|
||||
${10000} | ${16384}
|
||||
`('returns $result when is given $input', ({ input, result }) => {
|
||||
const res = nextPowerOfTwo(input)
|
||||
expect(res).toBe(result)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user