Testing Two's Complement Sign Switching Implementation in javascript-algorithms
This test suite validates the switchSign function implementation that converts positive numbers to negative and vice versa using the two’s complement approach. The tests verify the function’s ability to handle zero, positive integers, and negative integers while maintaining numerical accuracy.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
trekhleb/javascript-algorithms
src/algorithms/math/bits/__test__/switchSign.test.js
import switchSign from '../switchSign';
describe('switchSign', () => {
it('should switch the sign of the number using twos complement approach', () => {
expect(switchSign(0)).toBe(0);
expect(switchSign(1)).toBe(-1);
expect(switchSign(-1)).toBe(1);
expect(switchSign(32)).toBe(-32);
expect(switchSign(-32)).toBe(32);
expect(switchSign(23)).toBe(-23);
expect(switchSign(-23)).toBe(23);
});
});