Testing Binary Addition Implementation in javascript-algorithms
This test suite validates the fullAdder function implementation in the javascript-algorithms repository, focusing on binary addition operations. The tests verify correct addition behavior across various number combinations including positive, negative, and zero values.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
trekhleb/javascript-algorithms
src/algorithms/math/bits/__test__/fullAdder.test.js
import fullAdder from '../fullAdder';
describe('fullAdder', () => {
it('should add up two numbers', () => {
expect(fullAdder(0, 0)).toBe(0);
expect(fullAdder(2, 0)).toBe(2);
expect(fullAdder(0, 2)).toBe(2);
expect(fullAdder(1, 2)).toBe(3);
expect(fullAdder(2, 1)).toBe(3);
expect(fullAdder(6, 6)).toBe(12);
expect(fullAdder(-2, 4)).toBe(2);
expect(fullAdder(4, -2)).toBe(2);
expect(fullAdder(-4, -4)).toBe(-8);
expect(fullAdder(4, -5)).toBe(-1);
expect(fullAdder(2, 121)).toBe(123);
expect(fullAdder(121, 2)).toBe(123);
});
});