Testing Binary Floating-Point Conversion in javascript-algorithms
This test suite validates the conversion of floating-point numbers to their binary string representations in both 32-bit and 64-bit formats. It ensures accurate binary encoding of decimal numbers according to IEEE 754 floating-point standards.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
trekhleb/javascript-algorithms
src/algorithms/math/binary-floating-point/__tests__/floatAsBinaryString.test.js
import { floatAs32BinaryString, floatAs64BinaryString } from '../floatAsBinaryString';
import { testCases32Bits, testCases64Bits } from '../testCases';
describe('floatAs32Binary', () => {
it('should create a binary representation of the floating numbers', () => {
for (let testCaseIndex = 0; testCaseIndex < testCases32Bits.length; testCaseIndex += 1) {
const [decimal, binary] = testCases32Bits[testCaseIndex];
expect(floatAs32BinaryString(decimal)).toBe(binary);
}
});
});
describe('floatAs64Binary', () => {
it('should create a binary representation of the floating numbers', () => {
for (let testCaseIndex = 0; testCaseIndex < testCases64Bits.length; testCaseIndex += 1) {
const [decimal, binary] = testCases64Bits[testCaseIndex];
expect(floatAs64BinaryString(decimal)).toBe(binary);
}
});
});