From d2c4be15d07a07c8417990e6464d51c8fb3fd5c3 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 14 Mar 2026 17:56:39 -0600 Subject: [PATCH] test: Expand Pi button test coverage Co-authored-by: aider (gemini/gemini-2.5-pro) --- calculator/test.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/calculator/test.js b/calculator/test.js index 41b9282..77888ea 100644 --- a/calculator/test.js +++ b/calculator/test.js @@ -517,5 +517,73 @@ test('Operation with Pi', () => { checkDisplay(5 * Math.PI); }); +test('Pi as second operand', () => { + press('2+p='); + checkDisplay(2 + Math.PI); +}); + +test('Chaining operations with Pi', () => { + press('p*2+3='); + checkDisplay(Math.PI * 2 + 3); +}); + +test('Unary operations on Pi', () => { + press('p'); + checkDisplay(Math.PI); + press('r'); // sqrt + checkDisplay(Math.sqrt(Math.PI)); + press('R'); press('R'); // AC + press('p'); + press('s'); // x^2 + checkDisplay(Math.PI * Math.PI); + press('R'); press('R'); // AC + press('p'); + press('i'); // 1/x + checkDisplay(1 / Math.PI); +}); + +test('Trig functions with Pi (rad)', () => { + buttonPress('angleMode'); // switch to RAD + assert.strictEqual(scientificOperators.angleMode.val, 'rad'); + + press('p'); + press('sin'); + checkDisplay(Math.sin(Math.PI)); // ~0 + press('R'); press('R'); + + press('p'); + press('cos'); + checkDisplay(Math.cos(Math.PI)); // -1 + press('R'); press('R'); + + press('p'); + press('tan'); + checkDisplay(Math.tan(Math.PI)); // ~0 + + buttonPress('angleMode'); // switch back to DEG + assert.strictEqual(scientificOperators.angleMode.val, 'deg'); +}); + +test('Pi after equals', () => { + press('1+2='); + checkDisplay(3); + press('p'); + checkDisplay(Math.PI); + press('+1='); + checkDisplay(Math.PI + 1); +}); + +test('Pi with negative operator', () => { + press('pN'); + checkDisplay(-Math.PI); + press('*2='); + checkDisplay(-Math.PI * 2); +}); + +test('Negative number times Pi', () => { + press('2N*p='); + checkDisplay(-2 * Math.PI); +}); + // Run all the defined tests runTests();