Testing Power of Two Algorithm Implementation in javascript-algorithms
This test suite validates the isPowerOfTwo function implementation, which determines if a given number is a power of two. The tests systematically verify the function’s ability to identify numbers that can be expressed as 2^n, covering both positive and negative test cases.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
trekhleb/javascript-algorithms
src/algorithms/math/is-power-of-two/__test__/isPowerOfTwo.test.js
import isPowerOfTwo from '../isPowerOfTwo';
describe('isPowerOfTwo', () => {
it('should check if the number is made by multiplying twos', () => {
expect(isPowerOfTwo(-1)).toBe(false);
expect(isPowerOfTwo(0)).toBe(false);
expect(isPowerOfTwo(1)).toBe(true);
expect(isPowerOfTwo(2)).toBe(true);
expect(isPowerOfTwo(3)).toBe(false);
expect(isPowerOfTwo(4)).toBe(true);
expect(isPowerOfTwo(5)).toBe(false);
expect(isPowerOfTwo(6)).toBe(false);
expect(isPowerOfTwo(7)).toBe(false);
expect(isPowerOfTwo(8)).toBe(true);
expect(isPowerOfTwo(10)).toBe(false);
expect(isPowerOfTwo(12)).toBe(false);
expect(isPowerOfTwo(16)).toBe(true);
expect(isPowerOfTwo(31)).toBe(false);
expect(isPowerOfTwo(64)).toBe(true);
expect(isPowerOfTwo(1024)).toBe(true);
expect(isPowerOfTwo(1023)).toBe(false);
});
});