Testing Binary Bit Setting Operations in javascript-algorithms
This test suite validates the setBit function’s ability to manipulate binary numbers by setting specific bits at given positions. It verifies both basic bit operations and position-based modifications in binary representations of integers.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
trekhleb/javascript-algorithms
src/algorithms/math/bits/__test__/setBit.test.js
import setBit from '../setBit';
describe('setBit', () => {
it('should set bit at specific position', () => {
// 1 = 0b0001
expect(setBit(1, 0)).toBe(1);
expect(setBit(1, 1)).toBe(3);
expect(setBit(1, 2)).toBe(5);
// 10 = 0b1010
expect(setBit(10, 0)).toBe(11);
expect(setBit(10, 1)).toBe(10);
expect(setBit(10, 2)).toBe(14);
});
});