From 424275ee8f4b5911fef32fe8f1a8b54d2f0fd47a Mon Sep 17 00:00:00 2001 From: Jordan Sinclair Date: Sun, 18 May 2025 00:40:35 -0500 Subject: [PATCH] Fixed an additional "decimal place" defect, in scope of issue #2326 --- src/CalcManager/CEngine/scicomm.cpp | 34 +++++++++++++++++++ .../ScientificModeFunctionalTests.cs | 34 +++++++++++++++++++ .../CalculatorManagerTest.cpp | 8 +++++ 3 files changed, 76 insertions(+) diff --git a/src/CalcManager/CEngine/scicomm.cpp b/src/CalcManager/CEngine/scicomm.cpp index 2ecc9739..a4300edc 100644 --- a/src/CalcManager/CEngine/scicomm.cpp +++ b/src/CalcManager/CEngine/scicomm.cpp @@ -832,6 +832,40 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam) break; case IDC_PNT: + + // Check if the last command was a closing parenthesis + if (m_nLastCom == IDC_CLOSEP) + { + // Treat this as an implicit multiplication + m_nOpCode = IDC_MUL; + m_lastVal = m_currentVal; + + // We need to clear any previous state from last calculation + m_holdVal = Rational(0); + m_bNoPrevEqu = true; + + // Add the operand to history before adding the implicit multiplication + if (!m_HistoryCollector.FOpndAddedToHistory()) + { + m_HistoryCollector.AddOpenBraceToHistory(); + m_HistoryCollector.AddOpndToHistory(m_numberString, m_currentVal); + m_HistoryCollector.AddCloseBraceToHistory(); + } + + // Add the implicit multiplication to history + m_HistoryCollector.AddBinOpToHistory(m_nOpCode, m_fIntegerMode); + + m_bChangeOp = true; + m_nPrevOpCode = 0; + + // Clear any pending operations in the precedence stack + while (m_precedenceOpCount > 0) + { + m_precedenceOpCount--; + m_nPrecOp[m_precedenceOpCount] = 0; + } + } + if (m_bRecord && !m_fIntegerMode && m_input.TryAddDecimalPt()) { DisplayNum(); diff --git a/src/CalculatorUITests/ScientificModeFunctionalTests.cs b/src/CalculatorUITests/ScientificModeFunctionalTests.cs index 8f30b388..9911bf8e 100644 --- a/src/CalculatorUITests/ScientificModeFunctionalTests.cs +++ b/src/CalculatorUITests/ScientificModeFunctionalTests.cs @@ -173,6 +173,40 @@ namespace CalculatorUITests var historyItems1 = page.HistoryPanel.GetAllHistoryListViewItems(); Assert.IsTrue(historyItems1[0].GetValue().Equals("28", StringComparison.InvariantCultureIgnoreCase)); Assert.IsTrue(historyItems1[0].GetExpression().Equals("(7 \x00D7 2) \x00D7 2=", StringComparison.InvariantCultureIgnoreCase)); + + /* + * TEST #3 + */ + page.ScientificOperators.ParenthesisLeftButton.Click(); + page.StandardOperators.NumberPad.Input(8); + page.ScientificOperators.ParenthesisRightButton.Click(); + page.StandardOperators.NumberPad.Input(0.5); + page.StandardOperators.EqualButton.Click(); + + // Assert calculator & history results + Assert.AreEqual("4", page.CalculatorResults.GetCalculatorResultText()); + Assert.AreEqual("(8) \x00D7 0.5=", page.CalculatorResults.GetCalculatorExpressionText()); + + var historyItems2 = page.HistoryPanel.GetAllHistoryListViewItems(); + Assert.IsTrue(historyItems2[0].GetValue().Equals("4", StringComparison.InvariantCultureIgnoreCase)); + Assert.IsTrue(historyItems2[0].GetExpression().Equals("(8) \x00D7 0.5=", StringComparison.InvariantCultureIgnoreCase)); + + /* + * TEST #4 + */ + page.ScientificOperators.ParenthesisLeftButton.Click(); + page.StandardOperators.NumberPad.Input(8); + page.ScientificOperators.ParenthesisRightButton.Click(); + page.StandardOperators.NumberPad.Input(.5); + page.StandardOperators.EqualButton.Click(); + + // Assert calculator & history results + Assert.AreEqual("4", page.CalculatorResults.GetCalculatorResultText()); + Assert.AreEqual("(8) \x00D7 0.5=", page.CalculatorResults.GetCalculatorExpressionText()); + + var historyItems3 = page.HistoryPanel.GetAllHistoryListViewItems(); + Assert.IsTrue(historyItems3[0].GetValue().Equals("4", StringComparison.InvariantCultureIgnoreCase)); + Assert.IsTrue(historyItems3[0].GetExpression().Equals("(8) \x00D7 0.5=", StringComparison.InvariantCultureIgnoreCase)); } [TestMethod] diff --git a/src/CalculatorUnitTests/CalculatorManagerTest.cpp b/src/CalculatorUnitTests/CalculatorManagerTest.cpp index d9e19a4b..d5b574f7 100644 --- a/src/CalculatorUnitTests/CalculatorManagerTest.cpp +++ b/src/CalculatorUnitTests/CalculatorManagerTest.cpp @@ -655,6 +655,14 @@ namespace CalculatorManagerTest Command::CommandCLOSEP, Command::Command2, Command::CommandEQU, Command::CommandOPENP, Command::Command1, Command::Command4, Command::CommandCLOSEP, Command::Command2, Command::CommandEQU, Command::CommandNULL}; TestDriver::Test(L"28", L"(14) \x00D7 2=", commands8, true, true); + + Command commands9[] = { Command::CommandOPENP, Command::Command8, Command::CommandCLOSEP, + Command::Command0, Command::CommandPNT, Command::Command5, Command::CommandEQU, Command::CommandNULL }; + TestDriver::Test(L"4", L"(8) \x00D7 0.5=", commands9, true, true); + + Command commands10[] = { Command::CommandOPENP, Command::Command8, Command::CommandCLOSEP, + Command::CommandPNT, Command::Command5, Command::CommandEQU, Command::CommandNULL }; + TestDriver::Test(L"4", L"(8) \x00D7 0.5=", commands10, true, true); } void CalculatorManagerTest::CalculatorManagerTestScientificError()