Add isPowerOfTwo snippet

This commit is contained in:
Angelos Chalaris
2019-12-31 13:17:12 +02:00
parent 21b0ab5c65
commit eb55b3972a
7 changed files with 59 additions and 3 deletions

29
test/isPowerOfTwo.test.js Normal file
View File

@ -0,0 +1,29 @@
const {isPowerOfTwo} = require('./_30s.js');
test('isPowerOfTwo is a Function', () => {
expect(isPowerOfTwo).toBeInstanceOf(Function);
});
test('0 is not a power of 2', () => {
expect(isPowerOfTwo(0)).toBeFalsy();
});
test('1 is a power of 2', () => {
expect(isPowerOfTwo(1)).toBeTruthy();
});
test('2 is a power of 2', () => {
expect(isPowerOfTwo(2)).toBeTruthy();
});
test('3 is not a power of 2', () => {
expect(isPowerOfTwo(3)).toBeFalsy();
});
test('4 is a power of 2', () => {
expect(isPowerOfTwo(4)).toBeTruthy();
});
test('5 is not a power of 2', () => {
expect(isPowerOfTwo(5)).toBeFalsy();
});
test('6 is not a power of 2', () => {
expect(isPowerOfTwo(6)).toBeFalsy();
});
test('undefined is not a power of 2', () => {
expect(isPowerOfTwo()).toBeFalsy();
});