fix: Update checkDisplay logic and backspace/trig test assertions

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-03-14 17:27:01 -06:00
committed by Tanner
parent 2088081bb8
commit e32b274e5c
+13 -14
View File
@@ -141,15 +141,19 @@ function checkDisplay(expected, message) {
return; return;
} }
// Use a tolerance for floating point comparisons // Coerce to numbers for comparison to handle string vs number differences ('5' vs 5)
if (typeof expected === 'number' && typeof actual === 'number') { // and use a tolerance for floating point values.
const actualNum = parseFloat(actual);
const expectedNum = parseFloat(expected);
if (!isNaN(actualNum) && !isNaN(expectedNum)) {
const tolerance = 1e-9; const tolerance = 1e-9;
if (Math.abs(expected - actual) < tolerance) { if (Math.abs(expectedNum - actualNum) < tolerance || actualNum === expectedNum) { // second part handles Infinity
return; // The numbers are close enough. return; // The numbers are close enough.
} }
} }
// Fallback to strict equality for everything else (e.g., strings like '0.') // Fallback to strict equality for non-numeric strings or when numeric check fails
assert.strictEqual(actual, expected, message); assert.strictEqual(actual, expected, message);
} }
// --- End Test Framework --- // --- End Test Framework ---
@@ -291,15 +295,6 @@ test('Switch to RAD mode', () => {
for (const op in trigOps) { for (const op in trigOps) {
for (const angle of trigAngles) { for (const angle of trigAngles) {
// tan(pi/2) is Infinity, which the calculator can handle
if (op === 'tan' && (Math.abs(angle - Math.PI/2) < 1e-9 || Math.abs(angle - 3*Math.PI/2) < 1e-9)) {
test(`Trig Edge Case (rad): tan(${angle})`, () => {
pressNumber(angle);
buttonPress('tan');
checkDisplay(Infinity);
});
continue;
}
test(`Trig (rad): ${trigOps[op].name}(${angle})`, () => { test(`Trig (rad): ${trigOps[op].name}(${angle})`, () => {
pressNumber(angle); pressNumber(angle);
buttonPress(op); buttonPress(op);
@@ -336,7 +331,11 @@ test('Clear and All Clear', () => {
test('Backspace', () => { test('Backspace', () => {
press('123.45B'); press('123.45B');
checkDisplay('123.4'); checkDisplay('123.4');
press('BB'); press('B');
checkDisplay('123.');
press('B');
checkDisplay('123');
press('B');
checkDisplay('12'); checkDisplay('12');
press('B'); press('B');
checkDisplay('1'); checkDisplay('1');